// file: $isip/class/search/NBestNode/NBestNode.h
// version: $Id: NBestNode.h 9330 2003-10-30 22:03:17Z alphonso $
//

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

#ifndef ISIP_DOUBLE
#include <Float.h>
#endif

#ifndef ISIP_SYMBOL_GRAPH_NODE
#include <SymbolGraphNode.h>
#endif

// NBestNode: a class to represent the location in the n-best search
//
class NBestNode {

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

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

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

  static const String DEF_PARAM;
  
  //----------------------------------------
  //
  // default values and arguments
  //
  //----------------------------------------  

  // default values
  //
  static const float DEF_PATH_SCORE = 0.0;
  
  //---------------------------------------
  //
  // error codes
  //
  //---------------------------------------

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

  // define the symbol graph node associated with this node
  //
  SymbolGraphNode* symbol_node_d;

  // define the backpointer
  //
  NBestNode* prev_node_d;

  // define the path score
  //
  Float path_score_d;
  
  // define a static memory manager
  //
  static MemoryManager mgr_d;
  
  // define a static debug level
  //
  static Integral::DEBUG debug_level_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 debug_level) {
    debug_level_d = debug_level;
    return true;
  }
  
  // method: destructor
  //
  ~NBestNode() {
    clear();
  }

  // method: default constructor
  //
  NBestNode() {
    symbol_node_d = (SymbolGraphNode*)NULL;
    prev_node_d = (NBestNode*)NULL;
    path_score_d = DEF_PATH_SCORE;
  }

  // method: constructor
  //
  NBestNode(SymbolGraphNode* sym_node, NBestNode* nbst_node, float score) {
    symbol_node_d = sym_node;
    prev_node_d = nbst_node;
    path_score_d = score;
  }  

  // method: copy constructor
  //
  NBestNode(const NBestNode& copy_sym) {
    assign(copy_sym);
  }

  // method: assign
  //
  boolean assign(const NBestNode& copy_node) {
    return Error::handle(name(), L"assign", Error::ARG, __FILE__, __LINE__);
  }
  
  // method: operator=
  //
  NBestNode& operator=(const NBestNode& arg) {
    assign(arg);
    return *this;
  }
  
  // method: sofSize
  //
  long sofSize() const {
    return Error::handle(name(), L"sofSize", Error::ARG, __FILE__, __LINE__);
  }

  // method: read
  //
  boolean read(Sof& sof, long tag, const String& cname = CLASS_NAME) {
    return Error::handle(name(), L"read", Error::ARG, __FILE__, __LINE__);
  }

  // method: readData
  //
  boolean readData(Sof& sof, const String& pname = DEF_PARAM,
		   long size = SofParser::FULL_OBJECT, boolean param = true,
                   boolean nested = false) {
    return Error::handle(name(), L"readData", Error::ARG, __FILE__, __LINE__);
  }
  
  // method: write
  //
  boolean write(Sof& sof, long tag, const String& cname = CLASS_NAME) const {
    return Error::handle(name(), L"write", Error::ARG, __FILE__, __LINE__);
  }

  // method: writeData
  //
  boolean writeData(Sof& sof, const String& pname = DEF_PARAM) const {
    return Error::handle(name(), L"writeData", Error::ARG, __FILE__, __LINE__);
  }

  // method: eq
  //
  boolean eq(const NBestNode& obj) const {
    return (this == &obj);
  }
  
  // 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) {
    symbol_node_d = (SymbolGraphNode*)NULL;
    prev_node_d = (NBestNode*)NULL;
    path_score_d = DEF_PATH_SCORE;
    return true;
  }

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

  // method: setSymbolNode
  //
  boolean setSymbolNode(SymbolGraphNode* arg) {
    symbol_node_d = arg;
    return true;
  }

  // method: getSymbolNode
  //
  SymbolGraphNode* getSymbolNode() const {
    return symbol_node_d;
  }

  // method: setPrevNode
  //
  boolean setPrevNode(NBestNode* arg) {
    prev_node_d = arg;
    return true;
  }

  // method: getPrevNode
  //
  NBestNode* getPrevNode() const {
    return prev_node_d;
  }    

  // method: setPathScore
  //
  boolean setPathScore(float arg) {
    path_score_d = arg;
    return true;
  }

  // method: getPathScore
  //
  float getPathScore() const {
    return path_score_d;
  }    
  
  //---------------------------------------------------------------------------
  //
  // private methods
  //
  //---------------------------------------------------------------------------
private:

};

// end of include file
//
#endif
