2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
20 * @brief This is the header file for the %Short class.
24 * This header file contains the declarations of the %Short class.
26 #ifndef _FBASE_SHORT_H_
27 #define _FBASE_SHORT_H_
29 #include <FBaseNumber.h>
32 namespace Tizen { namespace Base
36 * @brief This class is the wrapper class for the @c signed @c short built-in type.
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
45 * The following example demonstrates how to use the %Short class.
51 * using namespace Tizen::Base;
53 * // This method checks whether the given string object contains a string
54 * // representation of the pre-defined minimum 16-bit integral value
56 * MyClass::Verify(String& string, bool& out)
58 * static const Short MINIMUM(1230);
60 * result r = E_SUCCESS;
63 * r = Short::Parse(string, s)
69 * out = (MINIMUM.Compare(s) == 0) ? true: false;
77 class _OSP_EXPORT_ Short
82 * Initializes this instance of %Short with the specified @c value.
86 * @param[in] value A @c short value
88 Short(short value = 0);
91 * This is the copy constructor for the %Short class.
95 * @param[in] value An instance of %Short
97 Short(const Short& value);
100 * This is the destructor for this class.
104 virtual ~Short(void);
107 * Assigns the value of the specified instance to the current instance of %Short.
111 * @param[in] rhs An instance of %Short
113 Short& operator =(const Short& rhs);
116 * Compares the specified @c short values.
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
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
130 static int Compare(short s1, short s2);
133 * Compares the value of the current instance of the %Short class
134 * with the value of the specified instance of the %Short class.
138 * @return A @c signed 32-bit @c integer value
139 * @param[in] value An instance of the %Short class to compare
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
147 int CompareTo(const Short& value) const;
150 * Checks whether the value of the specified instance of Object is equal to the value of the current instance of %Short.
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
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
159 * @see Tizen::Base::Object::Equals()
161 virtual bool Equals(const Object& obj) const;
165 * Checks whether the value of the current instance is equal to the specified @c short value.
169 * @return @c true if the value of the current instance is equal to the specified @c short value, @n
171 * @param[in] value A @c short value to compare
173 bool Equals(short value) const;
176 * Gets the hash value of the current instance of %Short.
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.
185 virtual int GetHashCode(void) const;
188 * Gets the hash value of the specified @c short value.
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
195 static int GetHashCode(short val);
198 * Decodes a string into a @c signed @c short.
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
212 * Sign[opt] DecimalNumeral
213 * Sign[opt] 0x HexDigits
214 * Sign[opt] 0X HexDigits
215 * Sign[opt] # HexDigits
216 * Sign[opt] 0 OctalDigits
221 static result Decode(const String& s, short& ret);
224 * Parses the specified string representing a numeric value and
225 * returns the value as @c signed @c short.
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
237 static result Parse(const String& s, short& ret);
240 * Parses the specified string representing a numeric value
241 * using the specified radix and returns the value as @c signed @c short.
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.
254 static result Parse(const String& s, int radix, short& ret);
257 * Gets the @c signed @c char equivalent of the current instance of the %Short class.
261 * @return A @c signed @c char equivalent of the current instance
263 virtual char ToChar(void) const;
266 * Gets the @c signed @c short equivalent of the current instance of the %Short class.
270 * @return A @c signed @c short equivalent of the current instance
272 virtual short ToShort(void) const;
275 * Gets the @c signed @c int equivalent of the current instance of the %Short class.
279 * @return A @c signed @c int equivalent of the current instance
281 virtual int ToInt(void) const;
284 * Gets the @c signed @c long equivalent of the current instance of the %Short class.
288 * @return A @c signed @c long equivalent of the current instance
290 virtual long ToLong(void) const;
293 * Gets the @c signed @c long @c long equivalent of the current instance of the %Short class.
297 * @return A @c signed @c long @c long equivalent of the current instance
299 virtual long long ToLongLong(void) const;
302 * Gets the @c signed @c float equivalent of the current instance of the %Short class.
306 * @return A @c signed @c float equivalent of the current instance
308 virtual float ToFloat(void) const;
311 * Gets the @c signed @c double equivalent of the current instance of the %Short class.
315 * @return A @c signed @c double equivalent of the current instance
317 virtual double ToDouble(void) const;
320 * Gets the string representing the value of the current instance of the %Short class.
324 * @return A string representing the value of the current instance
326 virtual String ToString(void) const;
329 * Gets the string representing the specified @c signed @c short value.
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
336 static String ToString(short value);
339 * A constant holding the maximum value a @c short will be equal to 2^15-1.
343 static const short VALUE_MAX = (short) 0x7FFF;
346 * A constant holding the minimum value a @c short will be equal to -2^15.
350 static const short VALUE_MIN = (short) 0x8000;
353 * A @c short value of this instance.
361 friend class _ShortImpl;
362 class _ShortImpl * __pShortImpl;
368 #endif //_FBASE_SHORT_H_