]> git.saurik.com Git - apple/xnu.git/blob - libkern/c++/OSBoolean.cpp
b6a1bb4f9d298f49acd07d1d75f33605df517a92
[apple/xnu.git] / libkern / c++ / OSBoolean.cpp
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /* OSBoolean.cpp created by rsulack on Tue Oct 12 1999 */
24
25 #include <libkern/c++/OSBoolean.h>
26 #include <libkern/c++/OSString.h>
27 #include <libkern/c++/OSSerialize.h>
28 #include <libkern/c++/OSLib.h>
29
30 #define super OSObject
31
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);
41
42 static OSBoolean * gOSBooleanTrue = 0;
43 static OSBoolean * gOSBooleanFalse = 0;
44
45 OSBoolean * const & kOSBooleanTrue = gOSBooleanTrue;
46 OSBoolean * const & kOSBooleanFalse = gOSBooleanFalse;
47
48 void OSBoolean::initialize()
49 {
50 gOSBooleanTrue = new OSBoolean;
51 assert(gOSBooleanTrue);
52
53 if (!gOSBooleanTrue->init()) {
54 gOSBooleanTrue->OSObject::free();
55 assert(false);
56 };
57 gOSBooleanTrue->value = true;
58
59 gOSBooleanFalse = new OSBoolean;
60 assert(gOSBooleanFalse);
61
62 if (!gOSBooleanFalse->init()) {
63 gOSBooleanFalse->OSObject::free();
64 assert(false);
65 };
66 gOSBooleanFalse->value = false;
67 }
68
69 void OSBoolean::free()
70 {
71 /*
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.
76 */
77 assert(false);
78 }
79
80 void OSBoolean::taggedRetain(const void *tag) const { }
81 void OSBoolean::taggedRelease(const void *tag, const int when) const { }
82
83 OSBoolean *OSBoolean::withBoolean(bool inValue)
84 {
85 return (inValue) ? kOSBooleanTrue : kOSBooleanFalse;
86 }
87
88 bool OSBoolean::isTrue() const { return value; }
89 bool OSBoolean::isFalse() const { return !value; }
90 bool OSBoolean::getValue() const { return value; }
91
92 bool OSBoolean::isEqualTo(const OSBoolean *boolean) const
93 {
94 return (boolean == this);
95 }
96
97 bool OSBoolean::isEqualTo(const OSMetaClassBase *obj) const
98 {
99 OSBoolean * boolean;
100 if ((boolean = OSDynamicCast(OSBoolean, obj)))
101 return isEqualTo(boolean);
102 else
103 return false;
104 }
105
106 bool OSBoolean::serialize(OSSerialize *s) const
107 {
108 return s->addString(value ? "<true/>" : "<false/>");
109 }