// file: $isip/class/dstr/GraphArc/GraphArc.h // version: $Id: GraphArc.h 9329 2003-10-29 20:40:03Z alphonso $ // // make sure definitions are only made once // #ifndef ISIP_GRAPH_ARC #define ISIP_GRAPH_ARC // isip include files // #ifndef ISIP_BOOLEAN #include #endif #ifndef ISIP_FLOAT #include #endif #ifndef ISIP_CONSOLE #include #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 GraphArcDiagnose; template class GraphVertex; #ifndef ISIP_GRAPH_VERTEX #include #endif // GraphArc: a generic arc in a graph. the main purpose of an arc is // to connect two graph vertices. // template 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 float32 DEF_WEIGHT = 0.0; static const float64 DEF_OPTIONAL_WEIGHT = 0.0; static const bool8 DEF_EPSILON = false; //---------------------------------------- // // error codes // //---------------------------------------- static const int32 ERR = 41000; //--------------------------------------------------------------------------- // // protected data // //--------------------------------------------------------------------------- protected: // vertex we are pointing to // GraphVertex* vertex_d; // weight for the edge // Float weight_d; // alternative weight 1 // Double weight1_d; // alternative weight 2 // Double weight2_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 bool8 setDebug(Integral::DEBUG level) { debug_level_d = level; return true; } // other debug methods // bool8 debug(const unichar* message) const; // method: destructor // ~GraphArc() { clear(Integral::RESET); } // default constructor // GraphArc(GraphVertex* = (GraphVertex*)NULL, float32 weight = DEF_WEIGHT, bool8 is_epsilon = DEF_EPSILON); // copy constructor // GraphArc(const GraphArc& copy_arc); // method: assign // bool8 assign(const GraphArc& copy_arc) { return (setVertex(copy_arc.vertex_d) && setWeight(copy_arc.weight_d) && setEpsilon(copy_arc.is_epsilon_d)); } // method: operator= // GraphArc& operator=(const GraphArc& arg) { assign(arg); return *this; } // method: eq // determines if the endpoint, weights and epsilon settings of the // respective arcs are equivalent. // bool8 eq(const GraphArc& 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 bool8 setGrowSize(int32 grow_size) { return (mgr_d.setGrow(grow_size)); } // other memory management methods: // bool8 clear(Integral::CMODE cmode = Integral::DEF_CMODE); //--------------------------------------------------------------------------- // // class-specific public methods: // vertex get and set methods // //--------------------------------------------------------------------------- // method: getVertex // GraphVertex* getVertex() const { return vertex_d; } // method: setVertex // bool8 setVertex(GraphVertex* dest) { vertex_d = dest; return true; } //--------------------------------------------------------------------------- // // class-specific public methods: // get and set methods // //--------------------------------------------------------------------------- // method: getWeight // float32 getWeight() const { return (float32)weight_d; } // method: setWeight // bool8 setWeight(const float32 weight) { weight_d = weight; return true; } // method: getAccumulator // float64 getAccumulator() const { return (float64)weight1_d; } // method: setAccumulator // bool8 setAccumulator(const float64 weight) { weight1_d = weight; return true; } // method: getLanguageWeight // float64 getLanguageWeight() const { return (float64)weight1_d; } // method: setLanguageWeight // bool8 setLanguageWeight(const float64 weight) { weight1_d = weight; return true; } // method: getAcousticWeight // float64 getAcousticWeight() const { return (float64)weight2_d; } // method: setAcousticWeight // bool8 setAcousticWeight(const float64 weight) { weight2_d = weight; return true; } //--------------------------------------------------------------------------- // // class-specific public methods: // arc epsilon get and set methods // //--------------------------------------------------------------------------- // method: getEpsilon // bool8 getEpsilon() const { return (bool8)is_epsilon_d; } // method: setEpsilon // bool8 setEpsilon(bool8 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? // bool8 containsData() const { return ((is_epsilon_d != DEF_EPSILON) || (vertex_d->getParentGraph()->isWeighted())); } //--------------------------------------------------------------------------- // // private methods // //--------------------------------------------------------------------------- private: // friend class // template 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 const String GraphArc::CLASS_NAME(L"GraphArc"); template const String GraphArc::DEF_PARAM(L"arc"); // static instantiations: debug level and memory manager // template Integral::DEBUG GraphArc::debug_level_d = Integral::NONE; template MemoryManager GraphArc::mgr_d(sizeof(GraphArc), 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 const String& GraphArc::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 bool8 value indicating status // // this method dumps the contents of an object to the console // template bool8 GraphArc::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* vertex: (input) the endpoint vertex // float32 weight: (input) the arc weight // bool8 is_epsilon: (input) is this arc an epsilon transition // // return: none // // this is the default constructor for the GraphArc class // template GraphArc::GraphArc(GraphVertex* vertex_a, float32 weight_a, bool8 is_epsilon_a) { // initialize data // vertex_d = (GraphVertex*)NULL; weight_d = DEF_WEIGHT; is_epsilon_d = DEF_EPSILON; weight1_d = DEF_OPTIONAL_WEIGHT; weight2_d = DEF_OPTIONAL_WEIGHT; // set the class data // setVertex(vertex_a); setWeight(weight_a); setEpsilon(is_epsilon_a); // exit gracefully // } // method: copy constructor // // arguments: // const GraphArc& copy_arc: (input) the arc to copy // // return: none // // this is the copy constructor for the GraphArc class // template GraphArc::GraphArc(const GraphArc& copy_arc_a) { // initialize data // vertex_d = (GraphVertex*)NULL; weight_d = DEF_WEIGHT; is_epsilon_d = DEF_EPSILON; weight1_d = DEF_OPTIONAL_WEIGHT; weight2_d = DEF_OPTIONAL_WEIGHT; // 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 bool8 value indicating status // // this method clears the reference to the internal data. // template bool8 GraphArc::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*)NULL; } // exit gracefully // return true; } // end of include file // #endif