]>
git.saurik.com Git - apple/xnu.git/blob - libkern/c++/OSBoolean.cpp
19c5dd89f658d7f283069b9de37fdcf3b40e513b
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
23 * @APPLE_LICENSE_HEADER_END@
25 /* OSBoolean.cpp created by rsulack on Tue Oct 12 1999 */
27 #include <libkern/c++/OSBoolean.h>
28 #include <libkern/c++/OSString.h>
29 #include <libkern/c++/OSSerialize.h>
30 #include <libkern/c++/OSLib.h>
32 #define super OSObject
34 OSDefineMetaClassAndStructors(OSBoolean
, OSObject
)
35 OSMetaClassDefineReservedUnused(OSBoolean
, 0);
36 OSMetaClassDefineReservedUnused(OSBoolean
, 1);
37 OSMetaClassDefineReservedUnused(OSBoolean
, 2);
38 OSMetaClassDefineReservedUnused(OSBoolean
, 3);
39 OSMetaClassDefineReservedUnused(OSBoolean
, 4);
40 OSMetaClassDefineReservedUnused(OSBoolean
, 5);
41 OSMetaClassDefineReservedUnused(OSBoolean
, 6);
42 OSMetaClassDefineReservedUnused(OSBoolean
, 7);
44 static OSBoolean
* gOSBooleanTrue
= 0;
45 static OSBoolean
* gOSBooleanFalse
= 0;
47 OSBoolean
* const & kOSBooleanTrue
= gOSBooleanTrue
;
48 OSBoolean
* const & kOSBooleanFalse
= gOSBooleanFalse
;
50 void OSBoolean::initialize()
52 gOSBooleanTrue
= new OSBoolean
;
53 assert(gOSBooleanTrue
);
55 if (!gOSBooleanTrue
->init()) {
56 gOSBooleanTrue
->OSObject::free();
59 gOSBooleanTrue
->value
= true;
61 gOSBooleanFalse
= new OSBoolean
;
62 assert(gOSBooleanFalse
);
64 if (!gOSBooleanFalse
->init()) {
65 gOSBooleanFalse
->OSObject::free();
68 gOSBooleanFalse
->value
= false;
71 void OSBoolean::free()
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.
82 void OSBoolean::taggedRetain(const void *tag
) const { }
83 void OSBoolean::taggedRelease(const void *tag
, const int when
) const { }
85 OSBoolean
*OSBoolean::withBoolean(bool inValue
)
87 return (inValue
) ? kOSBooleanTrue
: kOSBooleanFalse
;
90 bool OSBoolean::isTrue() const { return value
; }
91 bool OSBoolean::isFalse() const { return !value
; }
92 bool OSBoolean::getValue() const { return value
; }
94 bool OSBoolean::isEqualTo(const OSBoolean
*boolean
) const
96 return (boolean
== this);
99 bool OSBoolean::isEqualTo(const OSMetaClassBase
*obj
) const
102 if ((boolean
= OSDynamicCast(OSBoolean
, obj
)))
103 return isEqualTo(boolean
);
108 bool OSBoolean::serialize(OSSerialize
*s
) const
110 return s
->addString(value
? "<true/>" : "<false/>");