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.");
120 if (value > Integer::VALUE_MAX)
122 ret = Integer::VALUE_MAX;
124 else if (value < Integer::VALUE_MIN)
126 ret = Integer::VALUE_MIN;
130 ret = static_cast< int >(value);
136 Integer::ToChar(void) const
138 return static_cast< char >(value);
142 Integer::ToShort(void) const
144 return static_cast< short >(value);
148 Integer::ToInt(void) const
154 Integer::ToLong(void) const
156 return static_cast< long >(value);
160 Integer::ToLongLong(void) const
162 return static_cast< long long >(value);
166 Integer::ToFloat(void) const
168 return static_cast< float >(value);
172 Integer::ToDouble(void) const
174 return static_cast< double >(value);
178 Integer::ToString(void) const
180 return(Integer::ToString(value));
184 Integer::ToString(int value)
186 const static unsigned int INTEGER_LENGTH_MAX = 11;
188 wchar_t sValue[INTEGER_LENGTH_MAX + 1] = {0, };
189 swprintf(sValue, (sizeof(sValue) / sizeof(sValue[0])), L"%d", value);
191 return String(sValue);