2734687df42480d5fde48bd1dee2a2a64e8a9306
[platform/framework/native/appfw.git] / inc / FBaseLongLong.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                FBaseLongLong.h
19  * @brief               This is the header file for the %LongLong class.
20  *
21  * @see                 Tizen::Base::Number
22  *
23  * This header file contains the declarations of the %LongLong class.
24  */
25 #ifndef _FBASE_LONG_LONG_H_
26 #define _FBASE_LONG_LONG_H_
27
28 #include <FBaseNumber.h>
29
30
31 namespace Tizen { namespace Base
32 {
33 /**
34  *      @class  LongLong
35  *      @brief  This class is the wrapper class for the @c signed @c long @c long built-in type.
36  *
37  *      @since  2.0
38  *
39  *      The %LongLong class represents an integer value ranging from -9223372036854775808 to 9223372036854775807
40  *      , that is, -(2^63) to +((2^63)-1). The class is useful when passing a 64-bit @c signed
41  *      integral value to a method that accepts only an instance of Object. Furthermore,
42  *      this class provides methods for converting %LongLong (and @c long @c long) to String, and %String
43  *      to %LongLong (and @c long @c long).
44  *
45  * The following example demonstrates how to use the %LongLong class.
46  *
47  *      @code
48  *
49  *      #include <FBase.h>
50  *
51  *      using namespace Tizen::Base;
52  *
53  *      // This method checks whether the given string object contains a string
54  *      // representation of the pre-defined minimum 64-bit integral value
55  *      result
56  *      MyClass::Verify(String& string, bool& out)
57  *      {
58  *              static const LongLong MINIMUM(123456789);
59  *              result r = E_SUCCESS;
60  *
61  *              long long l;
62  *              r = LongLong::Parse(string, l);
63  *              if (IsFailed(r))
64  *              {
65  *                      goto CATCH;
66  *              }
67  *
68  *              out = (MINIMUM.CompareTo(l) == 0) ? true: false;
69  *
70  *              return r;
71  *      CATCH:
72  *              return r;
73  *      }
74  *      @endcode
75  */
76 class _OSP_EXPORT_ LongLong
77         : public Number
78 {
79 public:
80         /**
81          *      Initializes this instance of %LongLong with the specified value.
82          *
83          *      @since                  2.0
84          *
85          *      @param[in]      value   A @c long @c long value
86          */
87         LongLong(long long value = 0);
88
89         /**
90          *      Copying of objects using this copy constructor is allowed.
91          *
92          *      @since                  2.0
93          *
94          *      @param[in]      value   An instance of %LongLong
95          */
96         LongLong(const LongLong& value);
97
98         /**
99          *      This destructor overrides Tizen::Base::Object::~Object().
100          *
101          *      @since  2.0
102          */
103         virtual ~LongLong(void);
104
105         /**
106          *      Copying of objects using this copy assignment operator is allowed.
107          *
108          *      @since                  2.0
109          *
110          *      @param[in]      rhs     An instance of %LongLong
111          */
112         LongLong& operator =(const LongLong& rhs);
113
114         /**
115          *      Compares two @c long @c long values.
116          *
117          *      @since          2.0
118          *
119          *      @return         A 32-bit @c signed integer value
120          *      @code
121          *      <  0  if the value of @c l1 is less than the value of @c l2
122          *      == 0  if the value of @c l1 is equal to the value of @c l2
123          *      >  0  if the value of @c l1 is greater than the value of @c l2
124          *      @endcode
125          *      @param[in]      l1      The first @c long @c long value to compare
126          *      @param[in]      l2      The second @c long @c long value to compare
127          */
128         static int Compare(long long l1, long long l2);
129
130         /**
131          *      Compares the value of the current instance with the value of the specified instance of the %LongLong class.
132          *
133          *      @since          2.0
134          *
135          *      @return         A 32-bit @c signed integer value
136          *      @code
137          *      <  0  if the value of the current instance is less than the value of the specified instance
138          *      == 0  if the value of the current instance is equal to the value of the specified instance
139          *      >  0  if the value of the current instance is greater than the value of the specified instance
140          *      @endcode
141          *      @param[in]      value   An instance of the %LongLong class to compare
142          */
143         int CompareTo(const LongLong& value) const;
144
145         /**
146          *      Checks whether the value of the specified instance of Object is equal to the value of the current instance of %LongLong.
147          *
148          *      @since          2.0
149          *
150          *      @return         @c true if the value of the specified instance of Object is equal to the value of the current instance of %LongLong, @n
151          *                              else @c false
152          *      @param[in]      obj     An instance of Object to compare
153          *      @see            Tizen::Base::Object::Equals()
154          */
155         virtual bool Equals(const Object& obj) const;
156
157         /**
158          *      Gets the hash value of the current instance of %LongLong.
159          *
160          *      @since          2.0
161          *
162          *      @return         An integer value indicating the hash value of the current instance of %LongLong
163          *      @remarks        Two equal instances must return the same hash value. For better performance,
164          *                              the used hash function must generate a random distribution for all inputs. @n
165          *                              The default implementation of this method returns the value of the current instance.
166          */
167         virtual int GetHashCode(void) const;
168
169         /**
170         *        Gets the hash value of the specified @c long @c long value.
171         *
172         *        @since         2.0
173         *
174         *        @return        An integer value indicating the hash value of the specified @c long @c long value
175         *        @param[in]   val   A @c long @c long value to get the hash value
176         */
177         static int GetHashCode(long long val);
178
179         /**
180          *      Gets the @c signed @c char equivalent of the current instance of the %LongLong class.
181          *
182          *      @since          2.0
183          *
184          *      @return         The @c signed @c char equivalent of the current instance
185          */
186         virtual char ToChar(void) const;
187
188         /**
189          *      Gets the @c signed @c short equivalent of the current instance of the %LongLong class.
190          *
191          *      @since          2.0
192          *
193          *      @return         The @c signed @c short equivalent of the current instance
194          */
195         virtual short ToShort(void) const;
196
197         /**
198          *      Gets the @c signed @c int equivalent of the current instance of the %LongLong class.
199          *
200          *      @since          2.0
201          *
202          *      @return         The @c signed @c int equivalent of the current instance
203          */
204         virtual int ToInt(void) const;
205
206         /**
207          *      Gets the @c signed @c long equivalent of the current instance of the %LongLong class.
208          *
209          *      @since          2.0
210          *
211          *      @return         The @c signed @c long equivalent of the current instance
212          */
213         virtual long ToLong(void) const;
214
215         /**
216          *      Gets the @c signed @c float equivalent of the current instance of the %LongLong class.
217          *
218          *      @since          2.0
219          *
220          *      @return         The @c signed @c float equivalent of the current instance
221          */
222         virtual float ToFloat(void) const;
223
224         /**
225          *      Gets the @c signed @c double equivalent of the current instance of the %LongLong class.
226          *
227          *      @since          2.0
228          *
229          *      @return         The @c signed @c double equivalent of the current instance
230          */
231         virtual double ToDouble(void) const;
232
233         /**
234          *      Gets the @c signed @c long @c long equivalent of the current instance of the %LongLong class.
235          *
236          *      @since          2.0
237          *
238          *      @return         The @c signed @c long @c long equivalent of the current instance
239          */
240         virtual long long ToLongLong(void) const;
241
242         /**
243          *      Gets the string representing the value of the current instance of the %LongLong class.
244          *
245          *      @since          2.0
246          *
247          *      @return         The string representing the value of the current instance
248          */
249         virtual String ToString(void) const;
250
251         /**
252          *      Gets the string representing the specified @c signed @c long @c long value.
253          *
254          *      @since                  2.0
255          *
256          *      @return                 The string containing a Unicode representation of the specified @c signed @c long @c long value
257          *      @param[in]      value   A @c signed @c long @c long value to convert
258          */
259         static String ToString(long long value);
260
261         /**
262          *      Parses the specified string representing a numeric value and
263          *      returns the value as a @c signed @c long @c long (as out parameter).
264          *
265          *      @since                  2.0
266          *
267          *      @return                 An error code
268          *      @param[in]      s                               A string representing a numeric value
269          *      @param[out]     ret                             The result of the operation
270          *      @exception      E_SUCCESS               The method is successful.
271          *      @exception      E_NUM_FORMAT    The specified string does not contain a number that can be parsed.
272          *      @remarks
273          *                              - This method assumes that the string representing the numeric value uses a radix 10.
274          *                              - This method guarantees that the original value of out-parameter is not changed when the method returns error.
275          */
276         static result Parse(const String& s, long long& ret);
277
278         /**
279          *      Parses the specified string representing a numeric value using the specified radix and
280          *      returns the value as a @c signed @c long @c long (as out parameter).
281          *
282          *      @since                  2.1
283          *
284          *      @return                 An error code
285          *      @param[in]      s                               A string representing a numeric value
286          *      @param[in]      radix                   The radix of the string representing a numeric value @n
287          *                                                              It must be either 2, 8, 10 or 16.
288          *      @param[out]     ret                             The result of the operation
289          *      @exception      E_SUCCESS               The method is successful.
290          *      @exception      E_NUM_FORMAT    The specified string does not contain a number that can be parsed.
291          *      @exception      E_OUT_OF_RANGE  The specified @c radix is invalid.
292          *      @remarks        This method guarantees that the original value of out-parameter is not changed when the method returns error.
293          */
294         static result Parse(const String& s, int radix, long long& ret);
295
296         /**
297          *      A constant holding the maximum value a @c long @c long can have; 2^63-1.
298          *
299          *      @since  2.0
300          */
301         static const long long VALUE_MAX = (long long) 0x7FFFFFFFFFFFFFFFLL;
302
303         /**
304          *      A constant holding the minimum value a @c long @c long can have; -2^63.
305          *
306          *      @since  2.0
307          */
308         static const long long VALUE_MIN = (long long) 0x8000000000000000LL;
309
310         /**
311          * A @c long @c long value of this instance.
312          *
313          * @since       2.0
314          */
315         long long value;
316
317
318 private:
319         friend class _LongLongImpl;
320         class _LongLongImpl * __pLongLongImpl;
321
322 }; // LongLong
323
324 }} // Tizen::Base
325
326 #endif //_FBASE_LONG_LONG_H_