// file: $isip/class/search/NBestPath/NBestPath.h
// version: $Id: NBestPath.h 9332 2003-11-03 14:27:14Z alphonso $
//

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

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

#ifndef ISIP_LONG
#include <Long.h>
#endif

#ifndef ISIP_SINGLE_LINKED_LIST
#include <SingleLinkedList.h>
#endif

#ifndef ISIP_NBEST_NODE
#include <NBestNode.h>
#endif

// NBestPath: a class that is used as the list of partial paths
//
class NBestPath {

  //---------------------------------------------------------------------------
  //
  // 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_MAX_SCORE = -1.0e10;
  static const long DEF_FRAME_INDEX = 0;
  
  //---------------------------------------
  //
  // error codes
  //
  //---------------------------------------

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

  // define the linked list of partial paths
  //
  SingleLinkedList<NBestNode> paths_d;

  // define the frame at which this path list was created
  //
  Long frame_index_d;

  // define the score of the best partial path in this list
  //
  Float max_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
  //
  ~NBestPath() {
    clear();
  }

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

    // set the member data
    //
    frame_index_d = DEF_FRAME_INDEX;
    max_score_d = DEF_MAX_SCORE;

    // set the allocation mode
    //
    paths_d.setAllocationMode(DstrBase::USER);
  }

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

  // method: assign
  //
  boolean assign(const NBestPath& copy_node) {
    return Error::handle(name(), L"assign", Error::ARG, __FILE__, __LINE__);
  }
  
  // method: operator=
  //
  NBestPath& operator=(const NBestPath& 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 NBestPath& 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);

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

  // method: getNumPaths
  //
  long getNumPaths() const {
    return paths_d.length();
  }
  
  // method: setPaths
  //
  boolean setPaths(SingleLinkedList<NBestNode>& arg) {
    return paths_d.assign(arg);
  }

  // method: getPaths
  //
  SingleLinkedList<NBestNode>& getPaths() {
    return paths_d;
  }
  
  // method: setFrameIndex
  //
  boolean setFrameIndex(long arg) {
    return (frame_index_d = arg);
  }

  // method: getFrameIndex
  //
  long getFrameIndex() {
    return frame_index_d;
  }  
  
  // method: setMaxScore
  //
  boolean setMaxScore(float arg) {
    return (max_score_d = arg);
  }

  // method: getMaxScore
  //
  float getMaxScore() {
    return max_score_d;
  }  
  
  // method to add a partial paths
  //
  boolean insertPath(NBestNode* path);
  
  // method to extend partial paths
  //
  boolean growPaths(NBestPath**& path_list, float scale, float penalty,
		    long max_paths, float beam);
  
  // method to prune partial paths
  //
  boolean prune(float beam, long max_paths);
  
  //---------------------------------------------------------------------------
  //
  // private methods
  //
  //---------------------------------------------------------------------------
private:

};

// end of include file
//
#endif
