2617ffc38186ccf696396e876d2877403f8d8b00
[platform/framework/native/appfw.git] / inc / FBaseLong.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                FBaseLong.h
19  * @brief               This is the header file for the %Long class.
20  *
21  * @see                 Number()
22  *
23  * This header file contains the declarations of the %Long class.
24  */
25 #ifndef _FBASE_LONG_H_
26 #define _FBASE_LONG_H_
27
28 #include <FBaseNumber.h>
29
30
31 namespace Tizen { namespace Base
32 {
33 /**
34  *      @class  Long
35  *      @brief  This class is the wrapper class for the @c signed @c long built-in type.
36  *
37  *      @since 2.0
38  *
39  *      The %Long class represents an integer value ranging from -2147483648 to 2147483647
40  *      , that is, -(2^31) to +((2^31)-1). The class is useful when passing a 32-bit @c signed
41  *      integral value to a method that accepts only an instance of Object. Furthermore,
42  *      this class provides methods for converting %Long (and @c long) to String, and %String
43  *      to %Long (and @c long).
44  *
45  * The following example demonstrates how to use the %Long 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 32-bit integral value
55  *      result
56  *      MyClass::Verify(String& string, bool& out)
57  *      {
58  *              static const Long MINIMUM(1230);
59  *              result r = E_SUCCESS;
60  *
61  *              long l;
62  *              r = Long::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_ Long
77         : public Number
78 {
79 public:
80         /**
81          *      Initializes this instance of %Long with the specified value.
82          *
83          *      @since 2.0
84          *
85          *      @param[in]      value   A @c long value
86          */
87         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 %Long
95          */
96         Long(const Long& value);
97
98         /**
99          *      This destructor overrides Tizen::Base::Object::~Object().
100          *
101          *      @since 2.0
102          */
103         virtual ~Long(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 %Long
111          */
112         Long& operator =(const Long& rhs);
113
114         /**
115          *      Compares two @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 value to compare
126          *      @param[in]      l2      The second @c long value to compare
127          */
128         static int Compare(long l1, long l2);
129
130         /**
131          *      Compares the value of the current instance with the value of the specified instance of the %Long class.
132          *
133          *      @since 2.0
134          *
135          *      @return         A 32-bit @c signed integer value
136          *
137          *      @code
138          *      <  0  if the value of the current instance is less than the value of the specified instance
139          *      == 0  if the value of the current instance is equal to the value of the specified instance
140          *      >  0  if the value of the current instance is greater than the value of the specified instance
141          *      @endcode
142          *      @param[in]      value   An instance of the %Long class to compare
143          */
144         int CompareTo(const Long& value) const;
145
146         /**
147          *      Checks whether the value of the specified instance of %Object is equal to the value of the current instance of %Long.
148          *
149          *      @since 2.0
150          *
151          *      @return         @c true if the value of the specified instance of %Object is equal to the value of the current instance of %Long, @n
152          *                              else @c false
153          *      @param[in]      obj     An instance of %Object to compare
154          *      @see            Object::Equals()
155          */
156         virtual bool Equals(const Object& obj) const;
157
158         /**
159          *      Gets the hash value of the current instance of %Long.
160          *
161          *      @since 2.0
162          *
163          *      @return         An integer value indicating the hash value of the current instance of %Long
164          *      @remarks        Two equal instances must return the same hash value. For better performance,
165          *                              the used hash function must generate a random distribution for all inputs. @n
166          *                              The default implementation of this method returns the value of the current instance.
167          */
168         virtual int GetHashCode(void) const;
169
170         /**
171         *        Gets the hash value of the specified @c long value.
172         *
173         *        @since 2.0
174         *
175         *        @return        An integer value indicating the hash value of the specified @c long value
176         *        @param[in]   val   A @c long value to get the hash value
177         */
178         static int GetHashCode(long val);
179
180         /**
181          *      Decodes a string into a @c signed @c long.
182          *
183          *      @since 2.0
184          *
185          *      @return         An error code
186          *      @param[in]      s                               A string representing a numeric value
187          *      @param[out]     ret                             The result of the operation
188          *      @exception      E_SUCCESS               The method is successful.
189          *      @exception      E_NUM_FORMAT    The specified string does not contain a number that can be parsed.
190          *      @remarks        This method accepts decimal, hexadecimal, and octal numbers given by the
191          *                              following grammar:
192          *      @code
193          *      - DecodableString:
194          *              Sign[opt] DecimalNumeral
195          *              Sign[opt] 0x HexDigits
196          *              Sign[opt] 0X HexDigits
197          *              Sign[opt] # HexDigits
198          *              Sign[opt] 0 OctalDigits
199          *      - Sign:
200          *              '-'
201          *      @endcode
202          */
203         static result Decode(const String& s, long& ret);
204
205         /**
206          *      Parses the @c signed @c long equivalent of the specified string representing a numeric value.
207          *
208          *      @since 2.0
209          *
210          *      @return         An error code
211          *      @param[in]      s                               A string representing a numeric value
212          *      @param[out]     ret                             The result of the operation
213          *      @exception      E_SUCCESS               The method is successful.
214          *      @exception      E_NUM_FORMAT    The specified string does not contain a number that can be parsed.
215          *      @remarks
216          *                              - This method assumes that the string representing the numeric value uses a radix 10.
217          *                              - This method guarantees that the original value of out-parameter is not changed when the method returns error.
218          */
219         static result Parse(const String& s, long& ret);
220
221         /**
222          *      Parses the @c signed @c long equivalent of the specified string representing a numeric value using the specified radix.
223          *
224          *      @since 2.0
225          *
226          *      @return         An error code
227          *      @param[in]      s                       A string representing a numeric value
228          *      @param[in]      radix           The radix of the string representing a numeric value @n
229          *                                                      It must be either 2, 8, 10, or 16.
230          *      @param[out]     ret                             The result of the operation
231          *      @exception      E_SUCCESS               The method is successful.
232          *      @exception      E_NUM_FORMAT    The specified string does not contain a number that can be parsed.
233          *      @exception      E_OUT_OF_RANGE The specified @c radix is invalid.
234          *      @remarks        This method guarantees that the original value of out-parameter is not changed when the method returns error.
235          */
236         static result Parse(const String& s, int radix, long& ret);
237
238         /**
239          *      Gets the @c signed @c char equivalent of the current instance of the %Long class.
240          *
241          *      @since 2.0
242          *
243          *      @return         The @c signed @c char equivalent of the current instance
244          */
245         virtual char ToChar(void) const;
246
247         /**
248          *      Gets the @c signed @c short equivalent of the current instance of the %Long class.
249          *
250          *      @since 2.0
251          *
252          *      @return         The @c signed @c short equivalent of the current instance
253          */
254         virtual short ToShort(void) const;
255
256         /**
257          *      Gets the @c signed @c int equivalent of the current instance of the %Long class.
258          *
259          *      @since 2.0
260          *
261          *      @return         The @c signed @c int equivalent of the current instance
262          */
263         virtual int ToInt(void) const;
264
265         /**
266          *      Gets the @c signed @c long equivalent of the current instance of the %Long class.
267          *
268          *      @since 2.0
269          *
270          *      @return         The @c signed @c long equivalent of the current instance
271          */
272         virtual long ToLong(void) const;
273
274         /**
275         *       Gets the @c signed @c long @c long equivalent of the current instance of the %Long class.
276         *
277         *       @since 2.0
278         *
279         *       @return         The @c signed @c long @c long equivalent of the current instance
280         */
281         virtual long long ToLongLong(void) const;
282
283         /**
284          *      Gets the @c signed @c float equivalent of the current instance of the %Long class.
285          *
286          *      @since 2.0
287          *
288          *      @return         The @c signed @c float equivalent of the current instance
289          */
290         virtual float ToFloat(void) const;
291
292         /**
293          *      Gets the @c signed @c double equivalent of the current instance of the %Long class.
294          *
295          *      @since 2.0
296          *
297          *      @return         The @c signed @c double equivalent of the current instance
298          */
299         virtual double ToDouble(void) const;
300
301         /**
302          *      Gets the string representing the value of the current instance of the %Long class.
303          *
304          *      @since 2.0
305          *
306          *      @return         The string representing the value of the current instance
307          */
308         virtual String ToString(void) const;
309
310         /**
311          *      Gets the string representing the specified @c signed @c long value.
312          *
313          *      @since 2.0
314          *
315          *      @return         The string containing a Unicode representation of the specified @c signed @c long value
316          *      @param[in]      value   A @c signed @c long value to convert
317          */
318         static String ToString(long value);
319
320         /**
321          *      A constant holding the maximum value a @c short can have; 2^31-1.
322          *
323          *      @since 2.0
324          */
325         static const long VALUE_MAX = (long) 0x7FFFFFFF;
326
327         /**
328          *      A constant holding the minimum value a @c short can have; -2^31.
329          *
330          *      @since 2.0
331          */
332         static const long VALUE_MIN = (long) 0x80000000;
333
334         /**
335          * A @c long value of this instance.
336          *
337          * @since 2.0
338          */
339         long value;
340
341
342 private:
343         friend class _LongImpl;
344         class _LongImpl * __pLongImpl;
345
346 }; // Long
347
348 }} // Tizen::Base
349
350 #endif //_FBASE_LONG_H_