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