2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @brief This is the header file for the %Short class.
21 * This header file contains the declarations of the %Short class.
23 * @see Tizen::Base::Number
25 #ifndef _FBASE_SHORT_H_
26 #define _FBASE_SHORT_H_
28 #include <FBaseNumber.h>
31 namespace Tizen { namespace Base
35 * @brief This class is the wrapper class for the @c signed @c short built-in type.
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
44 * The following example demonstrates how to use the %Short class.
50 * using namespace Tizen::Base;
52 * // This method checks whether the given string object contains a string
53 * // representation of the pre-defined minimum 16-bit integral value
55 * MyClass::Verify(String& string, bool& out)
57 * static const Short MINIMUM(1230);
59 * result r = E_SUCCESS;
62 * r = Short::Parse(string, s)
68 * out = (MINIMUM.Compare(s) == 0) ? true: false;
76 class _OSP_EXPORT_ Short
81 * Initializes this instance of %Short with the specified @c value.
85 * @param[in] value The @c short value
87 Short(short value = 0);
90 * This is the copy constructor for the %Short class.
94 * @param[in] value An instance of %Short to copy
96 Short(const Short& value);
99 * This is the destructor for this class.
103 virtual ~Short(void);
106 * Assigns the value of the specified instance to the current instance of %Short.
110 * @param[in] rhs An instance of %Short
112 Short& operator =(const Short& rhs);
115 * Compares the specified @c short values.
119 * @return The 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
124 * < 0 if s1 is less than s2
125 * == 0 if s1 is equal to s2
126 * > 0 if s1 is greater than s2
129 static int Compare(short s1, short s2);
132 * Compares the value of the current instance of %Short
133 * with the value of the specified instance of %Short.
137 * @return The @c signed 32-bit @c integer value
138 * @param[in] value An instance of %Short to compare
141 * < 0 if the value of the current instance is less than the specified instance
142 * == 0 if the value of the current instance is equal to the specified instance
143 * > 0 if the value of the current instance is greater than the specified instance
146 int CompareTo(const Short& value) const;
149 * Checks whether the value of the specified instance of Object is equal to the value of the current instance of %Short.
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
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
158 * @see Tizen::Base::Object::Equals()
160 virtual bool Equals(const Object& obj) const;
164 * Checks whether the value of the current instance is equal to the specified @c short value.
168 * @return @c true if the value of the current instance is equal to the specified @c short value, @n
170 * @param[in] value The @c short value to compare
172 bool Equals(short value) const;
175 * Gets the hash value of the current instance of %Short.
179 * @return The integer value that indicates the hash value of the current instance of %Short
181 * - Two equal instances must return the same hash value. @n
182 * For better performance, the used hash function must generate a random distribution for all the 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 The integer value that indicates the hash value of the specified @c short value
193 * @param[in] val The @c short value used 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 The 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 that represents a numeric value and
225 * returns the value as @c signed @c short.
229 * @return An error code
230 * @param[in] s The string that represents the 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.
235 * - This method assumes that the string that represents the numeric value that uses a radix @c 10.
236 * - This method guarantees that the original value of the out-parameter is not changed when the method returns an error.
238 static result Parse(const String& s, short& ret);
241 * Parses the specified string that represents a numeric value
242 * using the specified radix and returns the value as @c signed @c short.
246 * @return An error code
247 * @param[in] s The string that represents the numeric value
248 * @param[in] radix The radix of the string that represents the numeric value @n
249 * It must either be 2, 8, 10, or 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 the out-parameter is not changed when the method returns an error.
256 static result Parse(const String& s, int radix, short& ret);
259 * Gets the @c signed @c char equivalent of the current instance of %Short.
263 * @return The @c signed @c char equivalent of the current instance
265 virtual char ToChar(void) const;
268 * Gets the @c signed @c short equivalent of the current instance of %Short.
272 * @return The @c signed @c short equivalent of the current instance
274 virtual short ToShort(void) const;
277 * Gets the @c signed @c int equivalent of the current instance of %Short.
281 * @return The @c signed @c int equivalent of the current instance
283 virtual int ToInt(void) const;
286 * Gets the @c signed @c long equivalent of the current instance of %Short.
290 * @return The @c signed @c long equivalent of the current instance
292 virtual long ToLong(void) const;
295 * Gets the @c signed @c long @c long equivalent of the current instance of %Short.
299 * @return The @c signed @c long @c long equivalent of the current instance
301 virtual long long ToLongLong(void) const;
304 * Gets the @c signed @c float equivalent of the current instance of %Short.
308 * @return The @c signed @c float equivalent of the current instance
310 virtual float ToFloat(void) const;
313 * Gets the @c signed @c double equivalent of the current instance of %Short.
317 * @return The @c signed @c double equivalent of the current instance
319 virtual double ToDouble(void) const;
322 * Gets the string that represents the value of the current instance of %Short.
326 * @return The string that represents the value of the current instance
328 virtual String ToString(void) const;
331 * Gets the string that represents the specified @c signed @c short value.
335 * @return The string that contains the Unicode representation of the specified @c signed @c short value
336 * @param[in] value The @c signed @c short value to convert
338 static String ToString(short value);
341 * The constant holding the maximum value a @c short can be equal to 2^15-1.
345 static const short VALUE_MAX = (short) 0x7FFF;
348 * The constant holding the minimum value a @c short can be equal to -2^15.
352 static const short VALUE_MIN = (short) 0x8000;
355 * The @c short value of this instance.
363 friend class _ShortImpl;
364 class _ShortImpl * __pShortImpl;
370 #endif //_FBASE_SHORT_H_