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 FBaseLongLong.h
19 * @brief This is the header file for the %LongLong class.
21 * @see Tizen::Base::Number
23 * This header file contains the declarations of the %LongLong class.
25 #ifndef _FBASE_LONG_LONG_H_
26 #define _FBASE_LONG_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 @c long built-in type.
38 * The %LongLong class represents an integer value ranging from -9223372036854775808 to 9223372036854775807
39 * , that is, -(2^63) to +((2^63)-1). The class is useful when passing a 64-bit @c signed
40 * integral value to a method that accepts only an instance of Object. Furthermore,
41 * this class provides methods for converting %LongLong (and @c long @c long) to String, and %String
42 * to %LongLong (and @c long @c long).
44 * The following example demonstrates how to use the %LongLong 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 64-bit integral value
55 * MyClass::Verify(String& string, bool& out)
57 * static const LongLong MINIMUM(123456789);
58 * result r = E_SUCCESS;
61 * r = LongLong::Parse(string, l);
67 * out = (MINIMUM.CompareTo(l) == 0) ? true: false;
75 class _OSP_EXPORT_ LongLong
80 * Initializes this instance of %LongLong with the specified value.
84 * @param[in] value A @c long @c long value
86 LongLong(long long value = 0);
89 * Copying of objects using this copy constructor is allowed.
93 * @param[in] value An instance of %LongLong
95 LongLong(const LongLong& value);
98 * This destructor overrides Tizen::Base::Object::~Object().
102 virtual ~LongLong(void);
105 * Copying of objects using this copy assignment operator is allowed.
109 * @param[in] rhs An instance of %LongLong
111 LongLong& operator =(const LongLong& rhs);
114 * Compares two @c long @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 @c long value to compare
125 * @param[in] l2 The second @c long @c long value to compare
127 static int Compare(long long l1, long long l2);
130 * Compares the value of the current instance with the value of the specified instance of the %LongLong class.
134 * @return A 32-bit @c signed integer value
136 * < 0 if the value of the current instance is less than the value of the specified instance
137 * == 0 if the value of the current instance is equal to the value of the specified instance
138 * > 0 if the value of the current instance is greater than the value of the specified instance
140 * @param[in] value An instance of the %LongLong class to compare
142 int CompareTo(const LongLong& value) const;
145 * Checks whether the value of the specified instance of Object is equal to the value of the current instance of %LongLong.
149 * @return @c true if the value of the specified instance of Object is equal to the value of the current instance of %LongLong, @n
151 * @param[in] obj An instance of Object to compare
152 * @see Tizen::Base::Object::Equals()
154 virtual bool Equals(const Object& obj) const;
157 * Gets the hash value of the current instance of %LongLong.
161 * @return An integer value indicating the hash value of the current instance of %LongLong
162 * @remarks Two equal instances must return the same hash value. For better performance,
163 * the used hash function must generate a random distribution for all inputs. @n
164 * The default implementation of this method returns the value of the current instance.
166 virtual int GetHashCode(void) const;
169 * Gets the hash value of the specified @c long @c long value.
173 * @return An integer value indicating the hash value of the specified @c long @c long value
174 * @param[in] val A @c long @c long value to get the hash value
176 static int GetHashCode(long long val);
179 * Gets the @c char equivalent of the current instance of the %LongLong class.
183 * @brief <i> [Deprecated] </i>
185 * @deprecated This method has portability issue.
186 * Return value may not be @c signed @c char since char is treated as unsigned char in ARM architecture. @n
187 * Use ToInt8() method to get @c int8_t
189 * @return The @c char equivalent of the current instance
191 virtual char ToChar(void) const;
194 * Gets the @c int8_t equivalent of the current instance of %LongLong.
198 * @return The @c int8_t equivalent of the current instance
201 virtual int8_t ToInt8(void) const;
204 * Gets the @c signed @c short equivalent of the current instance of the %LongLong class.
208 * @return The @c signed @c short equivalent of the current instance
210 virtual short ToShort(void) const;
213 * Gets the @c signed @c int equivalent of the current instance of the %LongLong class.
217 * @return The @c signed @c int equivalent of the current instance
219 virtual int ToInt(void) const;
222 * Gets the @c signed @c long equivalent of the current instance of the %LongLong class.
226 * @return The @c signed @c long equivalent of the current instance
228 virtual long ToLong(void) const;
231 * Gets the @c signed @c float equivalent of the current instance of the %LongLong class.
235 * @return The @c signed @c float equivalent of the current instance
237 virtual float ToFloat(void) const;
240 * Gets the @c signed @c double equivalent of the current instance of the %LongLong class.
244 * @return The @c signed @c double equivalent of the current instance
246 virtual double ToDouble(void) const;
249 * Gets the @c signed @c long @c long equivalent of the current instance of the %LongLong class.
253 * @return The @c signed @c long @c long equivalent of the current instance
255 virtual long long ToLongLong(void) const;
258 * Gets the string representing the value of the current instance of the %LongLong class.
262 * @return The string representing the value of the current instance
264 virtual String ToString(void) const;
267 * Gets the string representing the specified @c signed @c long @c long value.
271 * @return The string containing a Unicode representation of the specified @c signed @c long @c long value
272 * @param[in] value A @c signed @c long @c long value to convert
274 static String ToString(long long value);
277 * Decodes a string into a @c signed @c long @c long value.
281 * @return An error code
282 * @param[in] inputStr A string representing a numeric value
283 * @param[out] ret The result of the operation
284 * @exception E_SUCCESS The method is successful.
285 * @exception E_NUM_FORMAT The specified string does not contain a number that can be parsed.
286 * @exception E_OUT_OF_RANGE The decoded value is not between VALUE_MIN and VALUE_MAX range.
288 * - This method guarantees that the original value of out-parameter is not changed when the method returns error.
289 * - This method accepts decimal, hexadecimal, and octal numbers given by the
293 * Sign[opt] DecimalNumeral
294 * Sign[opt] 0x HexDigits
295 * Sign[opt] 0X HexDigits
296 * Sign[opt] # HexDigits
297 * Sign[opt] 0 OctalDigits
302 static result Decode(const String& inputStr, long long& ret);
305 * Parses the specified string representing a numeric value and
306 * returns the value as a @c signed @c long @c long (as out parameter).
310 * @return An error code
311 * @param[in] s A string representing a numeric value
312 * @param[out] ret The result of the operation
313 * @exception E_SUCCESS The method is successful.
314 * @exception E_NUM_FORMAT The specified string does not contain a number that can be parsed.
315 * @exception E_OUT_OF_RANGE The parsed value is not between VALUE_MIN and VALUE_MAX range.
318 * - This method assumes that the string representing the numeric value uses a radix 10.
319 * - This method guarantees that the original value of out-parameter is not changed when the method returns error.
321 static result Parse(const String& s, long long& ret);
324 * Parses the specified string representing a numeric value using the specified radix and
325 * returns the value as a @c signed @c long @c long (as out parameter).
329 * @return An error code
330 * @param[in] s A string representing a numeric value
331 * @param[in] radix The radix of the string representing a numeric value @n
332 * Radix value range is from 2 to 36.
333 * @param[out] ret The result of the operation
334 * @exception E_SUCCESS The method is successful.
335 * @exception E_NUM_FORMAT The specified string does not contain a number that can be parsed.
336 * @exception E_OUT_OF_RANGE The specified @c radix is invalid or
337 * The parsed value is not between VALUE_MIN and VALUE_MAX range.
339 * @remarks This method guarantees that the original value of out-parameter is not changed when the method returns error.
341 static result Parse(const String& s, int radix, long long& ret);
344 * A constant holding the maximum value a @c long @c long can have; 2^63-1.
348 static const long long VALUE_MAX = static_cast< long long >(0x7FFFFFFFFFFFFFFFLL);
351 * A constant holding the minimum value a @c long @c long can have; -2^63.
355 static const long long VALUE_MIN = static_cast< long long >(0x8000000000000000LL);
358 * A @c long @c long value of this instance.
366 friend class _LongLongImpl;
367 class _LongLongImpl* __pLongLongImpl;
373 #endif //_FBASE_LONG_LONG_H_