2 // Copyright (c) 2013 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 FBaseInteger8.cpp
19 * @brief This is the implementation file for Integer8 class.
25 #include <FBaseInteger8.h>
26 #include <FBaseResult.h>
27 #include <FBaseCharacter.h>
28 #include <FBaseSysLog.h>
29 #include "FBase_NumberUtil.h"
30 #include "FApp_AppInfo.h"
32 namespace Tizen { namespace Base
35 Integer8::Integer8(void)
37 , __pInteger8Impl(null)
41 Integer8::Integer8(int8_t val)
43 , __pInteger8Impl(null)
47 Integer8::Integer8(const Integer8& rhs)
49 , __pInteger8Impl(null)
53 Integer8::~Integer8(void)
58 Integer8::operator =(const Integer8& rhs)
68 Integer8::Compare(int8_t i81, int8_t i82)
74 Integer8::CompareTo(const Integer8& rhs) const
76 return Integer8::Compare(this->value, rhs.value);
80 Integer8::Equals(const Object& obj) const
82 const Integer8* pOther = dynamic_cast< const Integer8* >(&obj);
88 return value == pOther->value;
92 Integer8::GetHashCode(void) const
94 return static_cast< int >(value);
98 Integer8::GetHashCode(int8_t val)
100 return static_cast< int >(val);
104 Integer8::Decode(const String& inputStr, int8_t& ret)
107 result r = _NumberUtil::Decode(inputStr, value);
108 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
109 SysTryReturnResult(NID_BASE, (value >= Integer8::VALUE_MIN) && (value <= Integer8::VALUE_MAX), E_OUT_OF_RANGE, "The value(%d) is out of range.", value);
110 ret = static_cast< int8_t >(value);
115 Integer8::Parse(const String& inputStr, int8_t& ret)
117 return Parse(inputStr, Character::RADIX_DECIMAL, ret);
121 Integer8::Parse(const String& inputStr, int radix, int8_t& ret)
124 result r = _NumberUtil::Parse(inputStr, radix, value);
125 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
126 SysTryReturnResult(NID_BASE, (value >= Integer8::VALUE_MIN) && (value <= Integer8::VALUE_MAX), E_OUT_OF_RANGE, "The value(%d) is out of range.", value);
127 ret = static_cast< int8_t >(value);
132 Integer8::ToChar(void) const
134 return static_cast< signed char >(value);
138 Integer8::ToShort(void) const
140 return static_cast< short >(value);
144 Integer8::ToInt(void) const
146 return static_cast< int >(value);
150 Integer8::ToLong(void) const
152 return static_cast< long >(value);
156 Integer8::ToLongLong(void) const
158 return static_cast< long long >(value);
162 Integer8::ToFloat(void) const
164 return static_cast< float >(value);
168 Integer8::ToDouble(void) const
170 return static_cast< double >(value);
174 Integer8::ToString(void) const
176 return (Integer8::ToString(value));
180 Integer8::ToString(int8_t value)
182 const static unsigned int INTEGER8_LENGTH_MAX = 4;
184 wchar_t sValue[INTEGER8_LENGTH_MAX + 1] = {0, };
185 swprintf(sValue, INTEGER8_LENGTH_MAX + 1, L"%d", value);
187 return String(sValue);