2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FBaseBoolean.h
19 * @brief This is the header file for the %Boolean class.
21 * This header file contains the declarations of the %Boolean class.
23 #ifndef _FBASE_BOOLEAN_H_
24 #define _FBASE_BOOLEAN_H_
26 #include <FBaseObject.h>
27 #include <FBaseString.h>
30 namespace Tizen { namespace Base
34 * @brief This class is the wrapper class for the @c bool data type.
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.
41 * The following example demonstrates how to use the %Boolean class.
47 * using namespace Tizen::Base;
54 * String string1(b1.ToString()); // string1 == L"true"
57 * // Compares the string1 with L"true"
58 * if (Boolean::Parse(string1))
66 class _OSP_EXPORT_ Boolean
71 * Initializes this instance of the %Boolean class with the specified @c value.
75 * @param[in] value The input @c bool value to initialize the %Boolean instance
80 * Copying of objects using this copy constructor is allowed.
84 * @param[in] value An instance of the %Boolean class
86 Boolean(const Boolean& value);
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,
95 * @param[in] value An instance of String
97 Boolean(const String& value);
100 * This destructor overrides Tizen::Base::Object::~Object().
104 virtual ~Boolean(void);
107 * Compares the values of two %Boolean instances.
111 * @return @c true if the values of the objects are equal, @n
113 * @param[in] rhs An instance of %Boolean to compare with the current instance
115 bool operator ==(const Boolean& rhs) const;
118 * Checks whether the two %Boolean instances are not equal.
122 * @return @c true if the values of the objects are not equal, @n
124 * @param[in] rhs An instance of %Boolean to compare with the current instance
126 bool operator !=(const Boolean& rhs) const;
129 * Copying of objects using this copy assignment operator is allowed.
133 * @param[in] rhs An instance of %Boolean
135 Boolean& operator =(const Boolean& rhs);
138 * Converts an instance of the Object class to an instance of %Boolean and then
139 * compares it with the calling %Boolean instance.
143 * @return @c true if the value of @c obj matches the value of the calling %Boolean instance, @n
145 * @param[in] obj A reference to the Object instance to compare with the calling %Boolean instance
146 * @see Tizen::Base::Object::Equals()
148 virtual bool Equals(const Object& obj) const;
151 * Gets the hash value of the current instance.
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.
159 virtual int GetHashCode(void) const;
162 * Converts a bool value to an instance of %Boolean and then
163 * compares it with the calling %Boolean instance.
167 * @return @c true if the parameter matches the calling %Boolean instance, @n
169 * @param[in] value The @c bool value to compare to this instance
171 bool Equals(bool value) const;
174 * Returns the value of the calling object as @c bool.
178 * @return The value of the %Boolean instance as bool
180 bool ToBool(void) const;
183 * Parses the specified string and converts it to a @c bool value.
187 * @return @c true if the value of the specified string is "true", @n
189 * @param[in] s An instance of String
190 * @remarks This method is case sensitive. @n
191 * It only accepts lowercase strings.
194 * bool b1 = Boolean::Parse(trueString); // trueString is L"true"
195 * bool b1 = Boolean::Parse(falseString); // falseString is L"false"
198 static bool Parse(const String& s);
201 * Parses the specified string and converts it to a @c bool value. @n
202 * Case sensitivity can be controlled.
206 * @return @c true if the value of the specified string is "true", @n
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.
214 * bool b1 = Boolean::Parse(L"True", false ); // Returns @c true
215 * bool b1 = Boolean::Parse(L"True", true); // Returns @c false
218 static bool Parse(const String& s, bool caseSensitive);
221 * Converts the value of the calling instance from @c bool to String.
225 * @return @c true if this instance is @c true, @n
228 String ToString(void) const;
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).
237 * @return @c true if the parameter is @c true, @n
239 * @param[in] value A @c bool value to convert to String
241 static String ToString(bool value);
244 * Returns a %Boolean instance whose value corresponds to the
245 * primitive value @c true.
249 * @return A %Boolean instance equivalent to @c true
251 static const Boolean GetTrue(void);
254 * Returns a %Boolean instance whose value corresponds to the primitive
259 * @return A %Boolean instance equivalent to @c false
261 static const Boolean GetFalse(void);
264 * A boolean value of this instance.
271 friend class _BooleanImpl;
272 class _BooleanImpl* __pBooleanImpl;
278 #endif //_FBASE_BOOLEAN_H_