]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/c++/OSBoolean.h
cd99b47c9736975b59e115b466bff4bc074318d3
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* OSBoolean.cpp created by rsulack on Tue Oct 12 1999 */
30 #ifndef _OS_OSBOOLEAN_H
31 #define _OS_OSBOOLEAN_H
33 #include <libkern/c++/OSObject.h>
41 * This header declares the OSBoolean container class.
49 * OSBoolean wraps a boolean value in a C++ object
50 * for use in Libkern collections.
53 * OSBoolean represents a boolean <code>true</code>/<code>false</code> value
54 * as a Libkern C++ object.
55 * There are only two instances of OSBoolean,
56 * <code>@link kOSBooleanTrue kOSBooleanTrue@/link</code>
57 * and <code>@link kOSBooleanFalse kOSBooleanFalse@/link</code>.
58 * These are shared globally and returned by the instance-creation function
59 * <code>@link withBoolean withBoolean@/link</code>.
60 * Thus, you can use pointer comparison
61 * to test whether two OSBoolean objects are equal.
63 class OSBoolean
: public OSObject
65 OSDeclareDefaultStructors(OSBoolean
)
71 * @function taggedRelease
74 * Overrides the reference counting mechanism
75 * for the shared global instances.
80 virtual void taggedRelease(
82 const int when
) const;
85 static void initialize();
88 * @function withBoolean
91 * Returns one of the global instances of OSBoolean.
93 * @param value A boolean value.
96 * The global instance of OSBoolean with the boolean <code>value</code>.
99 * This function actually returns either
100 * <code>@link kOSBooleanTrue kOSBooleanTrue@/link</code> or
101 * <code>@link kOSBooleanFalse kOSBooleanFalse@/link</code>,
102 * so that you can always use pointer comparison with OSBoolean objects.
104 static OSBoolean
* withBoolean(bool value
);
110 * Overridden to prevent deallocation of the shared global instances.
113 * This function should never be called.
119 * @function taggedRetain
122 * Overrides the reference counting mechanism for the shared global instances.
126 virtual void taggedRetain(const void * tag
) const;
133 * Checks whether the OSBoolean object
134 * represents a <code>true</code> <code>bool</code> value.
137 * <code>true</code> if the OSBoolean object is <code>true</code>,
138 * <code>false</code> otherwise.
141 * You can also use <code>==</code> against
142 * <code>@link kOSBooleanTrue kOSBooleanTrue@/link</code>.
144 virtual bool isTrue() const;
151 * Checks whether the OSBoolean object
152 * represents a <code>false</code> <code>bool</code> value.
155 * <code>true</code> if the OSBoolean object is <code>false</code>,
156 * <code>true</code> otherwise.
159 * You can also use <code>==</code> against
160 * <code>@link kOSBooleanFalse kOSBooleanFalse@/link</code>.
162 virtual bool isFalse() const;
169 * Returns the C++ <code>bool</code> value for the OSBoolean object.
172 * Returns the C++ <code>bool</code> value of the OSBoolean object.
174 virtual bool getValue() const;
178 * @function isEqualTo
181 * Tests the equality of two OSBoolean objects.
183 * @param aBoolean The OSBoolean to be compared against the receiver.
186 * <code>true</code> if the OSBoolean objects are equal,
187 * <code>false</code> if not.
190 * Two OSBoolean objects are considered equal
191 * if they are the same exact object (pointer equality).
193 virtual bool isEqualTo(const OSBoolean
* aBoolean
) const;
197 * @function isEqualTo
200 * Tests the equality an OSBoolean to an arbitrary object.
202 * @param anObject An object to be compared against the receiver.
205 * <code>true</code> if the objects are equal, <code>false</code> if not.
208 * An OSBoolean is considered equal to another object
209 * if that object is derived from OSBoolean
210 * and represents the same C++ <code>bool</code> value.
212 virtual bool isEqualTo(const OSMetaClassBase
* anObject
) const;
216 * @function serialize
219 * Archives the receiver into the provided
220 * @link //apple_ref/doc/class/OSSerialize OSSerialize@/link object.
222 * @param serializer The OSSerialize object.
225 * <code>true</code> if serialization succeeds, <code>false</code> if not.
227 virtual bool serialize(OSSerialize
* serializer
) const;
229 OSMetaClassDeclareReservedUnused(OSBoolean
, 0);
230 OSMetaClassDeclareReservedUnused(OSBoolean
, 1);
231 OSMetaClassDeclareReservedUnused(OSBoolean
, 2);
232 OSMetaClassDeclareReservedUnused(OSBoolean
, 3);
233 OSMetaClassDeclareReservedUnused(OSBoolean
, 4);
234 OSMetaClassDeclareReservedUnused(OSBoolean
, 5);
235 OSMetaClassDeclareReservedUnused(OSBoolean
, 6);
236 OSMetaClassDeclareReservedUnused(OSBoolean
, 7);
240 * @const kOSBoolean<code>true</code>
243 * The OSBoolean constant for <code>true</code>.
246 * The OSBoolean constant for <code>true</code>.
247 * This object does not need to be retained or released (but it can be).
248 * Comparisons of the form
249 * booleanObject == kOSBooleanTrue</code> are acceptable
250 * and are equivalent to
251 * <code>booleanObject->getValue() == true</code>.
253 extern OSBoolean
* const & kOSBooleanTrue
;
256 * @const kOSBoolean<code>false</code>
259 * The OSBoolean constant for <code>false</code>.
262 * The OSBoolean constant for <code>false</code>.
263 * This object does not need to be retained or released (but it can be).
264 * Comparisons of the form
265 * <code>booleanObject == kOSBooleanFalse</code>
266 * are acceptable and are equivalent to
267 * <code>booleanObject->getValue() == <code>false</code>.
269 extern OSBoolean
* const & kOSBooleanFalse
;
271 #endif /* !_OS_OSBOOLEAN_H */