1 /* 2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 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. 11 * 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 18 * under the License. 19 * 20 * @APPLE_LICENSE_HEADER_END@ 21 */ 22 /* OSBoolean.cpp created by rsulack on Tue Oct 12 1999 */ 23 24 #include <libkern/c++/OSBoolean.h> 25 #include <libkern/c++/OSString.h> 26 #include <libkern/c++/OSSerialize.h> 27 #include <libkern/c++/OSLib.h> 28 29 #define super OSObject 30 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); 40 41 static OSBoolean * gOSBooleanTrue = 0; 42 static OSBoolean * gOSBooleanFalse = 0; 43 44 OSBoolean * const & kOSBooleanTrue = gOSBooleanTrue; 45 OSBoolean * const & kOSBooleanFalse = gOSBooleanFalse; 46 47 void OSBoolean::initialize() 48 { 49 gOSBooleanTrue = new OSBoolean; 50 assert(gOSBooleanTrue); 51 52 if (!gOSBooleanTrue->init()) { 53 gOSBooleanTrue->OSObject::free(); 54 assert(false); 55 }; 56 gOSBooleanTrue->value = true; 57 58 gOSBooleanFalse = new OSBoolean; 59 assert(gOSBooleanFalse); 60 61 if (!gOSBooleanFalse->init()) { 62 gOSBooleanFalse->OSObject::free(); 63 assert(false); 64 }; 65 gOSBooleanFalse->value = false; 66 } 67 68 void OSBoolean::free() 69 { 70 /* 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. 75 */ 76 assert(false); 77 } 78 79 void OSBoolean::taggedRetain(const void *tag) const { } 80 void OSBoolean::taggedRelease(const void *tag, const int when) const { } 81 82 OSBoolean *OSBoolean::withBoolean(bool inValue) 83 { 84 return (inValue) ? kOSBooleanTrue : kOSBooleanFalse; 85 } 86 87 bool OSBoolean::isTrue() const { return value; } 88 bool OSBoolean::isFalse() const { return !value; } 89 bool OSBoolean::getValue() const { return value; } 90 91 bool OSBoolean::isEqualTo(const OSBoolean *boolean) const 92 { 93 return (boolean == this); 94 } 95 96 bool OSBoolean::isEqualTo(const OSMetaClassBase *obj) const 97 { 98 OSBoolean * boolean; 99 if ((boolean = OSDynamicCast(OSBoolean, obj))) 100 return isEqualTo(boolean); 101 else 102 return false; 103 } 104 105 bool OSBoolean::serialize(OSSerialize *s) const 106 { 107 return s->addString(value ? "<true/>" : "<false/>"); 108 } 109