darwin-xnu/libkern/c++/OSBoolean.cpp
<<
>>
Prefs
   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
  31OSDefineMetaClassAndStructors(OSBoolean, OSObject)
  32OSMetaClassDefineReservedUnused(OSBoolean, 0);
  33OSMetaClassDefineReservedUnused(OSBoolean, 1);
  34OSMetaClassDefineReservedUnused(OSBoolean, 2);
  35OSMetaClassDefineReservedUnused(OSBoolean, 3);
  36OSMetaClassDefineReservedUnused(OSBoolean, 4);
  37OSMetaClassDefineReservedUnused(OSBoolean, 5);
  38OSMetaClassDefineReservedUnused(OSBoolean, 6);
  39OSMetaClassDefineReservedUnused(OSBoolean, 7);
  40
  41static OSBoolean * gOSBooleanTrue  = 0;
  42static OSBoolean * gOSBooleanFalse = 0;
  43
  44OSBoolean * const & kOSBooleanTrue  = gOSBooleanTrue;
  45OSBoolean * const & kOSBooleanFalse = gOSBooleanFalse;
  46
  47void 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
  68void 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
  79void OSBoolean::taggedRetain(const void *tag) const { }
  80void OSBoolean::taggedRelease(const void *tag, const int when) const { }
  81
  82OSBoolean *OSBoolean::withBoolean(bool inValue)
  83{
  84    return (inValue) ? kOSBooleanTrue : kOSBooleanFalse;
  85}
  86
  87bool OSBoolean::isTrue() const { return value; }
  88bool OSBoolean::isFalse() const { return !value; }
  89bool OSBoolean::getValue() const { return value; }
  90
  91bool OSBoolean::isEqualTo(const OSBoolean *boolean) const
  92{
  93    return (boolean == this);
  94}
  95
  96bool 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
 105bool OSBoolean::serialize(OSSerialize *s) const
 106{
 107    return s->addString(value ? "<true/>" : "<false/>");
 108}
 109
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.