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.cpp
19 * @brief This is the implementation file for Integer class.
25 #include <FBaseInteger.h>
26 #include <FBaseResult.h>
27 #include <FBaseCharacter.h>
28 #include <FBaseSysLog.h>
29 #include "FBase_NumberUtil.h"
31 namespace Tizen { namespace Base
34 Integer::Integer(int value)
36 , __pIntegerImpl(null)
40 Integer::Integer(const Integer& value)
42 , __pIntegerImpl(null)
46 Integer::~Integer(void)
52 Integer::operator =(const Integer& rhs)
62 Integer::Compare(int i1, int i2)
64 return(i1 < i2 ? -1 : (i1 == i2 ? 0 : 1));
68 Integer::CompareTo(const Integer& value) const
70 return(Integer::Compare(this->value, value.value));
74 Integer::Equals(const Object& obj) const
76 const Integer* pOther = dynamic_cast< const Integer* >(&obj);
82 return value == (*pOther).value;
86 Integer::Decode(const String& s, int& ret)
89 result r = _NumberUtil::Decode(s, value);
90 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
91 ret = static_cast< int >(value);
96 Integer::GetHashCode(void) const
102 Integer::GetHashCode(int val)
108 Integer::Parse(const String& s, int& ret)
110 return Parse(s, Character::RADIX_DECIMAL, ret);
114 Integer::Parse(const String& s, int radix, int& ret)
117 result r = _NumberUtil::Parse(s, radix, value);
118 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
119 ret = static_cast< int >(value);
124 Integer::ToChar(void) const
126 return static_cast< char >(value);
130 Integer::ToInt8(void) const
132 return static_cast< int8_t >(value);
136 Integer::ToShort(void) const
138 return static_cast< short >(value);
142 Integer::ToInt(void) const
148 Integer::ToLong(void) const
150 return static_cast< long >(value);
154 Integer::ToLongLong(void) const
156 return static_cast< long long >(value);
160 Integer::ToFloat(void) const
162 return static_cast< float >(value);
166 Integer::ToDouble(void) const
168 return static_cast< double >(value);
172 Integer::ToString(void) const
174 return(Integer::ToString(value));
178 Integer::ToString(int value)
180 const static unsigned int INTEGER_LENGTH_MAX = 11;
182 wchar_t sValue[INTEGER_LENGTH_MAX + 1] = {0, };
183 swprintf(sValue, (sizeof(sValue) / sizeof(sValue[0])), L"%d", value);
185 return String(sValue);