// file: $isip/class/pr/LanguageModelIHD/LanguageModelIHD.h
//

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

#ifndef ISIP_LANGUAGE_MODEL_BASE
#include <LanguageModelBase.h>
#endif

// forward class definitions
//

// LanguageModelIHD: Used for language models in IHD format.  IHD is the
// standard ISIP compiled language model format.  
//
class LanguageModelIHD : public LanguageModelBase {

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

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

  //--------------------------------------------------------------
  //
  // other important constants
  //
  //--------------------------------------------------------------

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

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

  static const long ERR = 100102;
  
  //---------------------------------------------------------------------------
  //
  // protected data
  //
  //---------------------------------------------------------------------------
protected:

  // debug level
  //
  // debug_level_d inherited from LanguageModelBase
  
  // hierarchical digraph
  //
  HierarchicalDigraph hg_d;
  
  // memory manager
  //
  static MemoryManager mgr_d;

  //---------------------------------------------------------------------------
  //
  // required public methods
  //
  //---------------------------------------------------------------------------
public:

  // method: name
  //
  static const String& name() {
    return CLASS_NAME;
  }

  // method: diagnose
  //
  static boolean diagnose(Integral::DEBUG debug_level);
  
  // debug methods
  //
  boolean debug(const unichar* msg) const {
    return hg_d.debug(L"hg_d");
  }

  // method: setDebug
  //
  // inherited from LanguageModelBase
  
  // method: destructor
  //
  ~LanguageModelIHD() { }

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

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

  // assign methods
  //
  boolean assign(const LanguageModelIHD& arg) {
    return hg_d.assign(arg.hg_d);
  }


  // i/o methods
  //
  // method: sofSize
  //
  long sofSize() const {
    return hg_d.sofSize();
  }

  // method: read
  //
  boolean read(Sof& sof, long tag, const String& cname = CLASS_NAME);

  // method: write
  //
  boolean write(Sof& sof, long tag, const String& cname = CLASS_NAME) const;


  // method: readData
  //
  boolean readData(Sof& sof, const String& pname = DEF_PARAM,
		   long size = SofParser::FULL_OBJECT,
		   boolean param = true, boolean nested = false);

  // method: writeData
  //
  boolean writeData(Sof& sof, const String& pname = DEF_PARAM) const;

  // other memory managements methods
  //
  boolean clear(Integral::CMODE cmode = Integral::DEF_CMODE) {
    return hg_d.clear();
  }
      
  // equality methods
  //
  boolean eq(const LanguageModelIHD& arg) const {
    return hg_d.eq(arg.hg_d);
  }

  //---------------------------------------------------------------------------
  //
  // class-specific public methods required by interface contract
  // defined in LanguageModelBase.h
  //
  //---------------------------------------------------------------------------

  // LanguageModelBase required methods
  //
  boolean assign(const LanguageModelBase& arg);
  boolean eq(const LanguageModelBase& arg) const;
  
  //--------------------------------------------------------
  //
  // load and store methods
  //
  //--------------------------------------------------------

  //--------------------------------------------------------
  //
  // other methods
  //
  //--------------------------------------------------------  

  // method: className
  //
  const String& className() const {
    return CLASS_NAME;
  }
  
  // method: getRuleModel
  //
  RuleModel getRuleModel();
  
  // method: setRuleModel
  //
  boolean setRuleModel(const RuleModel& rm);
  
  // method: getHDigraph
  //
  HierarchicalDigraph& getIHD() {
    return hg_d;
  }
  
  // method: setHDigraph
  //
  boolean setIHD(const HierarchicalDigraph& hg) {
    return hg_d.assign(hg);
  }
  
  //---------------------------------------------------------------------------
  //
  // private methods
  //
  //---------------------------------------------------------------------------
private:  
  
  // method: isEpsilon
  //
  boolean isEpsilon(Vector<ProductionRule> rules, String rule_name);

  // method: findTerminals
  //
  Vector<Pair<String, SearchSymbol> > findTerminals(Vector<ProductionRule> rules, String rule_name);



};

// end of include file
// 
#endif
