Apply string localization for web
[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 #include <FBaseTypes.h>
27 #include <FBaseColIComparerT.h>
28
29 namespace Tizen { namespace Base
30 {
31 /**
32  * @class ComparerT
33  *
34  * @brief       This class checks for equivalence between two values of the same primitive type.
35  * @since 2.0
36  *
37  * The %ComparerT class checks for equivalence between two values of the same primitive type.
38  *
39  * The following example demonstrates how to use the %ComparerT class.
40  *
41  * @code
42  *
43  *      #include <FBase.h>
44  *
45  *      using namespace Tizen::Base;
46  *
47  *      void
48  *      MyClass::ComparerTSample(void)
49  *      {
50  *              double d1 = 123;
51  *              double d2 = 124;
52  *              ComparerT<double> comparer;
53  *
54  *              // Compares 2 instances of Double
55  *              int cmp;
56  *              comparer.Compare(d1, d2, cmp);
57  *              if (cmp < 0)
58  *              {
59  *                      // ...
60  *              }
61  *      }
62  * @endcode
63  */
64 template< class Type >
65 class ComparerT
66         : public virtual Tizen::Base::Collection::IComparerT< Type >
67         , public Object
68 {
69 public:
70         /**
71          * This constructor initializes a new instance of the %ComparerT class.
72          *
73          * @since 2.0
74          */
75         ComparerT(void) { }
76
77
78         /**
79          * This destructor overrides Tizen::Base::Object::~Object().
80          *
81          * @since 2.0
82          */
83         virtual ~ComparerT(void) { }
84
85         /**
86          * Compares two given instances of the same type.
87          *
88          * @since 2.0
89          *
90          * @return              An error code
91          * @param[in]   obj1                    The first object to compare
92          * @param[in]   obj2                    The second object to compare
93          * @param[out]  cmp                             The result of the comparison
94          * @exception   E_SUCCESS               The method is successful.
95          * @exception   E_INVALID_ARG   The specified objects are not of the expected type.
96          * @remarks             @c cmp can take one of the following values:
97          * @code
98          * <  0  if the value of obj1 is less than the value of obj2
99          * == 0  if the value of obj1 is equal to the value of obj2
100          * >  0  if the value of obj1 is greater than the value of obj2
101          * @endcode
102          */
103         virtual result Compare(const Type& obj1, const Type& obj2, int& cmp) const
104         {
105                 if (obj1 > obj2)
106                 {
107                         cmp = 1;
108                 }
109                 else if (obj1 < obj2)
110                 {
111                         cmp = -1;
112                 }
113                 else
114                 {
115                         cmp = 0;
116                 }
117
118                 return E_SUCCESS;
119         }
120
121 private:
122         //
123         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
124         //
125         ComparerT(const ComparerT& obj);
126
127         //
128         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
129         //
130         ComparerT& operator =(const ComparerT& rhs);
131
132 }; // ComparerT
133
134 template< >
135 class ComparerT< Tizen::Base::String >
136         : public virtual Tizen::Base::Collection::IComparerT< Tizen::Base::String >
137         , public Object
138 {
139 public:
140         /**
141          * This constructor initializes a new instance of the %ComparerT class.
142          *
143          * @since 2.1
144          */
145         ComparerT(void) { }
146
147         /**
148          * This destructor overrides Tizen::Base::Object::~Object().
149          *
150          * @since 2.1
151          */
152         virtual ~ComparerT(void) { }
153
154         /**
155          * Compares two String instances.
156          *
157          * @since 2.1
158          *
159          * @return       Always returns @c E_SUCCESS
160          * @param[in]    str1     The String instance to compare
161          * @param[in]    str2     The String instance to compare
162          * @param[in]    cmp      The integer value for the result
163          */
164         virtual result Compare(const Tizen::Base::String& str1, const Tizen::Base::String& str2, int& cmp) const
165         {
166                 cmp = String::Compare(str1, str2);
167                 return E_SUCCESS;
168         }
169 private:
170         //
171         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
172         //
173         ComparerT(const ComparerT& obj);
174
175         //
176         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
177         //
178         ComparerT& operator =(const ComparerT& rhs);
179
180 }; // ComparerT <Tizen::Base::String>
181
182 }} // Tizen::Base
183
184 #endif // _FBASE_COMPARER_T_H_