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