// file: $isip/class/math/scalar/Boolean/Boolean.h
// version: $Id: Boolean.h 6805 2001-04-23 22:57:41Z peng $
//

// make sure definitions are only made once
//
#ifndef ISIP_BOOLEAN
#define ISIP_BOOLEAN

// isip include files
//
#ifndef ISIP_SCALAR
#include <MScalar.h>
#endif

// Boolean: a binary boolean value (boolean true or boolean false)
//
class Boolean {

  //---------------------------------------------------------------------------
  //
  // public constants
  //
  //---------------------------------------------------------------------------
public:

  // define the class name
  //
  static const String CLASS_NAME;

  //----------------------------------------
  //
  // other important constants
  //
  //----------------------------------------
  
  // i/o related constants
  //
  static const String DEF_PARAM;

  //----------------------------------------
  //
  // default values and arguments
  //
  //----------------------------------------  

  // define the default value(s) of the class data
  //
  static const boolean DEF_VALUE = false;

  // default arguments to methods
  //
  
  //----------------------------------------
  //
  // error codes
  //
  //----------------------------------------  

  static const long ERR = 20100;

  //---------------------------------------------------------------------------
  //
  // protected data
  //
  //---------------------------------------------------------------------------
protected:

  // boolean value
  //
  boolean value_d;

  // define a static debug level for all objects of this class
  //
  static Integral::DEBUG debug_level_d;
  
  // static memory manager
  //
  static MemoryManager mgr_d;
  
  //---------------------------------------------------------------------------
  //
  // required public methods
  //
  //---------------------------------------------------------------------------
public:
  
  // method: name
  //
  static const String& name() {
    return CLASS_NAME;
  }

  // other static methods
  //
  static boolean diagnose(Integral::DEBUG debug_level);

  // method: setDebug
  //
  static boolean setDebug(Integral::DEBUG level) {
    debug_level_d = level;
    return true;
  }

  // other debug methods
  //
  boolean debug(const unichar* message) const;

  // method: destructor
  //
  ~Boolean() {}

  // method: default constructor
  //
  Boolean(boolean arg = DEF_VALUE) {
    value_d = arg;
  }

  // method: copy constructor
  //
  Boolean(const Boolean& arg) {
    assign(arg);
  }
  
  // method: assign
  //
  boolean assign(const Boolean& arg) {
    value_d = arg;
    return true;
  }

  // method: operator=
  //
  Boolean& operator= (const Boolean& arg) {
    assign(arg);
    return *this;
  }

  // method: sofSize
  //
  long sofSize() const {
    return sizeof(byte8);
  }

  // other i/o methods
  //
  boolean read(Sof& sof, long tag, const String& name = CLASS_NAME);
  boolean write(Sof& sof, long tag, const String& name = CLASS_NAME) const;

  boolean readData(Sof& sof, const String& pname = DEF_PARAM,
		   long size = SofParser::FULL_OBJECT,
		   boolean param = true,
		   boolean nested = false);
  boolean writeData(Sof& sof, const String& pname = DEF_PARAM) const;

  // method: eq
  //
  boolean eq(const Boolean& arg) const {
    return (value_d == arg.value_d);
  }
  
  // method: new
  //
  static void* operator new(size_t size) {
    return mgr_d.get();
  }

  // method: new[]
  //
  static void* operator new[](size_t size) {
    return mgr_d.getBlock(size);
  }

  // method: delete
  //
  static void operator delete(void* ptr) {
    mgr_d.release(ptr);
  }

  // method: delete[]
  // 
  static void operator delete[](void* ptr) {
    mgr_d.releaseBlock(ptr);
  }

  // method: setGrowSize
  //
  static boolean setGrowSize(long grow_size) {
    return mgr_d.setGrow(grow_size);
  }

  // method: clear
  //
  boolean clear(Integral::CMODE ctype = Integral::DEF_CMODE) {
    value_d = DEF_VALUE;
    return true;
  }
  
  //---------------------------------------------------------------------------
  //
  // class-specific public methods
  //
  //---------------------------------------------------------------------------
public:

  // method: assign
  //
  boolean assign(boolean arg) {
    value_d = arg;
    return true;
  }

  // method: assign
  //
  boolean assign(const String& arg) {
    arg.get(value_d);
    return true;
  }
  
  // method: almostEqual
  //  note that we need this method for higher-level templates
  //
  boolean almostEqual(boolean arg) const {
    return (value_d == arg);
  }

  // method: almostEqual
  //  note that we need this method for higher-level templates
  //  
  boolean almostEqual(boolean arg, double, double) const {
    return (value_d == arg);
  }

  // method: operator=
  //
  Boolean& operator= (boolean arg) {
    value_d = arg;
    return *this;
  }

  // method: operator()
  //
  operator boolean() const {
    return value_d;
  }

  // method: get
  //
  boolean get(String& arg) const {
    arg.assign(value_d);
    return true;
  }
  
  // method: rand
  //
  boolean rand(Random& generator = Random::GLOBAL_UNIFORM) {
    return (generator.get() > 0.5);
  }

  // method: memSize
  //
  long memSize() const {
    return sizeof(boolean);
  }
  
  //---------------------------------------------------------------------------
  //
  // private methods
  //
  //---------------------------------------------------------------------------
private:

};

// end of include file
//
#endif
