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.
18 * @file FBaseInteger.h
19 * @brief This is the header file for the %Integer class.
21 * @see Number() class()
23 * This header file contains the declarations of the %Integer class.
25 #ifndef _FBASE_INTEGER_H_
26 #define _FBASE_INTEGER_H_
28 #include <FBaseNumber.h>
30 namespace Tizen { namespace Base
34 * @brief This class is the wrapper class for the @c signed @c int built-in type.
38 * The %Integer class represents an integer value ranging from -2147483648 to 2147483647,
39 * that is, -(2^31) to +((2^31)-1). This class is useful when passing a 32-bit @c signed
40 * integral value to a method that accepts only an instance of Object. Furthermore,
41 * this class provides methods for converting %Integer (and @c int) to String, and %String
42 * to %Integer (and @c int).
44 * The following example demonstrates how to use the %Integer 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 32-bit integral value.
55 * MyClass::Verify(String& string, bool& out)
57 * static const Integer MINIMUM(1230);
59 * result r = E_SUCCESS;
62 * r = Integer::Parse(string, i);
68 * out = (MINIMUM.CompareTo(i) == 0) ? true: false;
76 class _OSP_EXPORT_ Integer
81 * Initializes this instance of %Integer with the specified value.
85 * @param[in] value An integer value
87 Integer(int value = 0);
90 * Copying of objects using this copy constructor is allowed.
94 * @param[in] value An instance of %Integer
96 Integer(const Integer& value);
99 * This destructor overrides Tizen::Base::Object::~Object().
103 virtual ~Integer(void);
106 * Copying of objects using this copy assignment operator is allowed.
110 * @param[in] rhs An instance of %Integer
112 Integer& operator =(const Integer& rhs);
115 * Compares two @c int values.
119 * @return A 32-bit @c signed integer value
121 * < 0 if the value of @c i1 is less than the value of @c i2
122 * == 0 if the value of @c i1 is equal to the value of @c i2
123 * > 0 if the value of @c i1 is greater than the value of @c i2
125 * @param[in] i1 The first @c int value to compare
126 * @param[in] i2 The second @c int value to compare
128 static int Compare(int i1, int i2);
131 * Compares the value of the current instance with the value of the specified instance of the %Integer class.
135 * @return A 32-bit @c signed integer value
138 * < 0 if the value of the current instance is less than the value of the specified instance
139 * == 0 if the value of the current instance is equal to the value of the specified instance
140 * > 0 if the value of the current instance is greater than the value of the specified instance
142 * @param[in] value An instance of the %Integer class to compare
144 int CompareTo(const Integer& value) const;
147 * Checks whether the value of the specified instance of Object is equal to the value of the current instance of %Integer.
151 * @return @c true if the value of the specified instance of Object is equal to the value of the current instance of %Integer, @n
153 * @param[in] obj An instance of Object to compare
154 * @see Tizen::Base::Object::Equals()
156 virtual bool Equals(const Object& obj) const;
159 * Decodes a string into a @c signed @c int.
163 * @return An error code
164 * @param[in] s A string representing the numeric value
165 * @param[out] ret The result of the operation
166 * @exception E_SUCCESS The method is successful.
167 * @exception E_NUM_FORMAT The specified string does not contain a number that can be parsed.
168 * @exception E_OUT_OF_RANGE The decoded value is not between VALUE_MIN and VALUE_MAX range.
171 * - This method guarantees that the original value of out-parameter is not changed when the method returns error.
172 * - This method accepts decimal, hexadecimal, and octal numbers given by the
176 * Sign[opt] DecimalNumeral
177 * Sign[opt] 0x HexDigits
178 * Sign[opt] 0X HexDigits
179 * Sign[opt] # HexDigits
180 * Sign[opt] 0 OctalDigits
185 static result Decode(const String& s, int& ret);
188 * Gets the hash value of the current instance of %Integer.
192 * @return An integer value indicating the hash value of the current instance of %Integer
193 * @remarks Two equal instances must return the same hash value. For better performance,
194 * the used hash function must generate a random distribution for all inputs. @n
195 * The default implementation of this method returns the value of the current instance.
197 virtual int GetHashCode(void) const;
200 * Gets the hash value of the specified @c int value.
204 * @return An integer value indicating the hash value of the specified @c int value
205 * @param[in] val A @c int value to get the hash value
207 static int GetHashCode(int val);
210 * Parses the @c signed @c int equivalent of the specified string representing a numeric value.
214 * @return An error code
215 * @param[in] s A string representing a numeric value
216 * @param[out] ret The result of the operation
217 * @exception E_SUCCESS The method is successful.
218 * @exception E_NUM_FORMAT The specified string does not contain a number that can be parsed.
219 * @exception E_OUT_OF_RANGE The parsed value is not between VALUE_MIN and VALUE_MAX range.
222 * - This method assumes that the string representing the numeric value uses a radix 10.
223 * - This method guarantees that the original value of out-parameter is not changed when the method returns error.
225 static result Parse(const String& s, int& ret);
228 * Parses the @c signed @c int equivalent of the specified string representing a numeric value using the specified radix.
232 * @return An error code
233 * @param[in] s A string representing a numeric value
234 * @param[in] radix The radix of the string representing the numeric value @n
235 * Radix value range is from 2 to 36.
236 * @param[out] ret The result of the operation
237 * @exception E_SUCCESS The method is successful.
238 * @exception E_NUM_FORMAT The specified string does not contain a number that can be parsed.
239 * @exception E_OUT_OF_RANGE The specified @c radix is invalid or
240 * The parsed value is not between VALUE_MIN and VALUE_MAX range.
242 * @remarks This method guarantees that the original value of out-parameter is not changed when the method returns error.
244 static result Parse(const String& s, int radix, int& ret);
247 * Gets the @c char equivalent of the current instance of the %Integer class.
250 * @brief <i> [Deprecated] </i>
252 * @deprecated This method has portability issue.
253 * Return value may not be @c signed @c char since char is treated as unsigned char in ARM architecture. @n
254 * Use ToInt8() method to get @c int8_t
256 * @return A @c char equivalent of the current instance
259 virtual char ToChar(void) const;
262 * Gets the @c int8_t equivalent of the current instance of %Integer.
266 * @return The @c int8_t equivalent of the current instance
269 virtual int8_t ToInt8(void) const;
272 * Gets the @c signed @c short equivalent of the current instance of the %Integer class.
276 * @return A @c signed @c short equivalent of the current instance
278 virtual short ToShort(void) const;
281 * Gets the @c signed @c int equivalent of the current instance of the %Integer class.
285 * @return A @c signed @c int equivalent of the current instance
287 virtual int ToInt(void) const;
290 * Gets the @c signed @c long equivalent of the current instance of the %Integer class.
294 * @return A @c signed @c long equivalent of the current instance
296 virtual long ToLong(void) const;
299 * Gets the @c signed @c long @c long equivalent of the current instance of the %Integer class.
303 * @return A @c signed @c long @c long equivalent of the current instance
305 virtual long long ToLongLong(void) const;
308 * Gets the @c signed @c float equivalent of the current instance of the %Integer class.
312 * @return A @c signed @c float equivalent of the current instance
314 virtual float ToFloat(void) const;
317 * Gets the @c signed @c double equivalent of the current instance of the %Integer class.
321 * @return A @c signed @c double equivalent of the current instance
323 virtual double ToDouble(void) const;
326 * Gets the string representing the value of the current instance of the %Integer class.
330 * @return A string representing the value of the current instance
332 virtual String ToString(void) const;
335 * Gets the string representing the specified @c signed @c int value.
339 * @return A string containing a Unicode representation of the specified @c signed @c int value
340 * @param[in] value A @c signed @c int value to convert
342 static String ToString(int value);
345 * A constant holding the maximum value of type @c int. @n
346 * A @c short integer can hold a value of upto 2^31-1.
350 static const int VALUE_MAX = static_cast< int >(0x7FFFFFFF);
353 * A constant holding the minimum value of type @c int. @n
354 * A @c short integer can hold a value of upto -2^31.
358 static const int VALUE_MIN = static_cast< int >(0x80000000);
361 * An integer value of this instance.
369 friend class _IntegerImpl;
370 class _IntegerImpl* __pIntegerImpl;
376 #endif //_FBASE_INTEGER_H_