xref: /xnu-12377.81.4/libkern/libkern/c++/OSBoolean.h (revision 043036a2b3718f7f0be807e2870f8f47d3fa0796)
1*043036a2SApple OSS Distributions /*
2*043036a2SApple OSS Distributions  * Copyright (c) 2019 Apple Inc. All rights reserved.
3*043036a2SApple OSS Distributions  *
4*043036a2SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*043036a2SApple OSS Distributions  *
6*043036a2SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*043036a2SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*043036a2SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*043036a2SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*043036a2SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*043036a2SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*043036a2SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*043036a2SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*043036a2SApple OSS Distributions  *
15*043036a2SApple OSS Distributions  * Please obtain a copy of the License at
16*043036a2SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*043036a2SApple OSS Distributions  *
18*043036a2SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*043036a2SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*043036a2SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*043036a2SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*043036a2SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*043036a2SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*043036a2SApple OSS Distributions  * limitations under the License.
25*043036a2SApple OSS Distributions  *
26*043036a2SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*043036a2SApple OSS Distributions  */
28*043036a2SApple OSS Distributions /* OSBoolean.cpp created by rsulack on Tue Oct 12 1999 */
29*043036a2SApple OSS Distributions 
30*043036a2SApple OSS Distributions #ifndef _OS_OSBOOLEAN_H
31*043036a2SApple OSS Distributions #define _OS_OSBOOLEAN_H
32*043036a2SApple OSS Distributions 
33*043036a2SApple OSS Distributions #include <libkern/c++/OSObject.h>
34*043036a2SApple OSS Distributions #include <libkern/c++/OSPtr.h>
35*043036a2SApple OSS Distributions 
36*043036a2SApple OSS Distributions class OSString;
37*043036a2SApple OSS Distributions class OSBoolean;
38*043036a2SApple OSS Distributions 
39*043036a2SApple OSS Distributions typedef OSBoolean* OSBooleanPtr;
40*043036a2SApple OSS Distributions 
41*043036a2SApple OSS Distributions /*!
42*043036a2SApple OSS Distributions  * @header
43*043036a2SApple OSS Distributions  *
44*043036a2SApple OSS Distributions  * @abstract
45*043036a2SApple OSS Distributions  * This header declares the OSBoolean container class.
46*043036a2SApple OSS Distributions  */
47*043036a2SApple OSS Distributions 
48*043036a2SApple OSS Distributions 
49*043036a2SApple OSS Distributions /*!
50*043036a2SApple OSS Distributions  * @class OSBoolean
51*043036a2SApple OSS Distributions  *
52*043036a2SApple OSS Distributions  * @abstract
53*043036a2SApple OSS Distributions  * OSBoolean wraps a boolean value in a C++ object
54*043036a2SApple OSS Distributions  * for use in Libkern collections.
55*043036a2SApple OSS Distributions  *
56*043036a2SApple OSS Distributions  * @discussion
57*043036a2SApple OSS Distributions  * OSBoolean represents a boolean <code>true</code>/<code>false</code> value
58*043036a2SApple OSS Distributions  * as a Libkern C++ object.
59*043036a2SApple OSS Distributions  * There are only two instances of OSBoolean,
60*043036a2SApple OSS Distributions  * <code>@link kOSBooleanTrue kOSBooleanTrue@/link</code>
61*043036a2SApple OSS Distributions  * and <code>@link kOSBooleanFalse kOSBooleanFalse@/link</code>.
62*043036a2SApple OSS Distributions  * These are shared globally and returned by the instance-creation function
63*043036a2SApple OSS Distributions  * <code>@link withBoolean withBoolean@/link</code>.
64*043036a2SApple OSS Distributions  * Thus, you can use pointer comparison
65*043036a2SApple OSS Distributions  * to test whether two OSBoolean objects are equal.
66*043036a2SApple OSS Distributions  */
67*043036a2SApple OSS Distributions class OSBoolean : public OSObject
68*043036a2SApple OSS Distributions {
69*043036a2SApple OSS Distributions 	OSDeclareDefaultStructors(OSBoolean);
70*043036a2SApple OSS Distributions 	friend class OSSerialize;
71*043036a2SApple OSS Distributions 
72*043036a2SApple OSS Distributions protected:
73*043036a2SApple OSS Distributions 	bool value;
74*043036a2SApple OSS Distributions 
75*043036a2SApple OSS Distributions /*!
76*043036a2SApple OSS Distributions  * @function taggedRelease
77*043036a2SApple OSS Distributions  *
78*043036a2SApple OSS Distributions  * @abstract
79*043036a2SApple OSS Distributions  * Overrides the reference counting mechanism
80*043036a2SApple OSS Distributions  * for the shared global instances.
81*043036a2SApple OSS Distributions  *
82*043036a2SApple OSS Distributions  * @param tag  Unused.
83*043036a2SApple OSS Distributions  * @param when Unused.
84*043036a2SApple OSS Distributions  */
85*043036a2SApple OSS Distributions 	virtual void taggedRelease(
86*043036a2SApple OSS Distributions 		const void * tag,
87*043036a2SApple OSS Distributions 		const int    when) const APPLE_KEXT_OVERRIDE;
88*043036a2SApple OSS Distributions 
89*043036a2SApple OSS Distributions public:
90*043036a2SApple OSS Distributions 	static void initialize();
91*043036a2SApple OSS Distributions 
92*043036a2SApple OSS Distributions /*!
93*043036a2SApple OSS Distributions  * @function withBoolean
94*043036a2SApple OSS Distributions  *
95*043036a2SApple OSS Distributions  * @abstract
96*043036a2SApple OSS Distributions  * Returns one of the global instances of OSBoolean.
97*043036a2SApple OSS Distributions  *
98*043036a2SApple OSS Distributions  * @param value   A boolean value.
99*043036a2SApple OSS Distributions  *
100*043036a2SApple OSS Distributions  * @result
101*043036a2SApple OSS Distributions  * The global instance of OSBoolean with the boolean <code>value</code>.
102*043036a2SApple OSS Distributions  *
103*043036a2SApple OSS Distributions  * @discussion
104*043036a2SApple OSS Distributions  * This function actually returns either
105*043036a2SApple OSS Distributions  * <code>@link kOSBooleanTrue kOSBooleanTrue@/link</code> or
106*043036a2SApple OSS Distributions  * <code>@link kOSBooleanFalse kOSBooleanFalse@/link</code>,
107*043036a2SApple OSS Distributions  * so that you can always use pointer comparison with OSBoolean objects.
108*043036a2SApple OSS Distributions  */
109*043036a2SApple OSS Distributions 	static OSPtr<OSBoolean> withBoolean(bool value) __returns_nonnull_osptr;
110*043036a2SApple OSS Distributions 
111*043036a2SApple OSS Distributions /*!
112*043036a2SApple OSS Distributions  * @function free
113*043036a2SApple OSS Distributions  *
114*043036a2SApple OSS Distributions  * @abstract
115*043036a2SApple OSS Distributions  * Overridden to prevent deallocation of the shared global instances.
116*043036a2SApple OSS Distributions  *
117*043036a2SApple OSS Distributions  * @discussion
118*043036a2SApple OSS Distributions  * This function should never be called.
119*043036a2SApple OSS Distributions  */
120*043036a2SApple OSS Distributions 	virtual void free() APPLE_KEXT_OVERRIDE;
121*043036a2SApple OSS Distributions 
122*043036a2SApple OSS Distributions 
123*043036a2SApple OSS Distributions /*!
124*043036a2SApple OSS Distributions  * @function taggedRetain
125*043036a2SApple OSS Distributions  *
126*043036a2SApple OSS Distributions  * @abstract
127*043036a2SApple OSS Distributions  * Overrides the reference counting mechanism for the shared global instances.
128*043036a2SApple OSS Distributions  *
129*043036a2SApple OSS Distributions  * @param tag  Unused.
130*043036a2SApple OSS Distributions  */
131*043036a2SApple OSS Distributions 	virtual void taggedRetain(const void * tag) const APPLE_KEXT_OVERRIDE;
132*043036a2SApple OSS Distributions 
133*043036a2SApple OSS Distributions 
134*043036a2SApple OSS Distributions /*!
135*043036a2SApple OSS Distributions  * @function isTrue
136*043036a2SApple OSS Distributions  *
137*043036a2SApple OSS Distributions  * @abstract
138*043036a2SApple OSS Distributions  * Checks whether the OSBoolean object
139*043036a2SApple OSS Distributions  * represents a <code>true</code> <code>bool</code> value.
140*043036a2SApple OSS Distributions  *
141*043036a2SApple OSS Distributions  * @result
142*043036a2SApple OSS Distributions  * <code>true</code> if the OSBoolean object is <code>true</code>,
143*043036a2SApple OSS Distributions  * <code>false</code> otherwise.
144*043036a2SApple OSS Distributions  *
145*043036a2SApple OSS Distributions  * @discussion
146*043036a2SApple OSS Distributions  * You can also use <code>==</code> against
147*043036a2SApple OSS Distributions  * <code>@link kOSBooleanTrue kOSBooleanTrue@/link</code>.
148*043036a2SApple OSS Distributions  */
149*043036a2SApple OSS Distributions 	virtual bool isTrue() const;
150*043036a2SApple OSS Distributions 
151*043036a2SApple OSS Distributions 
152*043036a2SApple OSS Distributions /*!
153*043036a2SApple OSS Distributions  * @function isFalse
154*043036a2SApple OSS Distributions  *
155*043036a2SApple OSS Distributions  * @abstract
156*043036a2SApple OSS Distributions  * Checks whether the OSBoolean object
157*043036a2SApple OSS Distributions  * represents a <code>false</code> <code>bool</code> value.
158*043036a2SApple OSS Distributions  *
159*043036a2SApple OSS Distributions  * @result
160*043036a2SApple OSS Distributions  * <code>true</code> if the OSBoolean object is <code>false</code>,
161*043036a2SApple OSS Distributions  * <code>true</code> otherwise.
162*043036a2SApple OSS Distributions  *
163*043036a2SApple OSS Distributions  * @discussion
164*043036a2SApple OSS Distributions  * You can also use <code>==</code> against
165*043036a2SApple OSS Distributions  * <code>@link kOSBooleanFalse kOSBooleanFalse@/link</code>.
166*043036a2SApple OSS Distributions  */
167*043036a2SApple OSS Distributions 	virtual bool isFalse() const;
168*043036a2SApple OSS Distributions 
169*043036a2SApple OSS Distributions 
170*043036a2SApple OSS Distributions /*!
171*043036a2SApple OSS Distributions  * @function getValue
172*043036a2SApple OSS Distributions  *
173*043036a2SApple OSS Distributions  * @abstract
174*043036a2SApple OSS Distributions  * Returns the C++ <code>bool</code> value for the OSBoolean object.
175*043036a2SApple OSS Distributions  *
176*043036a2SApple OSS Distributions  * @result
177*043036a2SApple OSS Distributions  * Returns the C++ <code>bool</code> value of the OSBoolean object.
178*043036a2SApple OSS Distributions  */
179*043036a2SApple OSS Distributions 	virtual bool getValue() const;
180*043036a2SApple OSS Distributions 
181*043036a2SApple OSS Distributions 
182*043036a2SApple OSS Distributions /*!
183*043036a2SApple OSS Distributions  * @function isEqualTo
184*043036a2SApple OSS Distributions  *
185*043036a2SApple OSS Distributions  * @abstract
186*043036a2SApple OSS Distributions  * Tests the equality of two OSBoolean objects.
187*043036a2SApple OSS Distributions  *
188*043036a2SApple OSS Distributions  * @param aBoolean    The OSBoolean to be compared against the receiver.
189*043036a2SApple OSS Distributions  *
190*043036a2SApple OSS Distributions  * @result
191*043036a2SApple OSS Distributions  * <code>true</code> if the OSBoolean objects are equal,
192*043036a2SApple OSS Distributions  * <code>false</code> if not.
193*043036a2SApple OSS Distributions  *
194*043036a2SApple OSS Distributions  * @discussion
195*043036a2SApple OSS Distributions  * Two OSBoolean objects are considered equal
196*043036a2SApple OSS Distributions  * if they are the same exact object (pointer equality).
197*043036a2SApple OSS Distributions  */
198*043036a2SApple OSS Distributions 	virtual bool isEqualTo(const OSBoolean * aBoolean) const;
199*043036a2SApple OSS Distributions 
200*043036a2SApple OSS Distributions 
201*043036a2SApple OSS Distributions /*!
202*043036a2SApple OSS Distributions  * @function isEqualTo
203*043036a2SApple OSS Distributions  *
204*043036a2SApple OSS Distributions  * @abstract
205*043036a2SApple OSS Distributions  * Tests the equality an OSBoolean to an arbitrary object.
206*043036a2SApple OSS Distributions  *
207*043036a2SApple OSS Distributions  * @param anObject  An object to be compared against the receiver.
208*043036a2SApple OSS Distributions  *
209*043036a2SApple OSS Distributions  * @result
210*043036a2SApple OSS Distributions  * <code>true</code> if the objects are equal, <code>false</code> if not.
211*043036a2SApple OSS Distributions  *
212*043036a2SApple OSS Distributions  * @discussion
213*043036a2SApple OSS Distributions  * An OSBoolean is considered equal to another object
214*043036a2SApple OSS Distributions  * if that object is derived from OSBoolean
215*043036a2SApple OSS Distributions  * and represents the same C++ <code>bool</code> value.
216*043036a2SApple OSS Distributions  */
217*043036a2SApple OSS Distributions 	virtual bool isEqualTo(const OSMetaClassBase * anObject) const APPLE_KEXT_OVERRIDE;
218*043036a2SApple OSS Distributions 
219*043036a2SApple OSS Distributions 
220*043036a2SApple OSS Distributions /*!
221*043036a2SApple OSS Distributions  * @function serialize
222*043036a2SApple OSS Distributions  *
223*043036a2SApple OSS Distributions  * @abstract
224*043036a2SApple OSS Distributions  * Archives the receiver into the provided
225*043036a2SApple OSS Distributions  * @link //apple_ref/doc/class/OSSerialize OSSerialize@/link object.
226*043036a2SApple OSS Distributions  *
227*043036a2SApple OSS Distributions  * @param serializer  The OSSerialize object.
228*043036a2SApple OSS Distributions  *
229*043036a2SApple OSS Distributions  * @result
230*043036a2SApple OSS Distributions  * <code>true</code> if serialization succeeds, <code>false</code> if not.
231*043036a2SApple OSS Distributions  */
232*043036a2SApple OSS Distributions 	virtual bool serialize(OSSerialize * serializer) const APPLE_KEXT_OVERRIDE;
233*043036a2SApple OSS Distributions 
234*043036a2SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(OSBoolean, 0);
235*043036a2SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(OSBoolean, 1);
236*043036a2SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(OSBoolean, 2);
237*043036a2SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(OSBoolean, 3);
238*043036a2SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(OSBoolean, 4);
239*043036a2SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(OSBoolean, 5);
240*043036a2SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(OSBoolean, 6);
241*043036a2SApple OSS Distributions 	OSMetaClassDeclareReservedUnused(OSBoolean, 7);
242*043036a2SApple OSS Distributions };
243*043036a2SApple OSS Distributions 
244*043036a2SApple OSS Distributions /*!
245*043036a2SApple OSS Distributions  * @const kOSBooleanTrue
246*043036a2SApple OSS Distributions  *
247*043036a2SApple OSS Distributions  * @abstract
248*043036a2SApple OSS Distributions  * The OSBoolean constant for <code>true</code>.
249*043036a2SApple OSS Distributions  *
250*043036a2SApple OSS Distributions  * @discussion
251*043036a2SApple OSS Distributions  * kOSBooleanTrue is the OSBoolean constant for <code>true</code>.
252*043036a2SApple OSS Distributions  * This object does not need to be retained or released (but it can be).
253*043036a2SApple OSS Distributions  * Comparisons of the form
254*043036a2SApple OSS Distributions  * <code>booleanObject == kOSBooleanTrue</code>
255*043036a2SApple OSS Distributions  * are acceptable and are equivalent to
256*043036a2SApple OSS Distributions  * <code>booleanObject->getValue() == true</code>.
257*043036a2SApple OSS Distributions  */
258*043036a2SApple OSS Distributions extern OSBoolean * const & kOSBooleanTrue;
259*043036a2SApple OSS Distributions 
260*043036a2SApple OSS Distributions /*!
261*043036a2SApple OSS Distributions  * @const kOSBooleanFalse
262*043036a2SApple OSS Distributions  *
263*043036a2SApple OSS Distributions  * @abstract
264*043036a2SApple OSS Distributions  * The OSBoolean constant for <code>false</code>.
265*043036a2SApple OSS Distributions  *
266*043036a2SApple OSS Distributions  * @discussion
267*043036a2SApple OSS Distributions  * kOSBooleanFalse is the OSBoolean constant for <code>false</code>.
268*043036a2SApple OSS Distributions  * This object does not need to be retained or released (but it can be).
269*043036a2SApple OSS Distributions  * Comparisons of the form
270*043036a2SApple OSS Distributions  * <code>booleanObject == kOSBooleanFalse</code>
271*043036a2SApple OSS Distributions  * are acceptable and are equivalent to
272*043036a2SApple OSS Distributions  * <code>booleanObject->getValue() == false</code>.
273*043036a2SApple OSS Distributions  */
274*043036a2SApple OSS Distributions extern OSBoolean * const & kOSBooleanFalse;
275*043036a2SApple OSS Distributions 
276*043036a2SApple OSS Distributions #endif /* !_OS_OSBOOLEAN_H */
277