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