]>
git.saurik.com Git - apple/xnu.git/blob - libkern/c++/OSBoolean.cpp
cd3ba2ef940c323a871bc1b99afb8f401de7c75b
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* OSBoolean.cpp created by rsulack on Tue Oct 12 1999 */
24 #include <libkern/c++/OSBoolean.h>
25 #include <libkern/c++/OSString.h>
26 #include <libkern/c++/OSSerialize.h>
27 #include <libkern/c++/OSLib.h>
29 #define super OSObject
31 OSDefineMetaClassAndStructors(OSBoolean
, OSObject
)
32 OSMetaClassDefineReservedUnused(OSBoolean
, 0);
33 OSMetaClassDefineReservedUnused(OSBoolean
, 1);
34 OSMetaClassDefineReservedUnused(OSBoolean
, 2);
35 OSMetaClassDefineReservedUnused(OSBoolean
, 3);
36 OSMetaClassDefineReservedUnused(OSBoolean
, 4);
37 OSMetaClassDefineReservedUnused(OSBoolean
, 5);
38 OSMetaClassDefineReservedUnused(OSBoolean
, 6);
39 OSMetaClassDefineReservedUnused(OSBoolean
, 7);
41 static OSBoolean
* gOSBooleanTrue
= 0;
42 static OSBoolean
* gOSBooleanFalse
= 0;
44 OSBoolean
* const & kOSBooleanTrue
= gOSBooleanTrue
;
45 OSBoolean
* const & kOSBooleanFalse
= gOSBooleanFalse
;
47 void OSBoolean::initialize()
49 gOSBooleanTrue
= new OSBoolean
;
50 assert(gOSBooleanTrue
);
52 if (!gOSBooleanTrue
->init()) {
53 gOSBooleanTrue
->OSObject::free();
56 gOSBooleanTrue
->value
= true;
58 gOSBooleanFalse
= new OSBoolean
;
59 assert(gOSBooleanFalse
);
61 if (!gOSBooleanFalse
->init()) {
62 gOSBooleanFalse
->OSObject::free();
65 gOSBooleanFalse
->value
= false;
68 void OSBoolean::free()
71 * An OSBoolean should never have free() called on it, since it is a shared
72 * object, with two non-mutable instances: kOSBooleanTrue, kOSBooleanFalse.
73 * There will be cases where an incorrect number of releases will cause the
74 * free() method to be called, however, which we must catch and ignore here.
79 OSBoolean
*OSBoolean::withBoolean(bool inValue
)
82 kOSBooleanTrue
->retain();
83 return kOSBooleanTrue
;
85 kOSBooleanFalse
->retain();
86 return 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/>");