Merge "Update deprecated libprivilege-control API functions." into tizen
[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 bool type value. This enables passing a bool 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 the %Boolean class with the specified @c value.
72          *
73          *      @since 2.0
74          *
75          *      @param[in]      value   The input @c bool value to initialize the %Boolean instance
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 the %Boolean class
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 case), the object is initialized to @c true,
91          *      else @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          *      Converts an instance of the Object class to an instance of %Boolean and then
139          *      compares it with the calling %Boolean instance.
140          *
141          *      @since 2.0
142          *
143          *      @return                 @c true if the value of @c obj matches the value of the calling %Boolean instance, @n
144          *                                              else @c false
145          *      @param[in]      obj             A reference to the Object instance to compare with the calling %Boolean instance
146          *      @see                            Tizen::Base::Object::Equals()
147          */
148         virtual bool Equals(const Object& obj) const;
149
150         /**
151          *      Gets the hash value of the current instance.
152          *
153          *      @since 2.0
154          *
155          *      @return         The hash value of the current instance
156          *      @remarks                The two Tizen::Base::Object::Equals() instances must return the same hash value. For better performance, @n
157          *                                      the used hash function must generate a random distribution for all inputs.
158          */
159         virtual int GetHashCode(void) const;
160
161         /**
162          *      Converts a bool value to an instance of %Boolean and then
163          *      compares it with the calling %Boolean instance.
164          *
165          *      @since 2.0
166          *
167          *  @return                     @c true if the parameter matches the calling %Boolean instance, @n
168          *                                              else @c false
169          *  @param[in]  value   The @c bool value to compare to this instance
170          */
171         bool Equals(bool value) const;
172
173         /**
174          * Returns the value of the calling object as @c bool.
175          *
176          * @since 2.0
177          *
178          * @return              The value of the %Boolean instance as bool
179          */
180         bool ToBool(void) const;
181
182         /**
183          *      Parses the specified string and converts it to a @c bool value.
184          *
185          *      @since 2.0
186          *
187          *      @return         @c true if the value of the specified string is "true", @n
188          *                                      else @c false
189          *      @param[in]      s                       An instance of String
190          *      @remarks        This method is case sensitive. @n
191          *                              It only accepts lowercase strings.
192          *
193          *      @code
194          *      bool b1 = Boolean::Parse(trueString); // trueString is L"true"
195          *      bool b1 = Boolean::Parse(falseString); // falseString is L"false"
196          *      @endcode
197          */
198         static bool Parse(const String& s);
199
200         /**
201          *      Parses the specified string and converts it to a @c bool value. @n
202          *      Case sensitivity can be controlled.
203          *
204          *      @since 2.0
205          *
206          *      @return         @c true if the value of the specified string is "true", @n
207          *                                      else @c false
208          *      @param[in]      s                               An instance of String
209          *      @param[in]      caseSensitive   Set to @c true to perform a
210          *                                                              case sensitive comparison of string @c s
211          *      @remarks        If @c caseSensitive is @c true, L"True" returns @c false, else @c true.
212          *
213          *  @code
214          *  bool b1 = Boolean::Parse(L"True", false ); // Returns @c true
215          *  bool b1 = Boolean::Parse(L"True", true); // Returns @c false
216          *  @endcode
217          */
218         static bool Parse(const String& s, bool caseSensitive);
219
220         /**
221          *      Converts the value of the calling instance from @c bool to String.
222          *
223          *      @since 2.0
224          *
225          *      @return @c true if this instance is @c true, @n
226          *                              else @c false
227          */
228         String ToString(void) const;
229
230         /**
231          *      Converts a @c bool parameter to a String
232          *      instance of the %String class and returns the string representation of the
233          *      input @c bool value (@c true or @c false).
234          *
235          *      @since 2.0
236          *
237          *      @return @c true if the parameter is @c true, @n
238          *                              else @c false
239          *      @param[in]      value   A @c bool value to convert to String
240          */
241         static String ToString(bool value);
242
243         /**
244          *      Returns a %Boolean instance whose value corresponds to the
245          *      primitive value @c true.
246          *
247          *      @since 2.0
248          *
249          *      @return         A %Boolean instance equivalent to @c true
250          */
251         static const Boolean GetTrue(void);
252
253         /**
254          *      Returns a %Boolean instance whose value corresponds to the primitive
255          *      value @c false.
256          *
257          *      @since 2.0
258          *
259          *      @return         A %Boolean instance equivalent to @c false
260          */
261         static const Boolean GetFalse(void);
262
263         /**
264          * A boolean value of this instance.
265          *
266          * @since 2.0
267          */
268         bool value;
269
270 private:
271         friend class _BooleanImpl;
272         class _BooleanImpl* __pBooleanImpl;
273
274 }; // Boolean
275
276 }} // Tizen::Base
277
278 #endif //_FBASE_BOOLEAN_H_