2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FBaseBoolean.h
20 * @brief This is the header file for the %Boolean class.
22 * This header file contains the declarations of the %Boolean class.
24 #ifndef _FBASE_BOOLEAN_H_
25 #define _FBASE_BOOLEAN_H_
27 #include <FBaseObject.h>
28 #include <FBaseString.h>
31 namespace Tizen { namespace Base
35 * @brief This class is the wrapper class for the @c bool data type.
39 * 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.
40 * It provides methods to convert %Boolean instances to String and %String instances to %Boolean.
42 * The following example demonstrates how to use the %Boolean class.
48 * using namespace Tizen::Base;
55 * String string1(b1.ToString()); // string1 == L"true"
58 * // Compares the string1 with L"true"
59 * if (Boolean::Parse(string1))
67 class _OSP_EXPORT_ Boolean
72 * Initializes this instance of the %Boolean class with the specified @c value.
76 * @param[in] value The input @c bool value to initialize the %Boolean instance
81 * Copying of objects using this copy constructor is allowed.
85 * @param[in] value An instance of the %Boolean class
87 Boolean(const Boolean& value);
90 * Initializes this instance of %Boolean with the specified input string. @n
91 * If the input is "true" (ignoring case), the object is initialized to @c true,
96 * @param[in] value An instance of String
98 Boolean(const String& value);
101 * This destructor overrides Tizen::Base::Object::~Object().
105 virtual ~Boolean(void);
108 * Compares the values of two %Boolean instances.
112 * @return @c true if the values of the objects are equal, @n
114 * @param[in] rhs An instance of %Boolean to compare with the current instance
116 bool operator ==(const Boolean& rhs) const;
119 * Checks whether the two %Boolean instances are not equal.
123 * @return @c true if the values of the objects are not equal, @n
125 * @param[in] rhs An instance of %Boolean to compare with the current instance
127 bool operator !=(const Boolean& rhs) const;
130 * Copying of objects using this copy assignment operator is allowed.
134 * @param[in] rhs An instance of %Boolean
136 Boolean& operator =(const Boolean& rhs);
139 * Converts an instance of the Object class to an instance of %Boolean and then
140 * compares it with the calling %Boolean instance.
144 * @return @c true if the value of @c obj matches the value of the calling %Boolean instance, @n
146 * @param[in] obj A reference to the Object instance to compare with the calling %Boolean instance
147 * @see Tizen::Base::Object::Equals()
149 virtual bool Equals(const Object& obj) const;
152 * Gets the hash value of the current instance.
156 * @return The hash value of the current instance
157 * @remarks The two Tizen::Base::Object::Equals() instances must return the same hash value. For better performance, @n
158 * the used hash function must generate a random distribution for all inputs.
160 virtual int GetHashCode(void) const;
163 * Converts a bool value to an instance of %Boolean and then
164 * compares it with the calling %Boolean instance.
168 * @return @c true if the parameter matches the calling %Boolean instance, @n
170 * @param[in] value The @c bool value to compare to this instance
172 bool Equals(bool value) const;
175 * Returns the value of the calling object as @c bool.
179 * @return The value of the %Boolean instance as bool
181 bool ToBool(void) const;
184 * Parses the specified string and converts it to a @c bool value.
188 * @return @c true if the value of the specified string is "true", @n
190 * @param[in] s An instance of String
191 * @remarks This method is case sensitive. @n
192 * It only accepts lowercase strings.
195 * bool b1 = Boolean::Parse(trueString); // trueString is L"true"
196 * bool b1 = Boolean::Parse(falseString); // falseString is L"false"
199 static bool Parse(const String& s);
202 * Parses the specified string and converts it to a @c bool value. @n
203 * Case sensitivity can be controlled.
207 * @return @c true if the value of the specified string is "true", @n
209 * @param[in] s An instance of String
210 * @param[in] caseSensitive Set to @c true to perform a
211 * case sensitive comparison of string @c s
212 * @remarks If @c caseSensitive is @c true, L"True" returns @c false, else @c true.
215 * bool b1 = Boolean::Parse(L"True", false ); // Returns @c true
216 * bool b1 = Boolean::Parse(L"True", true); // Returns @c false
219 static bool Parse(const String& s, bool caseSensitive);
222 * Converts the value of the calling instance from @c bool to String.
226 * @return @c true if this instance is @c true, @n
229 String ToString(void) const;
232 * Converts a @c bool parameter to a String
233 * instance of the %String class and returns the string representation of the
234 * input @c bool value (@c true or @c false).
238 * @return @c true if the parameter is @c true, @n
240 * @param[in] value A @c bool value to convert to String
242 static String ToString(bool value);
245 * Returns a %Boolean instance whose value corresponds to the
246 * primitive value @c true.
250 * @return A %Boolean instance equivalent to @c true
252 static const Boolean GetTrue(void);
255 * Returns a %Boolean instance whose value corresponds to the primitive
260 * @return A %Boolean instance equivalent to @c false
262 static const Boolean GetFalse(void);
265 * A boolean value of this instance.
272 friend class _BooleanImpl;
273 class _BooleanImpl * __pBooleanImpl;
279 #endif //_FBASE_BOOLEAN_H_