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