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 %Long class.
23 * This header file contains the declarations of the %Long class.
25 #ifndef _FBASE_LONG_H_
26 #define _FBASE_LONG_H_
28 #include <FBaseNumber.h>
30 namespace Tizen { namespace Base
34 * @brief This class is the wrapper class for the @c signed @c long built-in type.
38 * The %Long class represents an integer value ranging from -2147483648 to 2147483647
39 * , that is, -(2^31) to +((2^31)-1). The 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 %Long (and @c long) to String, and %String
42 * to %Long (and @c long).
44 * The following example demonstrates how to use the %Long 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 Long MINIMUM(1230);
58 * result r = E_SUCCESS;
61 * r = Long::Parse(string, l);
67 * out = (MINIMUM.CompareTo(l) == 0) ? true: false;
75 class _OSP_EXPORT_ Long
80 * Initializes this instance of %Long with the specified value.
84 * @param[in] value A @c long value
89 * Copying of objects using this copy constructor is allowed.
93 * @param[in] value An instance of %Long
95 Long(const Long& value);
98 * This destructor overrides Tizen::Base::Object::~Object().
105 * Copying of objects using this copy assignment operator is allowed.
109 * @param[in] rhs An instance of %Long
111 Long& operator =(const Long& rhs);
114 * Compares two @c long values.
118 * @return A 32-bit @c signed integer value
120 * < 0 if the value of @c l1 is less than the value of @c l2
121 * == 0 if the value of @c l1 is equal to the value of @c l2
122 * > 0 if the value of @c l1 is greater than the value of @c l2
124 * @param[in] l1 The first @c long value to compare
125 * @param[in] l2 The second @c long value to compare
127 static int Compare(long l1, long l2);
130 * Compares the value of the current instance with the value of the specified instance of the %Long class.
134 * @return A 32-bit @c signed integer value
137 * < 0 if the value of the current instance is less than the value of the specified instance
138 * == 0 if the value of the current instance is equal to the value of the specified instance
139 * > 0 if the value of the current instance is greater than the value of the specified instance
141 * @param[in] value An instance of the %Long class to compare
143 int CompareTo(const Long& value) const;
146 * Checks whether the value of the specified instance of %Object is equal to the value of the current instance of %Long.
150 * @return @c true if the value of the specified instance of %Object is equal to the value of the current instance of %Long, @n
152 * @param[in] obj An instance of %Object to compare
153 * @see Object::Equals()
155 virtual bool Equals(const Object& obj) const;
158 * Gets the hash value of the current instance of %Long.
162 * @return An integer value indicating the hash value of the current instance of %Long
163 * @remarks Two equal instances must return the same hash value. For better performance,
164 * the used hash function must generate a random distribution for all inputs. @n
165 * The default implementation of this method returns the value of the current instance.
167 virtual int GetHashCode(void) const;
170 * Gets the hash value of the specified @c long value.
174 * @return An integer value indicating the hash value of the specified @c long value
175 * @param[in] val A @c long value to get the hash value
177 static int GetHashCode(long val);
180 * Decodes a string into a @c signed @c long.
184 * @return An error code
185 * @param[in] s A string representing a numeric value
186 * @param[out] ret The result of the operation
187 * @exception E_SUCCESS The method is successful.
188 * @exception E_NUM_FORMAT The specified string does not contain a number that can be parsed.
189 * @exception E_OUT_OF_RANGE The decoded value is not between VALUE_MIN and VALUE_MAX range.
192 * - This method guarantees that the original value of out-parameter is not changed when the method returns error.
193 * - This method accepts decimal, hexadecimal, and octal numbers given by the
197 * Sign[opt] DecimalNumeral
198 * Sign[opt] 0x HexDigits
199 * Sign[opt] 0X HexDigits
200 * Sign[opt] # HexDigits
201 * Sign[opt] 0 OctalDigits
206 static result Decode(const String& s, long& ret);
209 * Parses the @c signed @c long 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 number that can be parsed.
218 * @exception E_OUT_OF_RANGE The parsed value is not between VALUE_MIN and VALUE_MAX range.
221 * - This method assumes that the string representing the numeric value uses a radix 10.
222 * - This method guarantees that the original value of out-parameter is not changed when the method returns error.
224 static result Parse(const String& s, long& ret);
227 * Parses the @c signed @c long equivalent of the specified string representing a numeric value using the specified radix.
231 * @return An error code
232 * @param[in] s A string representing a numeric value
233 * @param[in] radix The radix of the string representing a numeric value @n
234 * Radix value range is from 2 to 36.
235 * @param[out] ret The result of the operation
236 * @exception E_SUCCESS The method is successful.
237 * @exception E_NUM_FORMAT The specified string does not contain a number that can be parsed.
238 * @exception E_OUT_OF_RANGE The specified @c radix is invalid or
239 * The parsed value is not between VALUE_MIN and VALUE_MAX range.
241 * @remarks This method guarantees that the original value of out-parameter is not changed when the method returns error.
243 static result Parse(const String& s, int radix, long& ret);
246 * Gets the @c char equivalent of the current instance of the %Long 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 The @c char equivalent of the current instance
258 virtual char ToChar(void) const;
261 * Gets the @c int8_t equivalent of the current instance of %Long.
265 * @return The @c int8_t equivalent of the current instance
268 virtual int8_t ToInt8(void) const;
271 * Gets the @c signed @c short equivalent of the current instance of the %Long class.
275 * @return The @c signed @c short equivalent of the current instance
277 virtual short ToShort(void) const;
280 * Gets the @c signed @c int equivalent of the current instance of the %Long class.
284 * @return The @c signed @c int equivalent of the current instance
286 virtual int ToInt(void) const;
289 * Gets the @c signed @c long equivalent of the current instance of the %Long class.
293 * @return The @c signed @c long equivalent of the current instance
295 virtual long ToLong(void) const;
298 * Gets the @c signed @c long @c long equivalent of the current instance of the %Long class.
302 * @return The @c signed @c long @c long equivalent of the current instance
304 virtual long long ToLongLong(void) const;
307 * Gets the @c signed @c float equivalent of the current instance of the %Long class.
311 * @return The @c signed @c float equivalent of the current instance
313 virtual float ToFloat(void) const;
316 * Gets the @c signed @c double equivalent of the current instance of the %Long class.
320 * @return The @c signed @c double equivalent of the current instance
322 virtual double ToDouble(void) const;
325 * Gets the string representing the value of the current instance of the %Long class.
329 * @return The string representing the value of the current instance
331 virtual String ToString(void) const;
334 * Gets the string representing the specified @c signed @c long value.
338 * @return The string containing a Unicode representation of the specified @c signed @c long value
339 * @param[in] value A @c signed @c long value to convert
341 static String ToString(long value);
344 * A constant holding the maximum value a @c short can have; 2^31-1.
348 static const long VALUE_MAX = static_cast< long >(0x7FFFFFFF);
351 * A constant holding the minimum value a @c short can have; -2^31.
355 static const long VALUE_MIN = static_cast< long >(0x80000000);
358 * A @c long value of this instance.
366 friend class _LongImpl;
367 class _LongImpl* __pLongImpl;
373 #endif //_FBASE_LONG_H_