]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/c++/OSBoolean.h
4eb533ccf7f525f77eebe05acfd20a9da0f2155d
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
)
66 friend class OSSerialize
;
72 * @function taggedRelease
75 * Overrides the reference counting mechanism
76 * for the shared global instances.
81 virtual void taggedRelease(
83 const int when
) const;
86 static void initialize();
89 * @function withBoolean
92 * Returns one of the global instances of OSBoolean.
94 * @param value A boolean value.
97 * The global instance of OSBoolean with the boolean <code>value</code>.
100 * This function actually returns either
101 * <code>@link kOSBooleanTrue kOSBooleanTrue@/link</code> or
102 * <code>@link kOSBooleanFalse kOSBooleanFalse@/link</code>,
103 * so that you can always use pointer comparison with OSBoolean objects.
105 static OSBoolean
* withBoolean(bool value
);
111 * Overridden to prevent deallocation of the shared global instances.
114 * This function should never be called.
120 * @function taggedRetain
123 * Overrides the reference counting mechanism for the shared global instances.
127 virtual void taggedRetain(const void * tag
) const;
134 * Checks whether the OSBoolean object
135 * represents a <code>true</code> <code>bool</code> value.
138 * <code>true</code> if the OSBoolean object is <code>true</code>,
139 * <code>false</code> otherwise.
142 * You can also use <code>==</code> against
143 * <code>@link kOSBooleanTrue kOSBooleanTrue@/link</code>.
145 virtual bool isTrue() const;
152 * Checks whether the OSBoolean object
153 * represents a <code>false</code> <code>bool</code> value.
156 * <code>true</code> if the OSBoolean object is <code>false</code>,
157 * <code>true</code> otherwise.
160 * You can also use <code>==</code> against
161 * <code>@link kOSBooleanFalse kOSBooleanFalse@/link</code>.
163 virtual bool isFalse() const;
170 * Returns the C++ <code>bool</code> value for the OSBoolean object.
173 * Returns the C++ <code>bool</code> value of the OSBoolean object.
175 virtual bool getValue() const;
179 * @function isEqualTo
182 * Tests the equality of two OSBoolean objects.
184 * @param aBoolean The OSBoolean to be compared against the receiver.
187 * <code>true</code> if the OSBoolean objects are equal,
188 * <code>false</code> if not.
191 * Two OSBoolean objects are considered equal
192 * if they are the same exact object (pointer equality).
194 virtual bool isEqualTo(const OSBoolean
* aBoolean
) const;
198 * @function isEqualTo
201 * Tests the equality an OSBoolean to an arbitrary object.
203 * @param anObject An object to be compared against the receiver.
206 * <code>true</code> if the objects are equal, <code>false</code> if not.
209 * An OSBoolean is considered equal to another object
210 * if that object is derived from OSBoolean
211 * and represents the same C++ <code>bool</code> value.
213 virtual bool isEqualTo(const OSMetaClassBase
* anObject
) const;
217 * @function serialize
220 * Archives the receiver into the provided
221 * @link //apple_ref/doc/class/OSSerialize OSSerialize@/link object.
223 * @param serializer The OSSerialize object.
226 * <code>true</code> if serialization succeeds, <code>false</code> if not.
228 virtual bool serialize(OSSerialize
* serializer
) const;
230 OSMetaClassDeclareReservedUnused(OSBoolean
, 0);
231 OSMetaClassDeclareReservedUnused(OSBoolean
, 1);
232 OSMetaClassDeclareReservedUnused(OSBoolean
, 2);
233 OSMetaClassDeclareReservedUnused(OSBoolean
, 3);
234 OSMetaClassDeclareReservedUnused(OSBoolean
, 4);
235 OSMetaClassDeclareReservedUnused(OSBoolean
, 5);
236 OSMetaClassDeclareReservedUnused(OSBoolean
, 6);
237 OSMetaClassDeclareReservedUnused(OSBoolean
, 7);
241 * @const kOSBooleanTrue
244 * The OSBoolean constant for <code>true</code>.
247 * kOSBooleanTrue is the OSBoolean constant for <code>true</code>.
248 * This object does not need to be retained or released (but it can be).
249 * Comparisons of the form
250 * <code>booleanObject == kOSBooleanTrue</code>
251 * are acceptable and are equivalent to
252 * <code>booleanObject->getValue() == true</code>.
254 extern OSBoolean
* const & kOSBooleanTrue
;
257 * @const kOSBooleanFalse
260 * The OSBoolean constant for <code>false</code>.
263 * kOSBooleanFalse is the OSBoolean constant for <code>false</code>.
264 * This object does not need to be retained or released (but it can be).
265 * Comparisons of the form
266 * <code>booleanObject == kOSBooleanFalse</code>
267 * are acceptable and are equivalent to
268 * <code>booleanObject->getValue() == false</code>.
270 extern OSBoolean
* const & kOSBooleanFalse
;
272 #endif /* !_OS_OSBOOLEAN_H */