Parse() remains original value when the function returns errror
[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
235          *                              - This method assumes that the string representing the numeric value uses a radix 10.
236          *                              - This method guarantees that the original value of out-parameter is not changed when the method returns error.
237          */
238         static result Parse(const String& s, short& ret);
239
240         /**
241          *      Parses the specified string representing a numeric value
242          *      using the specified radix and returns the value as @c signed @c short.
243          *
244          *      @since 2.0
245          *
246          *      @return         An error code
247          *      @param[in]      s               A string representing a numeric value
248          *      @param[in]      radix           The radix of the string representing a numeric value @n
249          *                                              It must either be @c 2, @c 8, @c 10, or @c 16.
250          *      @param[out]     ret                             The result of the operation
251          *      @exception      E_SUCCESS               The method is successful.
252          *      @exception      E_NUM_FORMAT    The specified string does not contain a number that can be parsed.
253          *      @exception      E_OUT_OF_RANGE The specified @c radix is invalid.
254          *      @remarks        This method guarantees that the original value of out-parameter is not changed when the method returns error.
255          */
256         static result Parse(const String& s, int radix, short& ret);
257
258         /**
259          *      Gets the @c signed @c char equivalent of the current instance of the %Short class.
260          *
261          *      @since 2.0
262          *
263          *      @return A @c signed @c char equivalent of the current instance
264          */
265         virtual char ToChar(void) const;
266
267         /**
268          *      Gets the @c signed @c short equivalent of the current instance of the %Short class.
269          *
270          *      @since 2.0
271          *
272          *      @return A @c signed @c short equivalent of the current instance
273          */
274         virtual short ToShort(void) const;
275
276         /**
277          *      Gets the @c signed @c int equivalent of the current instance of the %Short class.
278          *
279          *      @since 2.0
280          *
281          *      @return A @c signed @c int equivalent of the current instance
282          */
283         virtual int ToInt(void) const;
284
285         /**
286          *      Gets the @c signed @c long equivalent of the current instance of the %Short class.
287          *
288          *      @since 2.0
289          *
290          *      @return A @c signed @c long equivalent of the current instance
291          */
292         virtual long ToLong(void) const;
293
294         /**
295         *       Gets the @c signed @c long @c long equivalent of the current instance of the %Short class.
296         *
297         *       @since 2.0
298         *
299         *       @return A @c signed @c long @c long equivalent of the current instance
300         */
301         virtual long long ToLongLong(void) const;
302
303         /**
304          *      Gets the @c signed @c float equivalent of the current instance of the %Short class.
305          *
306          *      @since 2.0
307          *
308          *      @return A @c signed @c float equivalent of the current instance
309          */
310         virtual float ToFloat(void) const;
311
312         /**
313          *      Gets the @c signed @c double equivalent of the current instance of the %Short class.
314          *
315          *      @since 2.0
316          *
317          *      @return A @c signed @c double equivalent of the current instance
318          */
319         virtual double ToDouble(void) const;
320
321         /**
322          * Gets the string representing the value of the current instance of the %Short class.
323          *
324          *      @since 2.0
325          *
326          *  @return             A string representing the value of the current instance
327          */
328         virtual String ToString(void) const;
329
330         /**
331          *      Gets the string representing the specified @c signed @c short value.
332          *
333          *      @since 2.0
334          *
335          *      @return                 A string containing a Unicode representation of the specified @c signed @c short value
336          *      @param[in]      value   A @c signed @c short value to convert
337          */
338         static String ToString(short value);
339
340         /**
341          *      A constant holding the maximum value a @c short will be equal to 2^15-1.
342          *
343          *      @since 2.0
344          */
345         static const short VALUE_MAX = (short) 0x7FFF;
346
347         /**
348          *      A constant holding the minimum value a @c short will be equal to -2^15.
349          *
350          *      @since 2.0
351          */
352         static const short VALUE_MIN = (short) 0x8000;
353
354         /**
355          * A @c short value of this instance.
356          *
357          * @since 2.0
358          */
359         short value;
360
361
362 private:
363         friend class _ShortImpl;
364         class _ShortImpl * __pShortImpl;
365
366 }; // Short
367
368 }} // Tizen::Base
369
370 #endif //_FBASE_SHORT_H_