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 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.
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 %Boolean with the specified @c value.
75 * @param[in] value The @c bool value used to initialize %Boolean
80 * Copying of objects using this copy constructor is allowed.
84 * @param[in] value An instance of %Boolean
86 Boolean(const Boolean& value);
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.
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 * Compares the specified Object instance with the current %Boolean instance.
142 * @return @c true if @c obj matches the current %Boolean instance, @n
144 * @param[in] obj A reference to the Object instance to compare with the current %Boolean instance
145 * @see Tizen::Base::Object::Equals()
147 virtual bool Equals(const Object& obj) const;
150 * Gets the hash value of the current instance.
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.
158 virtual int GetHashCode(void) const;
161 * Converts a @c bool value to an instance of %Boolean and then
162 * compares it with the current %Boolean instance.
166 * @return @c true if @c value matches the current %Boolean instance, @n
168 * @param[in] value The @c bool value to compare to this instance
170 bool Equals(bool value) const;
173 * Returns the value of the current object as @c bool.
177 * @return The value of the %Boolean instance as @c bool
179 bool ToBool(void) const;
182 * Parses the specified string and converts it to a @c bool value.
186 * @return @c true if the value of the specified string is "true", @n
188 * @param[in] s An instance of String
189 * @remarks This method is case sensitive and accepts only lowercase strings.
192 * bool b1 = Boolean::Parse(trueString); // trueString is L"true"
193 * bool b1 = Boolean::Parse(falseString); // falseString is L"false"
196 static bool Parse(const String& s);
199 * Parses the specified string and converts it to a @c bool value. @n
200 * Case sensitivity can be controlled.
204 * @return @c true if the value of the specified string is "true", @n
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.
212 * bool b1 = Boolean::Parse(L"True", false ); // Returns @c true
213 * bool b1 = Boolean::Parse(L"True", true); // Returns @c false
216 static bool Parse(const String& s, bool caseSensitive);
219 * Converts the value of the current instance from @c bool to String.
223 * @return @c true if this instance is @c true, @n
226 String ToString(void) const;
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).
235 * @return @c true if the parameter is @c true, @n
237 * @param[in] value The @c bool value to convert to String
239 static String ToString(bool value);
242 * Returns a %Boolean instance whose value corresponds to the
243 * primitive value @c true.
247 * @return A %Boolean instance equivalent to @c true
249 static const Boolean GetTrue(void);
252 * Returns a %Boolean instance whose value corresponds to the primitive
257 * @return A %Boolean instance equivalent to @c false
259 static const Boolean GetFalse(void);
262 * A boolean value of this instance.
269 friend class _BooleanImpl;
270 class _BooleanImpl* __pBooleanImpl;
276 #endif //_FBASE_BOOLEAN_H_