]> git.saurik.com Git - apple/xnu.git/blob - libkern/c++/OSBoolean.cpp
xnu-792.12.6.tar.gz
[apple/xnu.git] / libkern / c++ / OSBoolean.cpp
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_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
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
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
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.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /* OSBoolean.cpp created by rsulack on Tue Oct 12 1999 */
31
32 #include <libkern/c++/OSBoolean.h>
33 #include <libkern/c++/OSString.h>
34 #include <libkern/c++/OSSerialize.h>
35 #include <libkern/c++/OSLib.h>
36
37 #define super OSObject
38
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);
48
49 static OSBoolean * gOSBooleanTrue = 0;
50 static OSBoolean * gOSBooleanFalse = 0;
51
52 OSBoolean * const & kOSBooleanTrue = gOSBooleanTrue;
53 OSBoolean * const & kOSBooleanFalse = gOSBooleanFalse;
54
55 void OSBoolean::initialize()
56 {
57 gOSBooleanTrue = new OSBoolean;
58 assert(gOSBooleanTrue);
59
60 if (!gOSBooleanTrue->init()) {
61 gOSBooleanTrue->OSObject::free();
62 assert(false);
63 };
64 gOSBooleanTrue->value = true;
65
66 gOSBooleanFalse = new OSBoolean;
67 assert(gOSBooleanFalse);
68
69 if (!gOSBooleanFalse->init()) {
70 gOSBooleanFalse->OSObject::free();
71 assert(false);
72 };
73 gOSBooleanFalse->value = false;
74 }
75
76 void OSBoolean::free()
77 {
78 /*
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.
83 */
84 assert(false);
85 }
86
87 void OSBoolean::taggedRetain(const void *tag) const { }
88 void OSBoolean::taggedRelease(const void *tag, const int when) const { }
89
90 OSBoolean *OSBoolean::withBoolean(bool inValue)
91 {
92 return (inValue) ? kOSBooleanTrue : kOSBooleanFalse;
93 }
94
95 bool OSBoolean::isTrue() const { return value; }
96 bool OSBoolean::isFalse() const { return !value; }
97 bool OSBoolean::getValue() const { return value; }
98
99 bool OSBoolean::isEqualTo(const OSBoolean *boolean) const
100 {
101 return (boolean == this);
102 }
103
104 bool OSBoolean::isEqualTo(const OSMetaClassBase *obj) const
105 {
106 OSBoolean * boolean;
107 if ((boolean = OSDynamicCast(OSBoolean, obj)))
108 return isEqualTo(boolean);
109 else
110 return false;
111 }
112
113 bool OSBoolean::serialize(OSSerialize *s) const
114 {
115 return s->addString(value ? "<true/>" : "<false/>");
116 }