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