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 implementation file for Int8 class.
25 #include <FBaseInt8.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 Int8::Int8(char value)
36 : value(static_cast< signed char >(value))
41 Int8::Int8(const Int8& value)
52 Int8::operator =(const Int8& rhs)
62 Int8::Compare(char ch1, char ch2)
64 return ((signed char) ch1 < (signed char) ch2 ? -1 : (ch1 == ch2 ? 0 : 1));
68 Int8::CompareTo(const Int8& value) const
70 return (Int8::Compare(this->value, value.value));
74 Int8::Equals(const Object& obj) const
76 const Int8* pOther = dynamic_cast< const Int8* >(&obj);
82 return (value == (*pOther).value);
86 Int8::GetHashCode(void) const
88 return static_cast< int >(value);
92 Int8::GetHashCode(char val)
94 return static_cast< int >(val);
98 Int8::Decode(const String& s, char& ret)
101 result r = _NumberUtil::Decode(s, value);
102 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
103 SysTryReturnResult(NID_BASE, (value >= Int8::VALUE_MIN) && (value <= Int8::VALUE_MAX), E_OUT_OF_RANGE, "The value(%d) is out of range.", value);
104 ret = static_cast< char >(value);
109 Int8::Parse(const String& s, char& ret)
111 return Parse(s, Character::RADIX_DECIMAL, ret);
115 Int8::Parse(const String& s, int radix, char& ret)
118 result r = _NumberUtil::Parse(s, radix, value);
119 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
120 SysTryReturnResult(NID_BASE, (value >= Int8::VALUE_MIN) && (value <= Int8::VALUE_MAX), E_OUT_OF_RANGE, "The value(%d) is out of range.", value);
121 ret = static_cast< char >(value);
126 Int8::ToChar(void) const
128 return static_cast< char >(value);
132 Int8::ToShort(void) const
134 return static_cast< short >(value);
138 Int8::ToInt(void) const
140 return static_cast< int >(value);
144 Int8::ToLong(void) const
146 return static_cast< long >(value);
150 Int8::ToLongLong(void) const
152 return static_cast< long long >(value);
156 Int8::ToFloat(void) const
158 return static_cast< float >(value);
162 Int8::ToDouble(void) const
164 return static_cast< double >(value);
168 Int8::ToString(void) const
170 return (Int8::ToString(value));
174 Int8::ToString(char value)
176 const static unsigned int INT8_LENGTH_MAX = 4;
178 wchar_t sValue[INT8_LENGTH_MAX + 1] = {0, };
179 swprintf(sValue, (sizeof(sValue) / sizeof(sValue[0])), L"%d", value);
181 return String(sValue);