]>
git.saurik.com Git - apple/xnu.git/blob - libkern/c++/OSBoolean.cpp
b6a1bb4f9d298f49acd07d1d75f33605df517a92
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
23 /* OSBoolean.cpp created by rsulack on Tue Oct 12 1999 */
25 #include <libkern/c++/OSBoolean.h>
26 #include <libkern/c++/OSString.h>
27 #include <libkern/c++/OSSerialize.h>
28 #include <libkern/c++/OSLib.h>
30 #define super OSObject
32 OSDefineMetaClassAndStructors(OSBoolean
, OSObject
)
33 OSMetaClassDefineReservedUnused(OSBoolean
, 0);
34 OSMetaClassDefineReservedUnused(OSBoolean
, 1);
35 OSMetaClassDefineReservedUnused(OSBoolean
, 2);
36 OSMetaClassDefineReservedUnused(OSBoolean
, 3);
37 OSMetaClassDefineReservedUnused(OSBoolean
, 4);
38 OSMetaClassDefineReservedUnused(OSBoolean
, 5);
39 OSMetaClassDefineReservedUnused(OSBoolean
, 6);
40 OSMetaClassDefineReservedUnused(OSBoolean
, 7);
42 static OSBoolean
* gOSBooleanTrue
= 0;
43 static OSBoolean
* gOSBooleanFalse
= 0;
45 OSBoolean
* const & kOSBooleanTrue
= gOSBooleanTrue
;
46 OSBoolean
* const & kOSBooleanFalse
= gOSBooleanFalse
;
48 void OSBoolean::initialize()
50 gOSBooleanTrue
= new OSBoolean
;
51 assert(gOSBooleanTrue
);
53 if (!gOSBooleanTrue
->init()) {
54 gOSBooleanTrue
->OSObject::free();
57 gOSBooleanTrue
->value
= true;
59 gOSBooleanFalse
= new OSBoolean
;
60 assert(gOSBooleanFalse
);
62 if (!gOSBooleanFalse
->init()) {
63 gOSBooleanFalse
->OSObject::free();
66 gOSBooleanFalse
->value
= false;
69 void OSBoolean::free()
72 * An OSBoolean should never have free() called on it, since it is a shared
73 * object, with two non-mutable instances: kOSBooleanTrue, kOSBooleanFalse.
74 * There will be cases where an incorrect number of releases will cause the
75 * free() method to be called, however, which we must catch and ignore here.
80 void OSBoolean::taggedRetain(const void *tag
) const { }
81 void OSBoolean::taggedRelease(const void *tag
, const int when
) const { }
83 OSBoolean
*OSBoolean::withBoolean(bool inValue
)
85 return (inValue
) ? kOSBooleanTrue
: kOSBooleanFalse
;
88 bool OSBoolean::isTrue() const { return value
; }
89 bool OSBoolean::isFalse() const { return !value
; }
90 bool OSBoolean::getValue() const { return value
; }
92 bool OSBoolean::isEqualTo(const OSBoolean
*boolean
) const
94 return (boolean
== this);
97 bool OSBoolean::isEqualTo(const OSMetaClassBase
*obj
) const
100 if ((boolean
= OSDynamicCast(OSBoolean
, obj
)))
101 return isEqualTo(boolean
);
106 bool OSBoolean::serialize(OSSerialize
*s
) const
108 return s
->addString(value
? "<true/>" : "<false/>");