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 Long class.
25 #include <FBaseLong.h>
26 #include <FBaseResult.h>
27 #include <FBaseCharacter.h>
28 #include <FBaseSysLog.h>
29 #include "FBase_NumberUtil.h"
31 namespace Tizen { namespace Base
34 Long::Long(long value)
40 Long::Long(const Long& value)
51 Long::operator =(const Long& rhs)
61 Long::Compare(long l1, long l2)
63 return(l1 < l2 ? -1 : (l1 == l2 ? 0 : 1));
67 Long::CompareTo(const Long& value) const
69 return(Long::Compare(this->value, value.value));
73 Long::Equals(const Object& obj) const
75 const Long* pOther = dynamic_cast< const Long* >(&obj);
81 return value == (*pOther).value;
85 Long::GetHashCode(void) const
87 return static_cast< int >(value);
91 Long::GetHashCode(long val)
93 return static_cast< int >(val);
97 Long::Decode(const String& s, long& ret)
100 result r = _NumberUtil::Decode(s, value);
101 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
107 Long::Parse(const String& s, long& ret)
109 return Parse(s, Character::RADIX_DECIMAL, ret);
113 Long::Parse(const String& s, int radix, long& ret)
116 result r = _NumberUtil::Parse(s, radix, value);
117 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
123 Long::ToChar(void) const
125 return static_cast< char >(value);
129 Long::ToInt8(void) const
131 return static_cast< int8_t >(value);
135 Long::ToShort(void) const
137 return static_cast< short >(value);
141 Long::ToInt(void) const
143 return static_cast< int >(value);
147 Long::ToLong(void) const
153 Long::ToLongLong(void) const
155 return static_cast< long long >(value);
159 Long::ToFloat(void) const
161 return static_cast< float >(value);
165 Long::ToDouble(void) const
167 return static_cast< double >(value);
171 Long::ToString(void) const
173 return(Long::ToString(value));
177 Long::ToString(long value)
179 const static unsigned int LONG_LENGTH_MAX = 11;
181 wchar_t sValue[LONG_LENGTH_MAX + 1] = {0, };
182 swprintf(sValue, (sizeof(sValue) / sizeof(sValue[0])), L"%d", value);
184 return String(sValue);