]>
git.saurik.com Git - apple/xnu.git/blob - libkern/c++/OSBoolean.cpp
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 /* OSBoolean.cpp created by rsulack on Tue Oct 12 1999 */
32 #include <libkern/c++/OSBoolean.h>
33 #include <libkern/c++/OSString.h>
34 #include <libkern/c++/OSSerialize.h>
35 #include <libkern/c++/OSLib.h>
37 #define super OSObject
39 OSDefineMetaClassAndStructors(OSBoolean
, OSObject
)
40 OSMetaClassDefineReservedUnused(OSBoolean
, 0);
41 OSMetaClassDefineReservedUnused(OSBoolean
, 1);
42 OSMetaClassDefineReservedUnused(OSBoolean
, 2);
43 OSMetaClassDefineReservedUnused(OSBoolean
, 3);
44 OSMetaClassDefineReservedUnused(OSBoolean
, 4);
45 OSMetaClassDefineReservedUnused(OSBoolean
, 5);
46 OSMetaClassDefineReservedUnused(OSBoolean
, 6);
47 OSMetaClassDefineReservedUnused(OSBoolean
, 7);
49 static OSBoolean
* gOSBooleanTrue
= 0;
50 static OSBoolean
* gOSBooleanFalse
= 0;
52 OSBoolean
* const & kOSBooleanTrue
= gOSBooleanTrue
;
53 OSBoolean
* const & kOSBooleanFalse
= gOSBooleanFalse
;
55 void OSBoolean::initialize()
57 gOSBooleanTrue
= new OSBoolean
;
58 assert(gOSBooleanTrue
);
60 if (!gOSBooleanTrue
->init()) {
61 gOSBooleanTrue
->OSObject::free();
64 gOSBooleanTrue
->value
= true;
66 gOSBooleanFalse
= new OSBoolean
;
67 assert(gOSBooleanFalse
);
69 if (!gOSBooleanFalse
->init()) {
70 gOSBooleanFalse
->OSObject::free();
73 gOSBooleanFalse
->value
= false;
76 void OSBoolean::free()
79 * An OSBoolean should never have free() called on it, since it is a shared
80 * object, with two non-mutable instances: kOSBooleanTrue, kOSBooleanFalse.
81 * There will be cases where an incorrect number of releases will cause the
82 * free() method to be called, however, which we must catch and ignore here.
87 void OSBoolean::taggedRetain(const void *tag
) const { }
88 void OSBoolean::taggedRelease(const void *tag
, const int when
) const { }
90 OSBoolean
*OSBoolean::withBoolean(bool inValue
)
92 return (inValue
) ? kOSBooleanTrue
: kOSBooleanFalse
;
95 bool OSBoolean::isTrue() const { return value
; }
96 bool OSBoolean::isFalse() const { return !value
; }
97 bool OSBoolean::getValue() const { return value
; }
99 bool OSBoolean::isEqualTo(const OSBoolean
*boolean
) const
101 return (boolean
== this);
104 bool OSBoolean::isEqualTo(const OSMetaClassBase
*obj
) const
107 if ((boolean
= OSDynamicCast(OSBoolean
, obj
)))
108 return isEqualTo(boolean
);
113 bool OSBoolean::serialize(OSSerialize
*s
) const
115 return s
->addString(value
? "<true/>" : "<false/>");