]> git.saurik.com Git - apple/xnu.git/blame - libkern/c++/OSBoolean.cpp
xnu-344.49.tar.gz
[apple/xnu.git] / libkern / c++ / OSBoolean.cpp
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
43866e37 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
43866e37
A
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
43866e37
A
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
1c79356b
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25/* OSBoolean.cpp created by rsulack on Tue Oct 12 1999 */
26
27#include <libkern/c++/OSBoolean.h>
28#include <libkern/c++/OSString.h>
29#include <libkern/c++/OSSerialize.h>
30#include <libkern/c++/OSLib.h>
31
32#define super OSObject
33
34OSDefineMetaClassAndStructors(OSBoolean, OSObject)
35OSMetaClassDefineReservedUnused(OSBoolean, 0);
36OSMetaClassDefineReservedUnused(OSBoolean, 1);
37OSMetaClassDefineReservedUnused(OSBoolean, 2);
38OSMetaClassDefineReservedUnused(OSBoolean, 3);
39OSMetaClassDefineReservedUnused(OSBoolean, 4);
40OSMetaClassDefineReservedUnused(OSBoolean, 5);
41OSMetaClassDefineReservedUnused(OSBoolean, 6);
42OSMetaClassDefineReservedUnused(OSBoolean, 7);
43
44static OSBoolean * gOSBooleanTrue = 0;
45static OSBoolean * gOSBooleanFalse = 0;
46
47OSBoolean * const & kOSBooleanTrue = gOSBooleanTrue;
48OSBoolean * const & kOSBooleanFalse = gOSBooleanFalse;
49
50void OSBoolean::initialize()
51{
52 gOSBooleanTrue = new OSBoolean;
53 assert(gOSBooleanTrue);
54
55 if (!gOSBooleanTrue->init()) {
56 gOSBooleanTrue->OSObject::free();
57 assert(false);
58 };
59 gOSBooleanTrue->value = true;
60
61 gOSBooleanFalse = new OSBoolean;
62 assert(gOSBooleanFalse);
63
64 if (!gOSBooleanFalse->init()) {
65 gOSBooleanFalse->OSObject::free();
66 assert(false);
67 };
68 gOSBooleanFalse->value = false;
69}
70
71void OSBoolean::free()
72{
73 /*
74 * An OSBoolean should never have free() called on it, since it is a shared
75 * object, with two non-mutable instances: kOSBooleanTrue, kOSBooleanFalse.
76 * There will be cases where an incorrect number of releases will cause the
77 * free() method to be called, however, which we must catch and ignore here.
78 */
79 assert(false);
80}
81
9bccf70c
A
82void OSBoolean::taggedRetain(const void *tag) const { }
83void OSBoolean::taggedRelease(const void *tag, const int when) const { }
84
1c79356b
A
85OSBoolean *OSBoolean::withBoolean(bool inValue)
86{
9bccf70c 87 return (inValue) ? kOSBooleanTrue : kOSBooleanFalse;
1c79356b
A
88}
89
90bool OSBoolean::isTrue() const { return value; }
91bool OSBoolean::isFalse() const { return !value; }
92bool OSBoolean::getValue() const { return value; }
93
94bool OSBoolean::isEqualTo(const OSBoolean *boolean) const
95{
96 return (boolean == this);
97}
98
99bool OSBoolean::isEqualTo(const OSMetaClassBase *obj) const
100{
101 OSBoolean * boolean;
102 if ((boolean = OSDynamicCast(OSBoolean, obj)))
103 return isEqualTo(boolean);
104 else
105 return false;
106}
107
108bool OSBoolean::serialize(OSSerialize *s) const
109{
110 return s->addString(value ? "<true/>" : "<false/>");
111}