// file: $isip/class/search/History/History.h
// version: $Id: History.h 9029 2003-02-15 17:08:33Z alphonso $
//

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

// isip include files
//
#ifndef ISIP_STACK
#include <Stack.h>
#endif

#ifndef ISIP_VECTOR_ULONG
#include <VectorUlong.h>
#endif

// forward class declaration:
//
class Context;

// History: a class to keep track of the history through a search. it acts
// like a stack where graph vertices can be push'd onto and pop'd off of
// the history list. the majority of the useful interface is inherited
// from the Stack class
//
class History : public Stack<Context> {

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

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

  //----------------------------------------
  //
  // i/o related constants
  //
  //----------------------------------------  

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

  // define default arguments to methods
  //
  static const ulong DEF_REF_INCR = 1;
  static const ulong DEF_REF_DECR = 1;
  
  //---------------------------------------
  //
  // error codes
  //
  //---------------------------------------

  static const long ERR = (long)90100;
  
  //---------------------------------------------------------------------------
  //
  // protected data
  //
  //---------------------------------------------------------------------------
protected:

  // static debug level
  //
  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);

  // the debug method is inherited from the Stack class
  //

  // method: setDebug
  //
  static boolean setDebug(Integral::DEBUG debug_level) {
    debug_level_d = debug_level;
    return true;
  }
  
  // method: destructor
  //
  ~History() {
    if (debug_level_d >= Integral::ALL) {     
      fprintf(stdout, "Destructor of history: %p\n", this);
      fflush(stdout);
    }
  }

  // method: default constructor
  //
  History() {

    if (debug_level_d >= Integral::ALL) { 
      fprintf(stdout, "Constructor of history: %p\n", this);
      fflush(stdout);
    }

    setAllocationMode(DstrBase::USER);
  }

  // method: copy constructor
  //
  History(const History& copy_history) {

    if (debug_level_d >= Integral::ALL) { 
      fprintf(stdout, "Constructor of history: %p\n", this);
      fflush(stdout);
    }

    setAllocationMode(DstrBase::USER);    
    assign(copy_history);    
  }
  
  // the assign eq and operator= methods are inherited from the Stack class
  //

  // method: sofSize
  //
  long sofSize() const {
    return Stack<Context>::sofSize();
  }

  // method: read
  //
  boolean read(Sof& sof, long tag, const String& name = CLASS_NAME) {
    return Stack<Context>::read(sof, tag, name);
  }
  
  // method: write
  //
  boolean write(Sof& sof, long tag, const String& name = CLASS_NAME) const {
    return Stack<Context>::write(sof, tag, name);
  }

  // method: readData
  //
  boolean readData(Sof& sof, const String& pname = String::EMPTY,
		   long size = SofParser::FULL_OBJECT, boolean param = true,
                   boolean nested = false) {
    return Stack<Context>::readData(sof, pname, size, param, nested);
  }
  
  // method: writeData
  //
  boolean writeData(Sof& sof, const String& pname = String::EMPTY) const {
    return Stack<Context>::writeData(sof, pname);
  }

  // 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);
  }

  // the clear method is inherited from the Stack class
  //

  //---------------------------------------------------------------------------
  //
  // class-specific public methods
  //
  //---------------------------------------------------------------------------

  // hash function
  //
  long hash(long capacity) const;
  
  //---------------------------------------------------------------------------
  //
  // private methods
  //
  //---------------------------------------------------------------------------
private:

};

// include the train node class here circumvent the circular dependency
//
#ifndef ISIP_CONTEXT
#include <Context.h>
#endif

// end of include file
//
#endif
