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

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

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

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

#ifndef __ISIP_LINK_LIST
#include <link_list.h>
#endif

// History: a class that is used as the path history for a
// trace-projection decoder
//
class History {
  
  //---------------------------------------------------------------------------
  //
  // protected data
  //
  //---------------------------------------------------------------------------
protected:
  
  // position in the linguistic search space ---
  //  a lattice node (lattice rescoring and verification)
  // or unigram node (ngram decoding and lattice generation) to represent
  // the current word and the N-2 prev Words if any
  // 
  void_p* histwords_d;
  logical_1 type_d;
  
  // path history information
  //
  Link_list* prev_d;           // pointers to the prev histories in path
  float_4* prevsc_d;           // array of path scores for these histories
  int_4 hist_num_d;            // size of the previous history list
  
  // level in the search network hierarchy
  //
  int_4 level_d;

  // the length of the history 
  //
  static int_4 hist_len_d;
  
  // pointer to the current triphone and state
  //
  int_4 phone_index_d;
  int_4 state_index_d;

  // reference count needed to keep track of all paths passing through
  // this node --- when it falls to zero, this history node can be
  // returned to memory
  //
  int_4 ref_count_d;           // reference count
			       
  // path information	       
  //			       
  int_4 frame_index_d;         // frame this history node was created
  float_4 score_d;             // path probability at this trace

  //---------------------------------------------------------------------------
  //
  // 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
  //
  ~History();  
  History();                                  // default
  History(History& history);                  // copy

  // init methods
  //
  logical_1 clear_cc();
  logical_1 init_cc(void_p* histwords, int_4 level, int_4 phone,
		    int_4 state, int_4 frame, float_4 score);
  
  
  // word history methods
  //
  logical_1 set_histwords_cc(void_p* histwords) {
    histwords_d = histwords;
    return ISIP_TRUE;
  }

  void_p* get_histwords_cc() {
    return histwords_d;
  }
  
  logical_1 set_histwords_cc(void_p histword, int_4 index);
  void_p get_histwords_cc(int_4 index);

  static logical_1 set_hist_len_cc(int_4 length) {
    hist_len_d = length;
    return ISIP_TRUE;
  }

  static int_4 get_hist_len_cc() {
    return hist_len_d;
  }
  
  // history type methods
  //
  logical_1 set_type_cc(logical_1 val) {
    type_d = val;
    return ISIP_TRUE;
  }
  logical_1 get_type_cc() {
    return type_d;
  }
  
  // level methods
  //
  logical_1 set_level_cc(int_4 inst) {
    level_d = inst;
    return ISIP_TRUE;
  }
  
  int_4 get_level_cc() {
    return level_d;
  }

  // phone index methods
  //
  logical_1 set_phone_ind_cc(int_4 phone) {
    phone_index_d = phone;
    return ISIP_TRUE;
  }
  
  int_4 get_phone_ind_cc() {
    return phone_index_d;
  }

  // state index methods
  //
  logical_1 set_state_ind_cc(int_4 state) {
    state_index_d = state;
    return ISIP_TRUE;
  }
  int_4 get_state_ind_cc() {
    return state_index_d;
  }

  // path history size methods
  //
  logical_1 set_hist_num_cc(int_4 size) {
    hist_num_d = size;
    return ISIP_TRUE;
  }
  
  int_4 get_hist_num_cc() {
    return hist_num_d;
  }
  
  logical_1 incr_hist_num_cc() {
    hist_num_d++;
    return ISIP_TRUE;
  }

  // previous history links methods
  //
  logical_1 set_prev_list_cc(Link_list* prev) {
    prev_d = prev;
    return ISIP_TRUE;
  }
  
  Link_list* get_prev_list_cc() {
    return prev_d;
  }
  
  logical_1 set_prev_score_cc(float_4* presc) {
    prevsc_d = presc;
    return ISIP_TRUE;
  }
  
  float_4* get_prev_score_cc() {
    return prevsc_d;
  }

  // adding previous histories
  //
  logical_1 add_prev_cc(History* hist, float_4 pscore, int_4 max_num);
  logical_1 add_score_cc(int_4 idx, float_4 pscore, int_4 max_num);
  logical_1 remove_score_cc(int_4 idx);

  // ref count methods
  //
  logical_1 set_ref_count_cc(int_4 count) {
    ref_count_d = count;
    return ISIP_TRUE;
  }
  
  int_4 get_ref_count_cc() {
    return ref_count_d;
  }
  
  logical_1 decr_ref_count_cc();
  
  logical_1 incr_ref_count_cc() {
    ref_count_d++;
    return ISIP_TRUE;
  }

  // frame index methods
  //
  logical_1 set_frame_ind_cc(int_4 count) {
    frame_index_d = count;
    return ISIP_TRUE;
  }
  
  int_4 get_frame_ind_cc() {
    return frame_index_d;
  }
  
  logical_1 incr_frame_ind_cc() {
    frame_index_d++;
    return ISIP_TRUE;
  }

  // score methods
  //
  logical_1 set_score_cc(float_4 score) {
    score_d = score;
    return ISIP_TRUE;
  }
  
  float_4 get_score_cc() {
    return score_d;
  }
  logical_1 incr_score_cc(float_4 incr);
  
  //---------------------------------------------------------------------------
  //
  // private methods
  //
  //---------------------------------------------------------------------------
private:

};

// end of file
// 
#endif
