// file: $isip/class/pr/PhoneticDecisionTreeNode/PhoneticDecisionTreeNode.h
// version: $Id: PhoneticDecisionTreeNode.h 9263 2003-07-08 13:50:41Z alphonso $
//

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

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

#ifndef ISIP_TRIPLE
#include <Triple.h>
#endif

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

#ifndef ISIP_BOOLEAN
#include <Boolean.h>
#endif

#ifndef ISIP_STATISTICAL_MODEL
#include <StatisticalModel.h>
#endif

#ifndef ISIP_HASH_TABLE
#include <HashTable.h>
#endif

#ifndef ISIP_STRING
#include <String.h>
#endif

// PhoneticDecisionTreeNode: A class to store phonetic information for
// each statistical-model
//
class PhoneticDecisionTreeNode {

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

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

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

  static const String DEF_PARAM;
  static const String PARAM_DATAPOINTS;
  static const String PARAM_BEST_ATTRIBUTE;
  static const String PARAM_TYPICAL_INDEX;
  static const String PARAM_ACTUAL_INDEX;
  static const String PARAM_TYPICAL_STAT_MODEL;
  static const String PARAM_FLAG_EXISTS;

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

  typedef Triple<Long, StatisticalModel, HashTable<String, String> > DataPoint;
  typedef SingleLinkedList<DataPoint> Data;
  
  //----------------------------------------
  //
  // default values and arguments
  //
  //----------------------------------------  

  // define default values for the typical statistical-model index
  //
  static const long DEF_TYPICAL_INDEX = -1;

  // define default values for the actual statistical-model index
  //
  static const long DEF_ACTUAL_INDEX = -1;

  // define default values for this flag
  //
  static const bool DEF_FLAG_EXISTS = true;

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

  static const long ERR = 00100400;
  
  //---------------------------------------------------------------------------
  //
  // protected data
  //
  //---------------------------------------------------------------------------
protected:
  
  // define the datapoints
  //
  Data datapoints_d;
  
  // define the best attribute that is used to split this node
  //
  String best_attribute_d;
  
  // define the typical statistical-mode index that represents this
  // node. this gets update during merging
  //
  Long typical_index_d;
  
  // define the actual statistical-mode index that represents this node
  //
  Long actual_index_d;
  
  // define the typical statistical-model that represents this node
  //
  StatisticalModel typical_stat_model_d;
  
  // define flag represents if this node exists or it is merged with
  // some other node
  //
  Boolean flag_exists_d;
  
  // define a static debug level
  //
  static Integral::DEBUG debug_level_d;
  
  // define a static 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);

  // method: debug
  //
  boolean debug(const unichar* message) const;

  // method: setDebug
  //
  static boolean setDebug(Integral::DEBUG debug_level) {
    debug_level_d = debug_level;
    return true;
  }
  
  // method: destructor
  //
  ~PhoneticDecisionTreeNode() {

    if (debug_level_d >= Integral::ALL) { 
      String out(L" Destructor of phonetic-decision-tree node: ");
      out.concat(this);
      out.concat("\n");
      Console::put(out);
    }
  }

  // constructor(s)
  //
  PhoneticDecisionTreeNode();
  PhoneticDecisionTreeNode(const PhoneticDecisionTreeNode& copy_node);
  
  // assign methods
  //
  boolean assign(const PhoneticDecisionTreeNode& copy_node);

  // method: sofSize
  //
  long sofSize() const;
  
  // 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;

  // equality method
  //
  boolean eq(const PhoneticDecisionTreeNode& compare_node) const;
  
  // 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 methods
  //
  boolean clear(Integral::CMODE ctype = Integral::DEF_CMODE);

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

  // method: setDataPoints
  //
  boolean setDataPoints(Data& arg) {
    datapoints_d = arg;
    return true;
  }

  // method: getDataPoints
  //
  Data& getDataPoints() const {
    return const_cast<Data &>(datapoints_d);
  }

  // method: setBestAttribute
  //
  boolean setBestAttribute(String& arg) {
    best_attribute_d = arg;
    return true;
  }

  // method: getBestAttribute
  //
  String& getBestAttribute() const {
    return const_cast<String &>(best_attribute_d);
  }

  // method: setTypicalIndex
  //
  boolean setTypicalIndex(Long arg) {
    typical_index_d = arg;
    return true;
  }

  // method: getTypicalIndex
  //
  Long getTypicalIndex() const {
    return typical_index_d;
  }

  // method: setActualIndex
  //
  boolean setActualIndex(Long arg) {
    actual_index_d = arg;
    return true;
  }

  // method: getActualIndex
  //
  Long getActualIndex() const {
    return actual_index_d;
  }

  // method: setTypicalStatModel
  //
  boolean setTypicalStatModel(StatisticalModel& arg) {
    typical_stat_model_d = arg;
    return true;
  }

  // method: getTypicalStatModel
  //
  StatisticalModel& getTypicalStatModel() const {
    return const_cast<StatisticalModel &>(typical_stat_model_d);
  }

  // method: setFlagExists
  //
  boolean setFlagExists(Boolean arg) {
    flag_exists_d = arg;
    return true;
  }

  // method: getFlagExists
  //
  Boolean getFlagExists() const {
    return flag_exists_d;
  }

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

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

};

// end of include file
//
#endif
