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 FBaseLongLong.cpp
19 * @brief This is the implementation file for LongLong class.
25 #include <FBaseLongLong.h>
26 #include <FBaseResult.h>
27 #include <FBaseCharacter.h>
28 #include <FBaseSysLog.h>
29 #include "FBase_NumberUtil.h"
31 namespace Tizen { namespace Base
34 LongLong::LongLong(long long value)
36 , __pLongLongImpl(null)
40 LongLong::LongLong(const LongLong& value)
42 , __pLongLongImpl(null)
46 LongLong::~LongLong(void)
51 LongLong::operator =(const LongLong& rhs)
61 LongLong::Compare(long long l1, long long l2)
63 return (int) (l1 < l2 ? -1 : (l1 == l2 ? 0 : 1));
67 LongLong::CompareTo(const LongLong& value) const
69 return(LongLong::Compare(this->value, value.value));
73 LongLong::Equals(const Object& obj) const
75 const LongLong* pOther = dynamic_cast< const LongLong* >(&obj);
81 return value == (*pOther).value;
85 LongLong::GetHashCode(void) const
87 return static_cast< int >(value);
91 LongLong::GetHashCode(long long val)
93 return static_cast< int >(val);
97 LongLong::ToChar(void) const
99 return static_cast< char >(value);
103 LongLong::ToInt8(void) const
105 return static_cast< int8_t >(value);
109 LongLong::ToShort(void) const
111 return static_cast< short >(value);
115 LongLong::ToInt(void) const
117 return static_cast< int >(value);
121 LongLong::ToLong(void) const
123 return static_cast< long >(value);
127 LongLong::ToFloat(void) const
129 return static_cast< float >(value);
133 LongLong::ToDouble(void) const
135 return static_cast< double >(value);
139 LongLong::ToLongLong(void) const
145 LongLong::ToString(void) const
147 return(LongLong::ToString(value));
151 LongLong::ToString(long long value)
153 const static unsigned int LONG_LONG_LENGTH_MAX = 20;
155 wchar_t sValue[LONG_LONG_LENGTH_MAX + 1];
157 wmemset(sValue, 0, sizeof(sValue) / sizeof(sValue[0]));
158 swprintf(sValue, (sizeof(sValue) / sizeof(sValue[0])), L"%lld", value);
160 return String(sValue);
164 LongLong::Parse(const String& s, long long& ret)
166 return Parse(s, Character::RADIX_DECIMAL, ret);
170 LongLong::Parse(const String& s, int radix, long long& ret)
173 result r = _NumberUtil::Parse(s, radix, value);
174 SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");