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