a4a47be7a9c9e8cc2cf7ada34b8e3d017abdcf0c
[platform/framework/native/appfw.git] / src / base / FBaseBoolean.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                FBaseBool.cpp
19  * @brief               This is the implementation file for Boolean class.
20  */
21
22 #include <FBaseBoolean.h>
23 #include <FBaseResult.h>
24
25
26 namespace Tizen { namespace Base
27 {
28
29 Boolean::Boolean(bool value)
30         : value(value)
31         , __pBooleanImpl(null)
32 {
33 }
34
35 Boolean::Boolean(const Boolean& value)
36         : value(value.value)
37         , __pBooleanImpl(null)
38 {
39 }
40
41 Boolean::Boolean(const String& value)
42 {
43         const String trueString = L"true";
44         String lowString;
45
46         value.ToLower(lowString);
47
48         if (lowString.Equals(trueString))
49         {
50                 this->value = true;
51         }
52         else
53         {
54                 this->value = false;
55         }
56
57         __pBooleanImpl = null;
58 }
59
60 Boolean::~Boolean(void)
61 {
62 }
63
64 bool
65 Boolean::operator ==(const Boolean& rhs) const
66 {
67         return(value == rhs.value);
68 }
69
70 bool
71 Boolean::operator !=(const Boolean& rhs) const
72 {
73         return(value != rhs.value);
74 }
75
76 Boolean&
77 Boolean::operator =(const Boolean& rhs)
78 {
79         if (&rhs != this)
80         {
81                 value = rhs.value;
82         }
83
84         return(*this);
85 }
86
87 bool
88 Boolean::Equals(const Object& obj) const
89 {
90         const Boolean* pOther = dynamic_cast <const Boolean*>(&obj);
91         if (pOther == null)
92         {
93                 return false;
94         }
95
96         return *this == *pOther;
97 }
98
99 int
100 Boolean::GetHashCode(void) const
101 {
102         return static_cast<int> (value);
103 }
104
105 bool
106 Boolean::Equals(bool value) const
107 {
108         return this->value == value;
109 }
110
111 bool
112 Boolean::ToBool(void) const
113 {
114         return value;
115 }
116
117 bool
118 Boolean::Parse(const String& s)
119 {
120         const String trueString = L"true";
121         if (s.Equals(trueString))
122         {
123                 return true;
124         }
125
126         return false;
127 }
128
129 bool
130 Boolean::Parse(const String& s, bool caseSensitive)
131 {
132         const String trueString = L"true";
133
134         if (caseSensitive)
135         {
136                 if (s.Equals(trueString))
137                 {
138                         return true;
139                 }
140         }
141         else
142         {
143                 int len = s.GetLength();
144                 int trueLen = trueString.GetLength();
145
146                 result r = E_SUCCESS;
147
148                 if (len != trueLen)
149                 {
150                         return false;
151                 }
152
153                 String lowString;
154
155                 r = s.ToLower(lowString);
156                 if (!lowString.Equals(trueString))
157                 {
158                         return false;
159                 }
160
161                 return true;
162         }
163
164         return false;
165 }
166
167 String
168 Boolean::ToString(void) const
169 {
170         return(Boolean::ToString(value));
171 }
172
173 String
174 Boolean::ToString(bool value)
175 {
176         String str;
177
178         if (value == true)
179         {
180                 str = L"true";
181         }
182         else
183         {
184                 str = L"false";
185         }
186
187         return str;
188 }
189
190 const Boolean
191 Boolean::GetTrue(void)
192 {
193         static const Boolean True(true);
194         return True;
195 }
196
197 const Boolean
198 Boolean::GetFalse(void)
199 {
200         static const Boolean False(false);
201         return False;
202 }
203
204 }} // Tizen::Base