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 %Int8 class.
21 * @see Tizen::Base::Number
23 * This header file contains the declarations of the %Int8 class.
25 #ifndef _FBASE_INT8_H_
26 #define _FBASE_INT8_H_
28 #include <FBaseNumber.h>
30 namespace Tizen { namespace Base
34 * @brief This class is the wrapper class for the @c signed @c char built-in type.
38 * The %Int8 class represents an integer value ranging from -128 to 127. The class is useful when passing an 8-bit
39 * signed integral value to a method that accepts only an instance of Object. Furthermore, this class provides
40 * methods for converting %Int8 (and @c char) to String, and %String to %Int8 (and @c char).
42 * The following example demonstrates how to use the %Int8 class.
47 * using namespace Tizen::Base;
49 * // This method checks whether the given string object contains a string
50 * // representation of the pre-defined minimum 8-bit integral value.
52 * MyClass::Verify(String& string, bool& out)
54 * static const Int8 MINIMUM(123);
56 * result r = E_SUCCESS;
59 * r = Int8::Parse(string, ch);
65 * out = (MINIMUM.CompareTo(ch) == 0) ? true: false;
73 class _OSP_EXPORT_ Int8
78 * Initializes this instance of %Int8 with the specified value.
82 * @param[in] value A @c char value
87 * Copying of objects using this copy constructor is allowed.
91 * @param[in] value An instance of %Int8
93 Int8(const Int8& value);
96 * This destructor overrides Tizen::Base::Object::~Object().
103 * Copying of objects using this copy assignment operator is allowed.
107 * @param[in] rhs An instance of %Int8
109 Int8& operator =(const Int8& rhs);
112 * Compares two @c char values.
116 * @return A 32-bit @c signed integer value
118 * < 0 if the value of ch1 is less than the value of ch2
119 * == 0 if the value of ch1 is equal to the value of ch2
120 * > 0 if the value of ch1 is greater than the value of ch2
122 * @param[in] ch1 The first @c char value to compare
123 * @param[in] ch2 The second @c char value to compare
125 static int Compare(char ch1, char ch2);
128 * Compares the value of the current instance with the value of the specified instance of the %Int8 class.
132 * @return A 32-bit @c signed integer value
134 * < 0 if the value of the current instance is less than the value of the specified instance
135 * == 0 if the value of the current instance is equal to the value of the specified instance
136 * > 0 if the value of the current instance is greater than the value of the specified instance
138 * @param[in] value An instance of the %Int8 class to compare
140 int CompareTo(const Int8& value) const;
143 * Checks whether the value of the specified instance of %Int8 is equal to the value of the current instance.
147 * @return @c true if the value of the specified instance is equal to the value of the current instance, @n
149 * @param[in] obj An instance of Object to compare
150 * @see Tizen::Base::Object::Equals()
152 virtual bool Equals(const Object& obj) const;
155 * Gets the hash value of the current instance of %Int8.
159 * @return An integer value indicating the hash value of the current instance of %Int8
160 * @remarks Two equal instances must return the same hash value. For better performance,
161 * the used hash function must generate a random distribution for all inputs. @n
162 * The default implementation of this method returns the value of the current instance.
164 virtual int GetHashCode(void) const;
167 * Gets the hash value of the specified @c char value.
171 * @return An integer value indicating the hash value of the specified @c char value
172 * @param[in] val A @c char value to get the hash value
174 static int GetHashCode(char val);
177 * Decodes a string into a @c signed @c char.
181 * @return An error code
182 * @param[in] s A string representing a numeric value
183 * @param[out] ret The result of the operation
184 * @exception E_SUCCESS The method is successful.
185 * @exception E_NUM_FORMAT The specified string does not contain a number that can be parsed.
186 * @remarks This method accepts decimal, hexadecimal, and octal numbers given by the
190 * Sign[opt] DecimalNumeral
191 * Sign[opt] 0x HexDigits
192 * Sign[opt] 0X HexDigits
193 * Sign[opt] # HexDigits
194 * Sign[opt] 0 OctalDigits
198 * @remarks This method has portability issue. @n
199 * When the specified string is nagative number in the ARM architecture, type casting is needed like following code.
202 * Int8::Decode(L"-0X20", ret);
203 * SomeOutputFunction(static_cast< signed char >(ret));
206 static result Decode(const String& s, char& ret);
209 * Parses the @c signed @c char equivalent of the specified string representing a numeric value.
213 * @return An error code
214 * @param[in] s A string representing a numeric value
215 * @param[out] ret The result of the operation
216 * @exception E_SUCCESS The method is successful.
217 * @exception E_NUM_FORMAT The specified string does not contain a byte that can be parsed.
219 * - This method assumes that the string representing the numeric 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, char& ret);
225 * Parses the specified string representing a numeric value and
226 * returns the value as @c signed @c char (as out parameter).
230 * @return The @c signed @c char equivalent of the specified string representing the numeric value using the specified index
231 * @param[in] s A string representing a numeric value
232 * @param[in] radix The radix of the string representing a numeric value @n
233 * It must either be 2, 8, 10, or 16.
234 * @param[out] ret The result of the operation
235 * @exception E_SUCCESS The method is successful.
236 * @exception E_NUM_FORMAT The specified string does not contain a number that can be parsed.
237 * @exception E_OUT_OF_RANGE The specified @c radix is invalid.
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, char& ret);
243 * Gets the @c signed @c char equivalent of the current instance of %Int8.
247 * @return The @c signed @c char equivalent of the current instance
249 virtual char ToChar(void) const;
252 * Gets the @c signed @c short equivalent of the current instance of %Int8.
256 * @return The @c signed @c short equivalent of the current instance
258 virtual short ToShort(void) const;
261 * Gets the @c signed @c int equivalent of the current instance of %Int8.
265 * @return The @c signed @c int equivalent of the current instance
267 virtual int ToInt(void) const;
270 * Gets the @c signed @c long equivalent of the current instance of %Int8.
274 * @return The @c signed @c long equivalent of the current instance
276 virtual long ToLong(void) const;
279 * Gets the @c signed @c long @c long equivalent of the current instance of %Int8.
283 * @return The @c signed @c long @c long equivalent of the current instance
285 virtual long long ToLongLong(void) const;
288 * Gets the @c signed @c float equivalent of the current instance of %Int8.
292 * @return The @c signed @c float equivalent of the current instance
294 virtual float ToFloat(void) const;
297 * Gets the @c signed @c double equivalent of the current instance of %Int8.
301 * @return The @c signed @c double equivalent of the current instance
303 virtual double ToDouble(void) const;
306 * Gets the string representing the value of the current instance of %Int8.
310 * @return A string representing the value of the current instance
312 virtual String ToString(void) const;
315 * Gets the string representing the specified @c signed @c char value using radix @c 10.
319 * @return A string containing a Unicode representation of the specified @c char value using radix 10
320 * @param[in] value A @c char value
322 static String ToString(char value);
325 * A constant holding the maximum value of type @c char. @n
326 * A @c short character can hold a value of upto 2^7-1.
330 static const char VALUE_MAX = (signed char) 0x7F;
333 * A constant holding the minimum value of type @c char. @n
334 * A @c short character can hold a value of upto -2^7.
338 static const char VALUE_MIN = (signed char) 0x80;
341 * A @c signed @c char value of this instance.
349 friend class _Int8Impl;
350 class _Int8Impl* __pInt8Impl;
356 #endif //_FBASE_INT8_H_