]> git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/c++/OSBoolean.h
cd99b47c9736975b59e115b466bff4bc074318d3
[apple/xnu.git] / libkern / libkern / c++ / OSBoolean.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /* OSBoolean.cpp created by rsulack on Tue Oct 12 1999 */
29
30 #ifndef _OS_OSBOOLEAN_H
31 #define _OS_OSBOOLEAN_H
32
33 #include <libkern/c++/OSObject.h>
34
35 class OSString;
36
37 /*!
38 * @header
39 *
40 * @abstract
41 * This header declares the OSBoolean container class.
42 */
43
44
45 /*!
46 * @class OSBoolean
47 *
48 * @abstract
49 * OSBoolean wraps a boolean value in a C++ object
50 * for use in Libkern collections.
51 *
52 * @discussion
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.
62 */
63 class OSBoolean : public OSObject
64 {
65 OSDeclareDefaultStructors(OSBoolean)
66
67 protected:
68 bool value;
69
70 /*!
71 * @function taggedRelease
72 *
73 * @abstract
74 * Overrides the reference counting mechanism
75 * for the shared global instances.
76 *
77 * @param tag Unused.
78 * @param when Unused.
79 */
80 virtual void taggedRelease(
81 const void * tag,
82 const int when) const;
83
84 public:
85 static void initialize();
86
87 /*!
88 * @function withBoolean
89 *
90 * @abstract
91 * Returns one of the global instances of OSBoolean.
92 *
93 * @param value A boolean value.
94 *
95 * @result
96 * The global instance of OSBoolean with the boolean <code>value</code>.
97 *
98 * @discussion
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.
103 */
104 static OSBoolean * withBoolean(bool value);
105
106 /*!
107 * @function free
108 *
109 * @abstract
110 * Overridden to prevent deallocation of the shared global instances.
111 *
112 * @discussion
113 * This function should never be called.
114 */
115 virtual void free();
116
117
118 /*!
119 * @function taggedRetain
120 *
121 * @abstract
122 * Overrides the reference counting mechanism for the shared global instances.
123 *
124 * @param tag Unused.
125 */
126 virtual void taggedRetain(const void * tag) const;
127
128
129 /*!
130 * @function isTrue
131 *
132 * @abstract
133 * Checks whether the OSBoolean object
134 * represents a <code>true</code> <code>bool</code> value.
135 *
136 * @result
137 * <code>true</code> if the OSBoolean object is <code>true</code>,
138 * <code>false</code> otherwise.
139 *
140 * @discussion
141 * You can also use <code>==</code> against
142 * <code>@link kOSBooleanTrue kOSBooleanTrue@/link</code>.
143 */
144 virtual bool isTrue() const;
145
146
147 /*!
148 * @function isFalse
149 *
150 * @abstract
151 * Checks whether the OSBoolean object
152 * represents a <code>false</code> <code>bool</code> value.
153 *
154 * @result
155 * <code>true</code> if the OSBoolean object is <code>false</code>,
156 * <code>true</code> otherwise.
157 *
158 * @discussion
159 * You can also use <code>==</code> against
160 * <code>@link kOSBooleanFalse kOSBooleanFalse@/link</code>.
161 */
162 virtual bool isFalse() const;
163
164
165 /*!
166 * @function getValue
167 *
168 * @abstract
169 * Returns the C++ <code>bool</code> value for the OSBoolean object.
170 *
171 * @result
172 * Returns the C++ <code>bool</code> value of the OSBoolean object.
173 */
174 virtual bool getValue() const;
175
176
177 /*!
178 * @function isEqualTo
179 *
180 * @abstract
181 * Tests the equality of two OSBoolean objects.
182 *
183 * @param aBoolean The OSBoolean to be compared against the receiver.
184 *
185 * @result
186 * <code>true</code> if the OSBoolean objects are equal,
187 * <code>false</code> if not.
188 *
189 * @discussion
190 * Two OSBoolean objects are considered equal
191 * if they are the same exact object (pointer equality).
192 */
193 virtual bool isEqualTo(const OSBoolean * aBoolean) const;
194
195
196 /*!
197 * @function isEqualTo
198 *
199 * @abstract
200 * Tests the equality an OSBoolean to an arbitrary object.
201 *
202 * @param anObject An object to be compared against the receiver.
203 *
204 * @result
205 * <code>true</code> if the objects are equal, <code>false</code> if not.
206 *
207 * @discussion
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.
211 */
212 virtual bool isEqualTo(const OSMetaClassBase * anObject) const;
213
214
215 /*!
216 * @function serialize
217 *
218 * @abstract
219 * Archives the receiver into the provided
220 * @link //apple_ref/doc/class/OSSerialize OSSerialize@/link object.
221 *
222 * @param serializer The OSSerialize object.
223 *
224 * @result
225 * <code>true</code> if serialization succeeds, <code>false</code> if not.
226 */
227 virtual bool serialize(OSSerialize * serializer) const;
228
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);
237 };
238
239 /*!
240 * @const kOSBoolean<code>true</code>
241 *
242 * @abstract
243 * The OSBoolean constant for <code>true</code>.
244 *
245 * @discussion
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>.
252 */
253 extern OSBoolean * const & kOSBooleanTrue;
254
255 /*!
256 * @const kOSBoolean<code>false</code>
257 *
258 * @abstract
259 * The OSBoolean constant for <code>false</code>.
260 *
261 * @discussion
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>.
268 */
269 extern OSBoolean * const & kOSBooleanFalse;
270
271 #endif /* !_OS_OSBOOLEAN_H */