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"
31 namespace Tizen { namespace Base
34 Int8::Int8(char value)
35 : value(static_cast< signed char >(value))
40 Int8::Int8(const Int8& value)
51 Int8::operator =(const Int8& rhs)
61 Int8::Compare(char ch1, char ch2)
63 return ((signed char) ch1 < (signed char) ch2 ? -1 : (ch1 == ch2 ? 0 : 1));
67 Int8::CompareTo(const Int8& value) const
69 return (Int8::Compare(this->value, value.value));
73 Int8::Equals(const Object& obj) const
75 const Int8* pOther = dynamic_cast< const Int8* >(&obj);
81 return (value == (*pOther).value);
85 Int8::GetHashCode(void) const
87 return static_cast< int >(value);
91 Int8::GetHashCode(char val)
93 return static_cast< int >(val);
97 Int8::Decode(const String& s, char& ret)
100 result r = _NumberUtil::Decode(s, value);
101 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
103 if (value > Int8::VALUE_MAX)
105 ret = Int8::VALUE_MAX;
107 else if (value < Int8::VALUE_MIN)
109 ret = Int8::VALUE_MIN;
113 ret = static_cast< char >(value);
119 Int8::Parse(const String& s, char& ret)
121 return Parse(s, Character::RADIX_DECIMAL, ret);
125 Int8::Parse(const String& s, int radix, char& ret)
128 result r = _NumberUtil::Parse(s, radix, value);
129 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
131 if (value > Int8::VALUE_MAX)
133 ret = Int8::VALUE_MAX;
135 else if (value < Int8::VALUE_MIN)
137 ret = Int8::VALUE_MIN;
141 ret = static_cast< char >(value);
147 Int8::ToChar(void) const
149 return static_cast< char >(value);
153 Int8::ToShort(void) const
155 return static_cast< short >(value);
159 Int8::ToInt(void) const
161 return static_cast< int >(value);
165 Int8::ToLong(void) const
167 return static_cast< long >(value);
171 Int8::ToLongLong(void) const
173 return static_cast< long long >(value);
177 Int8::ToFloat(void) const
179 return static_cast< float >(value);
183 Int8::ToDouble(void) const
185 return static_cast< double >(value);
189 Int8::ToString(void) const
191 return (Int8::ToString(value));
195 Int8::ToString(char value)
197 const static unsigned int INT8_LENGTH_MAX = 4;
199 wchar_t sValue[INT8_LENGTH_MAX + 1] = {0, };
200 swprintf(sValue, (sizeof(sValue) / sizeof(sValue[0])), L"%d", value);
202 return String(sValue);