]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 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. | |
8f6c56a5 | 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. | |
17 | * | |
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. | |
8f6c56a5 | 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 | 37 | OSDefineMetaClassAndStructorsWithInit(OSBoolean, OSObject, OSBoolean::initialize()) |
1c79356b A |
38 | OSMetaClassDefineReservedUnused(OSBoolean, 0); |
39 | OSMetaClassDefineReservedUnused(OSBoolean, 1); | |
40 | OSMetaClassDefineReservedUnused(OSBoolean, 2); | |
41 | OSMetaClassDefineReservedUnused(OSBoolean, 3); | |
42 | OSMetaClassDefineReservedUnused(OSBoolean, 4); | |
43 | OSMetaClassDefineReservedUnused(OSBoolean, 5); | |
44 | OSMetaClassDefineReservedUnused(OSBoolean, 6); | |
45 | OSMetaClassDefineReservedUnused(OSBoolean, 7); | |
46 | ||
47 | static OSBoolean * gOSBooleanTrue = 0; | |
48 | static OSBoolean * gOSBooleanFalse = 0; | |
49 | ||
50 | OSBoolean * const & kOSBooleanTrue = gOSBooleanTrue; | |
51 | OSBoolean * const & kOSBooleanFalse = gOSBooleanFalse; | |
52 | ||
53 | void OSBoolean::initialize() | |
54 | { | |
55 | gOSBooleanTrue = new OSBoolean; | |
56 | assert(gOSBooleanTrue); | |
57 | ||
58 | if (!gOSBooleanTrue->init()) { | |
59 | gOSBooleanTrue->OSObject::free(); | |
60 | assert(false); | |
61 | }; | |
62 | gOSBooleanTrue->value = true; | |
63 | ||
64 | gOSBooleanFalse = new OSBoolean; | |
65 | assert(gOSBooleanFalse); | |
66 | ||
67 | if (!gOSBooleanFalse->init()) { | |
68 | gOSBooleanFalse->OSObject::free(); | |
69 | assert(false); | |
70 | }; | |
71 | gOSBooleanFalse->value = false; | |
72 | } | |
73 | ||
74 | void OSBoolean::free() | |
75 | { | |
76 | /* | |
77 | * An OSBoolean should never have free() called on it, since it is a shared | |
78 | * object, with two non-mutable instances: kOSBooleanTrue, kOSBooleanFalse. | |
79 | * There will be cases where an incorrect number of releases will cause the | |
80 | * free() method to be called, however, which we must catch and ignore here. | |
81 | */ | |
82 | assert(false); | |
83 | } | |
84 | ||
b0d623f7 A |
85 | void OSBoolean::taggedRetain(__unused const void *tag) const { } |
86 | void OSBoolean::taggedRelease(__unused const void *tag, __unused const int when) const { } | |
9bccf70c | 87 | |
1c79356b A |
88 | OSBoolean *OSBoolean::withBoolean(bool inValue) |
89 | { | |
9bccf70c | 90 | return (inValue) ? kOSBooleanTrue : kOSBooleanFalse; |
1c79356b A |
91 | } |
92 | ||
93 | bool OSBoolean::isTrue() const { return value; } | |
94 | bool OSBoolean::isFalse() const { return !value; } | |
95 | bool OSBoolean::getValue() const { return value; } | |
96 | ||
97 | bool OSBoolean::isEqualTo(const OSBoolean *boolean) const | |
98 | { | |
99 | return (boolean == this); | |
100 | } | |
101 | ||
102 | bool OSBoolean::isEqualTo(const OSMetaClassBase *obj) const | |
103 | { | |
104 | OSBoolean * boolean; | |
105 | if ((boolean = OSDynamicCast(OSBoolean, obj))) | |
106 | return isEqualTo(boolean); | |
107 | else | |
108 | return false; | |
109 | } | |
110 | ||
111 | bool OSBoolean::serialize(OSSerialize *s) const | |
112 | { | |
113 | return s->addString(value ? "<true/>" : "<false/>"); | |
114 | } |