[2.2.1] Apply reviewed header file (Base to Collection)
[platform/framework/native/appfw.git] / inc / FBaseBoolean.h
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                FBaseBoolean.h
19  * @brief               This is the header file for the %Boolean class.
20  *
21  * This header file contains the declarations of the %Boolean class.
22  */
23 #ifndef _FBASE_BOOLEAN_H_
24 #define _FBASE_BOOLEAN_H_
25
26 #include <FBaseObject.h>
27 #include <FBaseString.h>
28
29
30 namespace Tizen { namespace Base
31 {
32 /**
33  *      @class  Boolean
34  *      @brief  This class is the wrapper class for the @c bool data type.
35  *
36  *      @since 2.0
37  *
38  * The %Boolean class wraps a boolean type value. This enables passing a boolean value to a method that only accepts an instance of the Object class.
39  * It provides methods to convert %Boolean instances to String and %String instances to %Boolean.
40  *
41  * The following example demonstrates how to use the %Boolean class.
42  *
43  *      @code
44  *
45  *      #include <FBase.h>
46  *
47  *      using namespace Tizen::Base;
48  *
49  *      void
50  *      MyClass::Test(void)
51  *      {
52  *              Boolean b1(true);
53  *
54  *              String string1(b1.ToString());          // string1 == L"true"
55  *
56  *
57  *              // Compares the string1 with L"true"
58  *              if (Boolean::Parse(string1))
59  *              {
60  *                      // ...
61  *              }
62  *
63  *      }
64  *      @endcode
65  */
66 class _OSP_EXPORT_ Boolean
67         : public Object
68 {
69 public:
70         /**
71          *      Initializes this instance of %Boolean with the specified @c value.
72          *
73          *      @since 2.0
74          *
75          *      @param[in]      value   The @c bool value used to initialize %Boolean
76          */
77         Boolean(bool value);
78
79         /**
80          *      Copying of objects using this copy constructor is allowed.
81          *
82          *      @since 2.0
83          *
84          *      @param[in]      value   An instance of %Boolean
85          */
86         Boolean(const Boolean& value);
87
88         /**
89          *      Initializes this instance of %Boolean with the specified input string. @n
90          *  If the input is "true" (ignoring cases), the object is initialized to @c true,
91          *      otherwise to @c false.
92          *
93          *      @since 2.0
94          *
95          *      @param[in]      value   An instance of String
96          */
97         Boolean(const String& value);
98
99         /**
100          *      This destructor overrides Tizen::Base::Object::~Object().
101          *
102          *      @since 2.0
103          */
104         virtual ~Boolean(void);
105
106         /**
107          *      Compares the values of two %Boolean instances.
108          *
109          *      @since 2.0
110          *
111          *      @return                         @c true if the values of the objects are equal, @n
112          *                                              else @c false
113          *      @param[in]      rhs             An instance of %Boolean to compare with the current instance
114          */
115         bool operator ==(const Boolean& rhs) const;
116
117         /**
118          *      Checks whether the two %Boolean instances are not equal.
119          *
120          *      @since 2.0
121          *
122          *      @return                         @c true if the values of the objects are not equal, @n
123          *                                              else @c false
124          *      @param[in]      rhs             An instance of %Boolean to compare with the current instance
125          */
126         bool operator !=(const Boolean& rhs) const;
127
128         /**
129          *      Copying of objects using this copy assignment operator is allowed.
130          *
131          *      @since 2.0
132          *
133          *  @param[in]  rhs     An instance of %Boolean
134          */
135         Boolean& operator =(const Boolean& rhs);
136
137         /**
138          *      Compares the specified Object instance with the current %Boolean instance.
139          *
140          *      @since 2.0
141          *
142          *      @return                         @c true if @c obj matches the current %Boolean instance, @n
143          *                                              else @c false
144          *      @param[in]      obj             A reference to the Object instance to compare with the current %Boolean instance
145          *      @see                            Tizen::Base::Object::Equals()
146          */
147         virtual bool Equals(const Object& obj) const;
148
149         /**
150          *      Gets the hash value of the current instance.
151          *
152          *      @since 2.0
153          *
154          *      @return                 The hash value of the current instance
155          *      @remarks                The two Tizen::Base::Object::Equals() instances must return the same hash value. @n
156          *                                      For better performance, the used hash function must generate a random distribution for all the inputs.
157          */
158         virtual int GetHashCode(void) const;
159
160         /**
161          *      Converts a @c bool value to an instance of %Boolean and then
162          *      compares it with the current %Boolean instance.
163          *
164          *      @since 2.0
165          *
166          *  @return                             @c true if @c value matches the current %Boolean instance, @n
167          *                                              else @c false
168          *  @param[in]  value   The @c bool value to compare to this instance
169          */
170         bool Equals(bool value) const;
171
172         /**
173          * Returns the value of the current object as @c bool.
174          *
175          * @since 2.0
176          *
177          * @return              The value of the %Boolean instance as @c bool
178          */
179         bool ToBool(void) const;
180
181         /**
182          *      Parses the specified string and converts it to a @c bool value.
183          *
184          *      @since 2.0
185          *
186          *      @return         @c true if the value of the specified string is "true", @n
187          *                              else @c false
188          *      @param[in]      s                       An instance of String
189          *      @remarks        This method is case sensitive and accepts only lowercase strings.
190          *
191          *      @code
192          *      bool b1 = Boolean::Parse(trueString); // trueString is L"true"
193          *      bool b1 = Boolean::Parse(falseString); // falseString is L"false"
194          *      @endcode
195          */
196         static bool Parse(const String& s);
197
198         /**
199          *      Parses the specified string and converts it to a @c bool value. @n
200          *      Case sensitivity can be controlled.
201          *
202          *      @since 2.0
203          *
204          *      @return         @c true if the value of the specified string is "true", @n
205          *                              else @c false
206          *      @param[in]      s                               An instance of String
207          *      @param[in]      caseSensitive   Set to @c true to perform a
208          *                                                              case sensitive comparison of string @c s
209          *      @remarks        If @c caseSensitive is @c true, L"True" returns @c false, else it returns @c true.
210          *
211          *  @code
212          *  bool b1 = Boolean::Parse(L"True", false ); // Returns @c true
213          *  bool b1 = Boolean::Parse(L"True", true); // Returns @c false
214          *  @endcode
215          */
216         static bool Parse(const String& s, bool caseSensitive);
217
218         /**
219          *      Converts the value of the current instance from @c bool to String.
220          *
221          *      @since 2.0
222          *
223          *      @return         @c true if this instance is @c true, @n
224          *                              else @c false
225          */
226         String ToString(void) const;
227
228         /**
229          *      Converts a @c bool parameter to a String
230          *      instance of the %String class and returns the string representation of the
231          *      input @c bool value (@c true or @c false).
232          *
233          *      @since 2.0
234          *
235          *      @return         @c true if the parameter is @c true, @n
236          *                              else @c false
237          *      @param[in]      value   The @c bool value to convert to String
238          */
239         static String ToString(bool value);
240
241         /**
242          *      Returns a %Boolean instance whose value corresponds to the
243          *      primitive value @c true.
244          *
245          *      @since 2.0
246          *
247          *      @return         A %Boolean instance equivalent to @c true
248          */
249         static const Boolean GetTrue(void);
250
251         /**
252          *      Returns a %Boolean instance whose value corresponds to the primitive
253          *      value @c false.
254          *
255          *      @since 2.0
256          *
257          *      @return         A %Boolean instance equivalent to @c false
258          */
259         static const Boolean GetFalse(void);
260
261         /**
262          * A boolean value of this instance.
263          *
264          * @since 2.0
265          */
266         bool value;
267
268 private:
269         friend class _BooleanImpl;
270         class _BooleanImpl* __pBooleanImpl;
271
272 }; // Boolean
273
274 }} // Tizen::Base
275
276 #endif //_FBASE_BOOLEAN_H_