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