]> git.saurik.com Git - apple/xnu.git/blame - libkern/c++/OSBoolean.cpp
xnu-6153.11.26.tar.gz
[apple/xnu.git] / libkern / c++ / OSBoolean.cpp
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 5 *
2d21ac55
A
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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
0a7de745 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
0a7de745 17 *
2d21ac55
A
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
0a7de745 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/* OSBoolean.cpp created by rsulack on Tue Oct 12 1999 */
29
30#include <libkern/c++/OSBoolean.h>
31#include <libkern/c++/OSString.h>
32#include <libkern/c++/OSSerialize.h>
33#include <libkern/c++/OSLib.h>
34
35#define super OSObject
36
b0d623f7 37OSDefineMetaClassAndStructorsWithInit(OSBoolean, OSObject, OSBoolean::initialize())
1c79356b
A
38OSMetaClassDefineReservedUnused(OSBoolean, 0);
39OSMetaClassDefineReservedUnused(OSBoolean, 1);
40OSMetaClassDefineReservedUnused(OSBoolean, 2);
41OSMetaClassDefineReservedUnused(OSBoolean, 3);
42OSMetaClassDefineReservedUnused(OSBoolean, 4);
43OSMetaClassDefineReservedUnused(OSBoolean, 5);
44OSMetaClassDefineReservedUnused(OSBoolean, 6);
45OSMetaClassDefineReservedUnused(OSBoolean, 7);
46
cb323159
A
47static OSBoolean * gOSBooleanTrue = NULL;
48static OSBoolean * gOSBooleanFalse = NULL;
1c79356b
A
49
50OSBoolean * const & kOSBooleanTrue = gOSBooleanTrue;
51OSBoolean * const & kOSBooleanFalse = gOSBooleanFalse;
52
0a7de745
A
53void
54OSBoolean::initialize()
1c79356b 55{
0a7de745
A
56 gOSBooleanTrue = new OSBoolean;
57 assert(gOSBooleanTrue);
58
59 if (!gOSBooleanTrue->init()) {
60 gOSBooleanTrue->OSObject::free();
61 assert(false);
62 }
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 ;
74 gOSBooleanFalse->value = false;
1c79356b
A
75}
76
0a7de745
A
77void
78OSBoolean::free()
1c79356b 79{
0a7de745
A
80 /*
81 * An OSBoolean should never have free() called on it, since it is a shared
82 * object, with two non-mutable instances: kOSBooleanTrue, kOSBooleanFalse.
83 * There will be cases where an incorrect number of releases will cause the
84 * free() method to be called, however, which we must catch and ignore here.
85 */
86 assert(false);
1c79356b
A
87}
88
0a7de745
A
89void
90OSBoolean::taggedRetain(__unused const void *tag) const
91{
92}
93void
94OSBoolean::taggedRelease(__unused const void *tag, __unused const int when) const
95{
96}
9bccf70c 97
0a7de745
A
98OSBoolean *
99OSBoolean::withBoolean(bool inValue)
1c79356b 100{
0a7de745 101 return (inValue) ? kOSBooleanTrue : kOSBooleanFalse;
1c79356b
A
102}
103
0a7de745
A
104bool
105OSBoolean::isTrue() const
106{
107 return value;
108}
109bool
110OSBoolean::isFalse() const
111{
112 return !value;
113}
114bool
115OSBoolean::getValue() const
116{
117 return value;
118}
1c79356b 119
0a7de745
A
120bool
121OSBoolean::isEqualTo(const OSBoolean *boolean) const
1c79356b 122{
0a7de745 123 return boolean == this;
1c79356b
A
124}
125
0a7de745
A
126bool
127OSBoolean::isEqualTo(const OSMetaClassBase *obj) const
1c79356b 128{
0a7de745
A
129 OSBoolean * boolean;
130 if ((boolean = OSDynamicCast(OSBoolean, obj))) {
131 return isEqualTo(boolean);
132 } else {
133 return false;
134 }
1c79356b
A
135}
136
0a7de745
A
137bool
138OSBoolean::serialize(OSSerialize *s) const
1c79356b 139{
0a7de745
A
140 if (s->binary) {
141 return s->binarySerialize(this);
142 }
fe8ab488 143
0a7de745 144 return s->addString(value ? "<true/>" : "<false/>");
1c79356b 145}