// file: instance.h
//
// this is the header for the path instance class
//

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

// isip include files
//
#ifndef __ISIP_INTEGRAL
#include <integral.h>
#endif

#ifndef __ISIP_INTEGRAL_CONSTANTS
#include <integral_constants.h>
#endif

#ifndef __ISIP_TOKEN
#include <token.h>
#endif

// forward class definitions
//
class Lex_node;
class Trace;

// Instance: a class that is used as the path instance for a
// trace-projection decoder
//
class Instance {
  
  //---------------------------------------------------------------------------
  //
  // protected data
  //
  //---------------------------------------------------------------------------
protected:

  // coordinates in the search space (it also depends on the history
  // but we don't need to save this information since instance is uniquely
  // hashed
  //
  Lex_node* lex_node_d;                  // position in the lexical tree
  int_4 phone_index_d;                   // index of the model

  // trace lists for each state in this model
  //
  Link_list* token_list_d;               // tokens for each state
  
  // score data
  //
  float_4 max_score_d;                   // max path score for this instance
  float_4 lm_score_d;                    // lm score for this instance

  // frame in which this instance was last active
  //
  int_4 frame_d;
  
  //---------------------------------------------------------------------------
  //
  // public methods
  //
  //---------------------------------------------------------------------------
public:
  
  // required methods
  //
  char_1* name_cc();
  volatile void error_handler_cc(char_1* mname, char_1* msg);
  logical_1 debug_cc(FILE* fp, char_1* message);
  int_4 size_cc();
  
  // destructors/constructors
  //
  ~Instance();  
  Instance();                                         // default
  Instance(Instance& inst);                           // copy

  // set all parameters
  //
  logical_1 set_params_cc(Lex_node* lex, int_4 phn) {
    lex_node_d = lex;
    phone_index_d = phn;
    return ISIP_TRUE;
  }
  
  logical_1 get_params_cc(Lex_node*& lex, int_4& phn) {
    lex = lex_node_d;
    phn = phone_index_d;
    return ISIP_TRUE;
  }
  
  // lexical tree node methods
  //
  logical_1 set_lex_node_cc(Lex_node* lex) {
    lex_node_d = lex;
    return ISIP_TRUE;
  }
  Lex_node* get_lex_node_cc() {
    return lex_node_d;
  }
  
  // phone index methods
  //
  logical_1 set_phone_ind_cc(int_4 phn) {
    phone_index_d = phn;
    return ISIP_TRUE;
  }
  
  int_4 get_phone_ind_cc() {
    return phone_index_d;
  }

  // token list methods
  //
  logical_1 set_toklist_cc(Link_list* list) {
    token_list_d = list;
    return ISIP_TRUE;
  }

  Link_list* get_toklist_cc() {
    return token_list_d;
  }
  
  logical_1 insert_trace_cc(Trace* trace, int_4 state, logical_1 flag,
			    float_4& score);
  logical_1 reset_markers_cc();
  
  // max path score methods
  //
  logical_1 set_score_cc(float_4 score) {
    max_score_d = score;
    return ISIP_TRUE;
  }
  
  float_4 get_score_cc() {
    return max_score_d;
  }
  
  logical_1 compare_score_cc(float_4 score) {
    if (max_score_d < score) {
      max_score_d = score;
    }
    return ISIP_TRUE;
  }

  // lm score methods
  //
  logical_1 set_lmscore_cc(float_4 score) {
    lm_score_d = score;
    return ISIP_TRUE;
  }

  float_4 get_lmscore_cc() {
    return lm_score_d;
  }
  
  logical_1 compare_lmscore_cc(float_4 score) {
    if (lm_score_d < score) {
      lm_score_d = score;
    }
    return ISIP_TRUE;
  }

  // frame index methods
  //
  logical_1 set_frame_cc(int_4 frame) {
    frame_d = frame;
    return ISIP_TRUE;
  }

  int_4 get_frame_cc() {
    return frame_d;
  }
  
  logical_1 active_cc(int_4 frame, int_4 diff);
  
  // reset parameters
  //
  logical_1 clear_cc();
  logical_1 prune_cc(logical_1 flag, int_4& ndel);
  logical_1 prune_cc(float_4 beam, logical_1 flag, int_4& ndel);

  //---------------------------------------------------------------------------
  //
  // private methods
  //
  //---------------------------------------------------------------------------
private:

};

// end of file
// 
#endif
