Merge "Update deprecated libprivilege-control API functions." into tizen
[platform/framework/native/appfw.git] / src / base / FBaseLong.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 /**
18  * @file                FBaseLong.cpp
19  * @brief               This is the implementation file for Long class.
20  * @see                 Number
21  */
22 #include <wchar.h>
23 #include <limits.h>
24 #include <errno.h>
25 #include <FBaseLong.h>
26 #include <FBaseResult.h>
27 #include <FBaseCharacter.h>
28 #include <FBaseSysLog.h>
29 #include "FBase_NumberUtil.h"
30
31 namespace Tizen { namespace Base
32 {
33
34 Long::Long(long value)
35         : value(value)
36         , __pLongImpl(null)
37 {
38 }
39
40 Long::Long(const Long& value)
41         : value(value.value)
42         , __pLongImpl(null)
43 {
44 }
45
46 Long::~Long(void)
47 {
48 }
49
50 Long&
51 Long::operator =(const Long& rhs)
52 {
53         if (&rhs != this)
54         {
55                 value = rhs.value;
56         }
57         return *this;
58 }
59
60 int
61 Long::Compare(long l1, long l2)
62 {
63         return(l1 < l2 ? -1 : (l1 == l2 ? 0 : 1));
64 }
65
66 int
67 Long::CompareTo(const Long& value) const
68 {
69         return(Long::Compare(this->value, value.value));
70 }
71
72 bool
73 Long::Equals(const Object& obj) const
74 {
75         const Long* pOther = dynamic_cast< const Long* >(&obj);
76         if (pOther == null)
77         {
78                 return false;
79         }
80
81         return value == (*pOther).value;
82 }
83
84 int
85 Long::GetHashCode(void) const
86 {
87         return static_cast< int >(value);
88 }
89
90 int
91 Long::GetHashCode(long val)
92 {
93         return static_cast< int >(val);
94 }
95
96 result
97 Long::Decode(const String& s, long& ret)
98 {
99         long value;
100         result r = _NumberUtil::Decode(s, value);
101         SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
102         ret = value;
103         return r;
104 }
105
106 result
107 Long::Parse(const String& s, long& ret)
108 {
109         return Parse(s, Character::RADIX_DECIMAL, ret);
110 }
111
112 result
113 Long::Parse(const String& s, int radix, long& ret)
114 {
115         long value;
116         result r = _NumberUtil::Parse(s, radix, value);
117         SysTryReturnResult(NID_BASE, r == E_SUCCESS, r, "Propagating.");
118         ret = value;
119         return r;
120 }
121
122 char
123 Long::ToChar(void) const
124 {
125         return static_cast< char >(value);
126 }
127
128 int8_t
129 Long::ToInt8(void) const
130 {
131         return static_cast< int8_t >(value);
132 }
133
134 short
135 Long::ToShort(void) const
136 {
137         return static_cast< short >(value);
138 }
139
140 int
141 Long::ToInt(void) const
142 {
143         return static_cast< int >(value);
144 }
145
146 long
147 Long::ToLong(void) const
148 {
149         return value;
150 }
151
152 long long
153 Long::ToLongLong(void) const
154 {
155         return static_cast< long long >(value);
156 }
157
158 float
159 Long::ToFloat(void) const
160 {
161         return static_cast< float >(value);
162 }
163
164 double
165 Long::ToDouble(void) const
166 {
167         return static_cast< double >(value);
168 }
169
170 String
171 Long::ToString(void) const
172 {
173         return(Long::ToString(value));
174 }
175
176 String
177 Long::ToString(long value)
178 {
179         const static unsigned int LONG_LENGTH_MAX = 11;
180
181         wchar_t sValue[LONG_LENGTH_MAX + 1] = {0, };
182         swprintf(sValue, (sizeof(sValue) / sizeof(sValue[0])), L"%d", value);
183
184         return String(sValue);
185 }
186
187 }} //Tizen::Base