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 FBaseShort.cpp
19 * @brief This is the implementation file for Short class.
25 #include <FBaseShort.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 Short::Short(short value)
41 Short::Short(const Short& value)
52 Short::operator =(const Short& rhs)
62 Short::Compare(short s1, short s2)
64 return(s1 < s2 ? -1 : (s1 == s2 ? 0 : 1));
68 Short::CompareTo(const Short& value) const
70 return(Short::Compare(this->value, value.value));
74 Short::Equals(const Object& obj) const
76 const Short* pOther = dynamic_cast< const Short* >(&obj);
82 return value == (*pOther).value;
86 Short::Equals(short value) const
88 return this->value == value;
92 Short::GetHashCode(void) const
94 return static_cast< int >(value);
98 Short::GetHashCode(short val)
100 return static_cast< int >(val);
104 Short::Decode(const String& s, short& ret)
107 result r = _NumberUtil::Decode(s, value);
108 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
109 SysTryReturnResult(NID_BASE, (value >= Short::VALUE_MIN) && (value <= Short::VALUE_MAX), E_OUT_OF_RANGE, "The value(%d) is out of range.", value);
110 ret = static_cast< short >(value);
115 Short::Parse(const String& s, short& ret)
117 return Parse(s, Character::RADIX_DECIMAL, ret);
121 Short::Parse(const String& s, int radix, short& ret)
124 result r = _NumberUtil::Parse(s, radix, value);
125 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
126 SysTryReturnResult(NID_BASE, (value >= Short::VALUE_MIN) && (value <= Short::VALUE_MAX), E_OUT_OF_RANGE, "The value(%d) is out of range.", value);
127 ret = static_cast< short >(value);
132 Short::ToChar(void) const
134 return static_cast< char >(value);
138 Short::ToInt8(void) const
140 return static_cast< int8_t >(value);
144 Short::ToShort(void) const
150 Short::ToInt(void) const
152 return static_cast< int >(value);
156 Short::ToLong(void) const
158 return static_cast< long >(value);
162 Short::ToLongLong(void) const
164 return static_cast< long long >(value);
168 Short::ToFloat(void) const
170 return static_cast< float >(value);
174 Short::ToDouble(void) const
176 return static_cast< double >(value);
180 Short::ToString(void) const
182 return(Short::ToString(value));
186 Short::ToString(short value)
188 const static unsigned int SHORT_LENGTH_MAX = 6;
190 wchar_t sValue[SHORT_LENGTH_MAX + 1] = {0, };
191 swprintf(sValue, (sizeof(sValue) / sizeof(sValue[0])), L"%d", value);
193 return String(sValue);