⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 grapharc.h

📁 这是一个从音频信号里提取特征参量的程序
💻 H
字号:
// file: $isip/class/dstr/GraphArc/GraphArc.h// version: $Id: GraphArc.h,v 1.31 2003/03/28 19:21:34 alphonso Exp $//// make sure definitions are only made once//#ifndef ISIP_GRAPH_ARC#define ISIP_GRAPH_ARC// isip include files//#ifndef ISIP_BOOLEAN#include <Boolean.h>#endif#ifndef ISIP_FLOAT#include <Float.h>#endif#ifndef ISIP_CONSOLE#include <Console.h>#endif// forward class definitions://  we must define the GraphVertex class here first because the header files//  might be short-circuited by the ifndef.//template<class TObject> class GraphArcDiagnose;template<class TObject> class GraphVertex;#ifndef ISIP_GRAPH_VERTEX#include <GraphVertex.h>#endif// GraphArc: a generic arc in a graph. the main purpose of an arc is// to connect two graph vertices.//template<class TObject>class GraphArc {  //---------------------------------------------------------------------------  //  // 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  //    // default arguments to methods  //  static const double DEF_ACCUMULATOR = 0.0;    static const float DEF_WEIGHT = 0.0;  static const boolean DEF_EPSILON = false;    //----------------------------------------  //  // error codes  //  //----------------------------------------      static const long ERR = 41000;    //---------------------------------------------------------------------------  //  // protected data  //  //---------------------------------------------------------------------------protected:  // vertex we are pointing to  //  GraphVertex<TObject>* vertex_d;    // weight for the edge  //  Float weight_d;  // accumulator for the edge  //  Double accumulator_d;      // is this an epsilon transition  //  Boolean is_epsilon_d;    // declare a static debug level for all class instantiations  //  static Integral::DEBUG debug_level_d;  // define the memory manager  //  static MemoryManager mgr_d;    //---------------------------------------------------------------------------  //  // required public methods  //  //---------------------------------------------------------------------------public:  // static methods:  //  diagnose method is moved outside the class header file and  //  defined in the GraphArcDiagnose.h in order to avoid issues  //  with preprocessing of the diagnose code.  //  static const String& name();  // method: setDebug  //  static boolean setDebug(Integral::DEBUG level) {    debug_level_d = level;    return true;  }  // other debug methods  //  boolean debug(const unichar* message) const;      // method: destructor  //  ~GraphArc() {    clear(Integral::RESET);  }    // default constructor  //  GraphArc(GraphVertex<TObject>* = (GraphVertex<TObject>*)NULL,	   float weight = DEF_WEIGHT, boolean is_epsilon = DEF_EPSILON);  // copy constructor  //    GraphArc(const GraphArc<TObject>& copy_arc);    // method: assign  //  boolean assign(const GraphArc<TObject>& copy_arc) {    return (setVertex(copy_arc.vertex_d) &&	    setWeight(copy_arc.weight_d) &&	    setEpsilon(copy_arc.is_epsilon_d));  }  // method: operator=  //  GraphArc<TObject>& operator=(const GraphArc<TObject>& arg) {    assign(arg);    return *this;  }  // method: eq  //  determines if the endpoint, weights and epsilon settings of the  //  respective arcs are equivalent.  //  boolean eq(const GraphArc<TObject>& compare_arc) const {    return ((vertex_d->eq(*compare_arc.vertex_d)) &&	    (weight_d.almostEqual(compare_arc.weight_d)) &&	    (is_epsilon_d.eq(compare_arc.is_epsilon_d)));  }  // i/o methods:  //  these methods are not needed since graph takes care of it's own i/o.  //  // method: new  //  void* operator new(size_t size) {    return mgr_d.get();  }  // method: new[]  //  void* operator new[](size_t size) {    return mgr_d.getBlock(size);  }  // method: delete  //  void operator delete(void* ptr) {    mgr_d.release(ptr);  }  // method: delete[]  //  void operator delete[](void* ptr) {    mgr_d.releaseBlock(ptr);  }  // method: setGrowSize  //    static boolean setGrowSize(long grow_size) {    return (mgr_d.setGrow(grow_size));  }  // other memory management methods:  //    boolean clear(Integral::CMODE cmode = Integral::DEF_CMODE);  //---------------------------------------------------------------------------  //  // class-specific public methods:  //  vertex get and set methods  //  //---------------------------------------------------------------------------  // method: getVertex  //  GraphVertex<TObject>* getVertex() const {    return vertex_d;  }    // method: setVertex  //  boolean setVertex(GraphVertex<TObject>* dest) {    vertex_d = dest;    return true;  }  //---------------------------------------------------------------------------  //  // class-specific public methods:  //  get and set methods  //  //---------------------------------------------------------------------------  // method: getWeight  //  float getWeight() const {    return (float)weight_d;  }    // method: setWeight  //  boolean setWeight(float weight) {    weight_d = weight;    return true;  }  // method: getAccumulator  //  double getAccumulator() const {    return (double)accumulator_d;  }    // method: setAccumulator  //  boolean setAccumulator(double accumulator) {    accumulator_d = accumulator;    return true;  }    //---------------------------------------------------------------------------  //  // class-specific public methods:  //  arc epsilon get and set methods  //  //---------------------------------------------------------------------------  // method: getEpsilon  //  boolean getEpsilon() const {    return (boolean)is_epsilon_d;  }    // method: setEpsilon  //  boolean setEpsilon(boolean is_epsilon = DEF_EPSILON) {    is_epsilon_d = is_epsilon;    return true;  }  // method: containsData  //  does this arc have any information that needs to be written to a file?  //  boolean containsData() const {    return ((is_epsilon_d != DEF_EPSILON) ||	    (vertex_d->getParentGraph()->isWeighted()));  }  //---------------------------------------------------------------------------  //  // private methods  //  //---------------------------------------------------------------------------private:  // friend class  //  template <class TObject_diagnose>   friend class GraphArcDiagnose;};//-----------------------------------------------------------------------------//// we define non-integral constants at the end of class definition for// templates (for non-templates these are defined in the default constructor)//      //-----------------------------------------------------------------------------// constants: required constants such as the class name//template <class TObject>const String GraphArc<TObject>::CLASS_NAME(L"GraphArc");template <class TObject>const String GraphArc<TObject>::DEF_PARAM(L"arc");// static instantiations: debug level and memory manager//template<class TObject>Integral::DEBUG GraphArc<TObject>::debug_level_d = Integral::NONE;template <class TObject>MemoryManager GraphArc<TObject>::mgr_d(sizeof(GraphArc<TObject>), CLASS_NAME);//-----------------------------------------------------------------------------//// below are all the methods for the GraphArc template class//      //-----------------------------------------------------------------------------//----------------------------------------------------------------------//// required static methods////----------------------------------------------------------------------// method: name//// arguments: none//// return: a static String& containing the class name//// this method returns the class name//template<class TObject>const String& GraphArc<TObject>::name() {  // create the static name string for this class and return it  //  static String cname(CLASS_NAME);  cname.clear(Integral::RESET);  cname.concat(CLASS_NAME);  cname.concat(L"<");  cname.concat(TObject::name());  cname.concat(L">");  // return the name  //  return cname;}//----------------------------------------------------------------------//// required debug methods////----------------------------------------------------------------------// method: debug//// arguments://  const unichar* message: (input) information message//// return: a boolean value indicating status//// this method dumps the contents of an object to the console// template<class TObject>boolean GraphArc<TObject>::debug(const unichar* message_a) const {  // declare local variables  //  String output;  String val;    Console::increaseIndention();  // dump the this pointer  //  val.assign(this);  output.debugStr(name(), message_a, L"this", val);  Console::put(output);  // dump the internal item if it exists  //  vertex_d->getItem()->debug(L"item");    // dump a pointer to the destination vertex  //  val.assign(vertex_d);  output.debugStr(name(), message_a, L"vertex_d", val);  Console::put(output);    // dump the weight  //  val.assign(weight_d);  output.debugStr(name(), message_a, L"weight_d", val);  Console::put(output);  // dump the epsilon flag  //  val.assign(is_epsilon_d);  output.debugStr(name(), message_a, L"is_epsilon_d", val);  Console::put(output);  Console::decreaseIndention();    // exit gracefully  //   return true;}//------------------------------------------------------------------------//// required destructor/constructor(s)////-----------------------------------------------------------------------// method: default constructor//// arguments://  GraphVertex<TObject>* vertex: (input) the endpoint vertex//  float weight: (input) the arc weight//  boolean is_epsilon: (input) is this arc an epsilon transition//// return: none//// this is the default constructor for the GraphArc class//template<class TObject>GraphArc<TObject>::GraphArc(GraphVertex<TObject>* vertex_a, float weight_a,			    boolean is_epsilon_a) {  // initialize data  //  vertex_d = (GraphVertex<TObject>*)NULL;  weight_d = DEF_WEIGHT;  is_epsilon_d = DEF_EPSILON;  accumulator_d = DEF_ACCUMULATOR;    // set the class data  //  setVertex(vertex_a);  setWeight(weight_a);  setEpsilon(is_epsilon_a);    // exit gracefully  //}// method: copy constructor//// arguments://  const GraphArc<TObject>& copy_arc: (input) the arc to copy//// return: none//// this is the copy constructor for the GraphArc class//template<class TObject>GraphArc<TObject>::GraphArc(const GraphArc<TObject>& copy_arc_a) {  // initialize data  //  vertex_d = (GraphVertex<TObject>*)NULL;  weight_d = DEF_WEIGHT;  is_epsilon_d = DEF_EPSILON;  accumulator_d = DEF_ACCUMULATOR;    // call the copy assign method  //  assign(copy_arc_a);  // exit gracefully  //}//-------------------------------------------------------------------------////  required clear methods////-------------------------------------------------------------------------// method: clear//// arguments://  Integral::CMODE cmode_a: (input) clear mode//// return: a boolean value indicating status//// this method clears the reference to the internal data.// template<class TObject>boolean GraphArc<TObject>::clear(Integral::CMODE cmode_a) {  // clear the references to the data  //  weight_d = DEF_WEIGHT;  is_epsilon_d = DEF_EPSILON;  if (cmode_a != Integral::RETAIN) {    vertex_d = (GraphVertex<TObject>*)NULL;  }    // exit gracefully  //   return true;}// end of include file//#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -