2 // Copyright (c) 2013 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 FBaseInteger8.h
19 * @brief This is the header file for the %Integer8 class.
21 * @see Tizen::Base::Number
23 * This header file contains the declarations of the %Integer8 class.
25 #ifndef _FBASE_INTEGER8_H_
26 #define _FBASE_INTEGER8_H_
29 #include <FBaseNumber.h>
31 namespace Tizen { namespace Base
35 * @brief This class is the wrapper class for the @c 8-bits integral built-in type @c int8_t.
39 * The %Integer8 class represents an integer value ranging from -128 to 127. The class is useful when passing an 8-bit
40 * signed integral value to a method that accepts only an instance of Object. Furthermore, this class provides
41 * methods for converting %Integer8 (and @c char) to String, and %String to %Integer8 (and @c char).
43 * The following example demonstrates how to use the %Integer8 class.
48 * using namespace Tizen::Base;
50 * // This method checks whether the given string object contains a string
51 * // representation of the pre-defined minimum 8-bit integral value.
53 * MyClass::Verify(String& string, bool& out)
55 * static const Integer8 i1(123);
58 * result r = Integer8::Parse(string, int8Val);
59 * static const Integer8 i2(int8Val);
62 * out = (i1.CompareTo(i2) == 0) ? true: false;
69 class _OSP_EXPORT_ Integer8
74 * This is the default constructor for this class. Initializes the value to 0.
82 * Initializes this instance of %Integer8 with the specified value.
86 * @param[in] value A @c signed 8-bits integral @c int8_t value
88 explicit Integer8(int8_t value);
92 * Copying of objects using this copy constructor is allowed.
96 * @param[in] value An instance of %Integer8
98 Integer8(const Integer8& value);
101 * This destructor overrides Tizen::Base::Object::~Object().
105 virtual ~Integer8(void);
108 * Copying of objects using this copy assignment operator is allowed.
112 * @param[in] rhs An instance of %Integer8
114 Integer8& operator =(const Integer8& rhs);
117 * Compares two @c signed 8-bits integral @c int8_t values.
121 * @return A 32-bit @c signed integr value
123 * < 0 if the value of i81 is less than the value of i82
124 * == 0 if the value of i81 is equal to the value of i82
125 * > 0 if the value of i81 is greater than the value of i82
127 * @param[in] i81 The first @c signed 8-bits integral @c int8_t value to compare
128 * @param[in] i82 The second @c signed 8-bits integral @c int8_t value to compare
130 static int Compare(int8_t i81, int8_t i82);
133 * Compares the value of the current instance with the value of the specified instance of the %Integer8 class.
137 * @return A 32-bit @c signed integer value
139 * < 0 if the value of the current instance is less than the value of the specified instance
140 * == 0 if the value of the current instance is equal to the value of the specified instance
141 * > 0 if the value of the current instance is greater than the value of the specified instance
143 * @param[in] value An instance of the %Integer8 class to compare
145 int CompareTo(const Integer8& value) const;
148 * Checks whether the value of the specified instance of %Integer8 is equal to the value of the current instance.
152 * @return @c true if the value of the specified instance is equal to the value of the current instance, @n
154 * @param[in] obj An instance of Object to compare
155 * @see Tizen::Base::Object::Equals()
157 virtual bool Equals(const Object& obj) const;
160 * Gets the hash value of the current instance of %Integer8.
164 * @return An integer value indicating the hash value of the current instance of %Integer8
165 * @remarks Two equal instances must return the same hash value. For better performance,
166 * the used hash function must generate a random distribution for all inputs. @n
167 * The default implementation of this method returns the value of the current instance.
169 virtual int GetHashCode(void) const;
172 * Gets the hash value of the specified @c signed 8-bits integral @c int8_t value.
176 * @return An integer value indicating the hash value of the specified @c signed 8-bits integral @c int8_t value
177 * @param[in] val A @c signed 8-bits integral @c int8_t value to get the hash value
179 static int GetHashCode(int8_t val);
182 * Decodes a string into a @c signed 8-bits integral @c int8_t value.
186 * @return An error code
187 * @param[in] s A string representing a numeric value
188 * @param[out] ret The result of the operation
189 * @exception E_SUCCESS The method is successful.
190 * @exception E_NUM_FORMAT The specified string does not contain a number that can be parsed.
191 * @exception E_OUT_OF_RANGE The decoded value is not between VALUE_MIN and VALUE_MAX range.
192 * @remarks This method accepts decimal, hexadecimal, and octal numbers given by the
196 * Sign[opt] DecimalNumeral
197 * Sign[opt] 0x HexDigits
198 * Sign[opt] 0X HexDigits
199 * Sign[opt] # HexDigits
200 * Sign[opt] 0 OctalDigits
205 static result Decode(const String& s, int8_t& ret);
208 * Parses the specified string representing a @c signed 8-bits integral @c int8_t value and
209 * returns the value as @c signed 8-bits integral @c int8_t (as out parameter).
212 * @return An error code
213 * @param[in] s A string representing a numeric value
214 * @param[out] ret The @c signed 8-bits integral @c int8_t equivalent of the specified string representing the numeric value using the decimal radix.
215 * @exception E_SUCCESS The method is successful.
216 * @exception E_NUM_FORMAT The specified string does not contain a byte that can be parsed.
217 * @exception E_OUT_OF_RANGE The parsed value is not between VALUE_MIN and VALUE_MAX range.
219 * - This method assumes that the string representing the @c signed 8-bits integral value uses a radix 10.
220 * - This method guarantees that the original value of out-parameter is not changed when the method returns error.
222 static result Parse(const String& s, int8_t& ret);
225 * Parses the specified string representing a @c signed 8-bits integral @c int8_t value and
226 * returns the value as @c signed 8-bits integral @c int8_t (as out parameter).
230 * @return An error code
231 * @param[in] s A string representing a @c signed 8-bits integral value
232 * @param[in] radix The radix of the string representing a numeric value. Radix value range is from 2 to 36.
233 * @param[out] ret The @c signed 8-bits integral @c int8_t equivalent of the specified string representing the numeric value using the specified radix
234 * @exception E_SUCCESS The method is successful.
235 * @exception E_NUM_FORMAT The specified string does not contain a number that can be parsed.
236 * @exception E_OUT_OF_RANGE The specified @c radix is invalid, or
237 * The parsed value is not between VALUE_MIN and VALUE_MAX range.
238 * @remarks This method guarantees that the original value of out-parameter is not changed when the method returns error.
240 static result Parse(const String& s, int radix, int8_t& ret);
243 * Gets the @c signed @c char equivalent of the current instance of %Integer8.
247 * @return The @c signed @c char equivalent of the current instance
248 * @remarks This method has portability issue. Return value may not be @c signed @c char since char is treated as unsigned char in ARM architecture. @n
251 virtual char ToChar(void) const;
254 * Gets the @c signed @c short equivalent of the current instance of %Integer8.
258 * @return The @c signed @c short equivalent of the current instance
260 virtual short ToShort(void) const;
263 * Gets the @c signed @c int equivalent of the current instance of %Integer8.
267 * @return The @c signed @c int equivalent of the current instance
269 virtual int ToInt(void) const;
272 * Gets the @c signed @c long equivalent of the current instance of %Integer8.
276 * @return The @c signed @c long equivalent of the current instance
278 virtual long ToLong(void) const;
281 * Gets the @c signed @c long @c long equivalent of the current instance of %Integer8.
285 * @return The @c signed @c long @c long equivalent of the current instance
287 virtual long long ToLongLong(void) const;
290 * Gets the @c signed @c float equivalent of the current instance of %Integer8.
294 * @return The @c signed @c float equivalent of the current instance
296 virtual float ToFloat(void) const;
299 * Gets the @c signed @c double equivalent of the current instance of %Integer8.
303 * @return The @c signed @c double equivalent of the current instance
305 virtual double ToDouble(void) const;
308 * Gets the string representing the value of the current instance of %Integer8 using radix @c 10.
312 * @return A string representing the value of the current instance using radix 10
314 virtual String ToString(void) const;
317 * Gets the string representing the specified @c signed 8-bits integral @c int8_t value using radix @c 10.
321 * @return A string containing a Unicode representation of the specified @c signed 8-bits integral @c int8_t value using radix 10
322 * @param[in] value A @c signed 8-bits integral @c int8_t value
324 static String ToString(int8_t value);
327 * A constant holding the maximum value of type @c signed 8-bits integral value. @n
328 * A @c signed 8-bits integral can hold a maximum value of upto 2^7-1.
332 static const int8_t VALUE_MAX = static_cast<int8_t> (0x7F);
335 * A constant holding the minimum value of type @c signed 8-bits integral value. @n
336 * A @c signed 8-bits integral can hold a minimum value of upto -2^7.
340 static const int8_t VALUE_MIN = static_cast<int8_t> (0x80);
343 * A @c signed @c signed 8-bits integral value of this instance.
351 friend class _Integer8Impl;
352 class _Integer8Impl* __pInteger8Impl;
358 #endif //_FBASE_INTEGER8_H_