// file: $isip/class/search/ContextMap/ContextMap.h
// version: $Id: ContextMap.h 8911 2002-12-13 22:25:56Z parihar $
//

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

// isip include files
//
#ifndef ISIP_SEARCH_SYMBOL
#include <SearchSymbol.h>
#endif

#ifndef ISIP_VECTOR
#include <Vector.h>
#endif

#ifndef ISIP_PAIR
#include <Pair.h>
#endif

#ifndef ISIP_ULONG
#include <Ulong.h>
#endif

// ContextMap: a class that provides a mapping between a sequence (context
// dependent/independent) at the current level of the search hierarchy and
// their corresponding subgraphs at the next level.
//
class ContextMap {

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

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

  //----------------------------------------
  //
  // i/o related constants
  //
  //----------------------------------------
  
  static const String DEF_PARAM;
  static const String PARAM_CONTEXT;  
  static const String PARAM_CONTEXT_INDEX;  
  
  //----------------------------------------
  //
  // default values and arguments
  //
  //----------------------------------------

  //---------------------------------------
  //
  // error codes
  //
  //---------------------------------------

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

  // sequence of search symbols
  //
  Vector<SearchSymbol> context_d;

  // subgraph index of the search symbols
  //
  Ulong index_d;
  
  // 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);

  // debug methods
  //  
  boolean debug(const unichar* message) const;
  
  // method: destructor
  //
  ~ContextMap() {}

  // method: default constructor
  //
  ContextMap() {}

  // method: copy constructor
  //
  ContextMap(const ContextMap& arg) {
    assign(arg);
  }

  // assign method
  //
  boolean assign(const ContextMap& arg);  

  // method: sofSize
  //
  long sofSize() const {
    return context_d.sofSize() + index_d.sofSize();
  }

  // read methods
  //
  boolean read(Sof& sof, long tag, const String& cname = CLASS_NAME);
  boolean readData(Sof& sof, const String& pname = DEF_PARAM,
		   long size = SofParser::FULL_OBJECT, boolean param = true,
                   boolean nested = false);
  
  // write methods
  //
  boolean write(Sof& sof, long tag, const String& cname = CLASS_NAME) const;
  boolean writeData(Sof& sof, const String& pname = DEF_PARAM) const;
  
  // equality method
  //
  boolean eq(const ContextMap& arg) const;
  
  // 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);
  }

  // clear method
  //
  boolean clear(Integral::CMODE ctype = Integral::DEF_CMODE);
  
  //---------------------------------------------------------------------------
  //
  // class-specific public methods
  //
  //---------------------------------------------------------------------------

  // method: getContext
  //
  Vector<SearchSymbol>& getContext() {
    return context_d;
  }

  // method: setContext
  //
  boolean setContext(Vector<SearchSymbol>& arg) {
    return context_d.assign(arg);
  }

  // method: getContextIndex
  //
  Ulong getContextIndex() {
    return index_d;
  }  
  
  // method: setContextIndex
  //
  boolean setContextIndex(ulong arg) {
    index_d = arg;
    return true;
  }  
  
  //---------------------------------------------------------------------------
  //
  // private methods
  //
  //---------------------------------------------------------------------------
private:

};

// end of include file
//
#endif
