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