sync with tizen_2.0
[platform/framework/native/appfw.git] / inc / FBaseComparerT.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FBaseComparerT.h
20  * @brief               This is the header file for the %ComparerT class.
21  *
22  * This file contains declarations of the %ComparerT class.
23  */
24 #ifndef _FBASE_COMPARER_T_H_
25 #define _FBASE_COMPARER_T_H_
26
27 // Includes
28 #include <FBaseTypes.h>
29 #include <FBaseColIComparerT.h>
30
31
32 namespace Tizen { namespace Base
33 {
34 /**
35  * @class ComparerT
36  *
37  * @brief       This class checks for equivalence between 2 values of the same primitive type.
38  * @since 2.0
39  *
40  * The %ComparerT class checks for equivalence between 2 values of the same primitive type.
41  *
42  * The following example demonstrates how to use the %ComparerT class.
43  *
44  *      @code
45  *
46  *      #include <FBase.h>
47  *
48  *      using namespace Tizen::Base;
49  *
50  *      void
51  *      MyClass::ComparerTSample(void)
52  *      {
53  *              double d1 = 123;
54  *              double d2 = 124;
55  *              ComparerT<double> comparer;
56  *
57  *              // Compares 2 instances of Double
58  *              int cmp;
59  *              comparer.Compare(d1, d2, cmp);
60  *              if (cmp < 0)
61  *              {
62  *                      // ...
63  *              }
64  *      }
65  *      @endcode
66  */
67 template<class Type>
68 class ComparerT
69         : public virtual Tizen::Base::Collection::IComparerT <Type>
70         , public Object
71 {
72 public:
73         /**
74          * This constructor initializes a new instance of the %ComparerT class.
75          *
76          * @since 2.0
77          */
78         ComparerT(void) {}
79
80
81         /**
82          * This destructor overrides Tizen::Base::Object::~Object().
83          *
84          * @since 2.0
85          */
86         virtual ~ComparerT(void) { }
87
88         /**
89          * Compares two given instances of the same type.
90          *
91          * @since 2.0
92          *
93          * @return              An error code
94          * @param[in]   obj1    The first object to compare
95          * @param[in]   obj2    The second object to compare
96          * @param[out]  cmp             The result of comparison
97          * @exception   E_SUCCESS               The method is successful.
98          * @exception   E_INVALID_ARG   The specified objects are not of the expected type.
99          * @remarks             @c cmp can take one of the following values:
100          * @code
101          * <  0  if the value of @c obj1 is less than the value of @c obj2
102          * == 0  if the value of @c obj1 is equal to the value of @c obj2
103          * >  0  if the value of @c obj1 is greater than the value of @c obj2
104          * @endcode
105          */
106         virtual result Compare(const Type& obj1, const Type& obj2, int& cmp) const
107         {
108                 if (obj1 > obj2)
109                 {
110                         cmp = 1;
111                 }
112                 else if (obj1 < obj2)
113                 {
114                         cmp = -1;
115                 }
116                 else
117                 {
118                         cmp = 0;
119                 }
120
121                 return E_SUCCESS;
122         }
123
124 private:
125         /**
126          * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
127          */
128         ComparerT(const ComparerT& obj);
129
130         /**
131          * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
132          */
133         ComparerT& operator =(const ComparerT& rhs);
134
135 }; // ComparerT
136
137 }} // Tizen::Base
138
139 #endif // _FBASE_COMPARER_T_H_