📄 graphvertex.h
字号:
// file: $isip/class/dstr/GraphVertex/GraphVertex.h// version: $Id: GraphVertex.h,v 1.39 2003/03/06 15:57:41 alphonso Exp $//// make sure definitions are only made once//#ifndef ISIP_GRAPH_VERTEX#define ISIP_GRAPH_VERTEX// isip include files//#ifndef ISIP_SINGLE_LINKED_LIST#include <SingleLinkedList.h>#endif#ifndef ISIP_MEMORY_MANAGER#include <MemoryManager.h>#endif#ifndef ISIP_STRING#include <String.h>#endif// forward class definitions:// we must define the Graph class and the GraphArc class here first because// the header files might be short-circuited by the ifndef.//template<class TObject> class DiGraph;template<class TObject> class GraphArc;// GraphVertex: a generic GraphVertex. the main purpose of a vertex is// to hold a list of arcs originating from the given vertex.//template<class TObject>class GraphVertex : public SingleLinkedList<GraphArc<TObject> >, public Node<TObject> { //--------------------------------------------------------------------------- // // 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 // //---------------------------------------- // // error codes // //---------------------------------------- static const long ERR = 41100; static const long ERR_NULLD = 41101; static const long ERR_NOPAR = 41102; //--------------------------------------------------------------------------- // // protected data // //---------------------------------------------------------------------------protected: // what graph does this vertex belong to // DiGraph<TObject>* parent_graph_d; // define the memory manager // static MemoryManager mgr_d; //--------------------------------------------------------------------------- // // required public methods // //---------------------------------------------------------------------------public: // static methods // static const String& name(); // this class doesn't have a diagnose method, its functionality is // tested in Graph::diagnose // // debug methods: // setDebug is inherited from the SingleLinkedList template class // boolean debug(const unichar* message) const; // method: destructor // ~GraphVertex() { removeAllArcs(); } // method: default constructor // GraphVertex() { parent_graph_d = (DiGraph<TObject>*)NULL; SingleLinkedList< GraphArc<TObject> >::setAllocationMode(USER); } // method: copy constructor // GraphVertex(const GraphVertex<TObject>& arg) { parent_graph_d = (DiGraph<TObject>*)NULL; SingleLinkedList< GraphArc<TObject> >::setAllocationMode(USER); assign(arg); } // assign methods // boolean assign(const GraphVertex<TObject>& copy_vertex); // method: operator= // GraphVertex<TObject>& operator=(const GraphVertex<TObject>& arg) { assign(arg); return *this; } // i/o methods: // these methods are not needed since graph takes care of it's own I/O. // // method: eq // determines if the contents of the vertex are equivalent. // adjacency lists & weights are ignored. // boolean eq(const GraphVertex<TObject>& arg) const { return Node<TObject>::eq(arg); } // 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: // parent graph manipulation methods // //--------------------------------------------------------------------------- // method: setParentGraph // boolean setParentGraph(DiGraph<TObject>* parent) { parent_graph_d = parent; return true; } // method: getParentGraph // DiGraph<TObject>* getParentGraph() const { return parent_graph_d; } //--------------------------------------------------------------------------- // // class-specific public methods: // vertex manipulation methods // //--------------------------------------------------------------------------- // insert/remove a vertex to/from the adjacency list: // these methods assume that the user is taking care of updating the // parent graphs, end vertices, etc. // boolean insertArc(GraphVertex<TObject>* vertex, double weight = GraphArc<TObject>::DEF_WEIGHT, boolean is_epsilon = GraphArc<TObject>::DEF_EPSILON); boolean insertArc(GraphVertex<TObject>* vertex, boolean is_epsilon = GraphArc<TObject>::DEF_EPSILON); boolean removeArc(GraphVertex<TObject>* vertex); boolean removeArc(); boolean removeAllArcs(); // is this vertex adjacent? // boolean isAdjacent(GraphVertex<TObject>* vertex) const; // method: isStart // boolean isStart() const { if (parent_graph_d == (DiGraph<TObject>*)NULL) { return Error::handle(name(), L"isStart - undefined parent", Error::ARG, __FILE__, __LINE__); } return (this == parent_graph_d->getStart()); } // method: isTerm // boolean isTerm() const { if (parent_graph_d == (DiGraph<TObject>*)NULL) { return Error::handle(name(), L"isTerm - undefined parent", Error::ARG, __FILE__, __LINE__); } return (this == parent_graph_d->getTerm()); } //--------------------------------------------------------------------------- // // class-specific public methods: // vertex comparison methods // //--------------------------------------------------------------------------- // compares the siblings of the two vertices and arc weights to see if // the two vertices has a similar structure // boolean compareVertices(const GraphVertex<TObject>& compare_vertex_a) const; //--------------------------------------------------------------------------- // // private methods // //---------------------------------------------------------------------------private: // friend class // template <class TObject_diagnose> friend class GraphVertexDiagnose;};// in order to allow graph to reference GraphVertex's constants, it// must be included after the class definition.//#ifndef ISIP_DI_GRAPH#include <DiGraph.h>#endif#ifndef ISIP_GRAPH_ARC#include <GraphArc.h>#endif//-----------------------------------------------------------------------------//// 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 GraphVertex<TObject>::CLASS_NAME(L"GraphVertex");template <class TObject>const String GraphVertex<TObject>::DEF_PARAM(L"vertex");// static instantiations: the memory manager//template <class TObject>MemoryManager GraphVertex<TObject>::mgr_d(sizeof(GraphVertex<TObject>), CLASS_NAME);// below are all the methods for the GraphVertex 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& GraphVertex<TObject>::name() { // create the static name string for this class and return it // static String cname(CLASS_NAME); cname.clear(); 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 GraphVertex<TObject>::debug(const unichar* message_a) const { // build a debug string // String output; String value; output.debugStr(name(), message_a, L""); Console::put(output); Console::increaseIndention(); // dump a pointer to the current vertex // value.assign(this); output.debugStr(name(), message_a, L"this", value); Console::put(output); // dump a pointer to the parent graph // value.assign(parent_graph_d); output.debugStr(name(), message_a, L"parent_graph_d", value); Console::put(output); // dump the internal item if it exists // Node<TObject>::debug(L"item"); // call the parent debug method to debug the list itself // SingleLinkedList< GraphArc<TObject> >::debug(L"arcs"); // that's it for sub-items, decrease indentation // Console::decreaseIndention(); // exit gracefully // return true;}//------------------------------------------------------------------------//// required assign methods////-------------------------------------------------------------------------// method: assign//// arguments:// const GraphVertex<TObject>& arg: (input) the vertex to copy//// return: a boolean value indicating status//// this method copies the contents of the input to this list//template<class TObject>boolean GraphVertex<TObject>::assign(const GraphVertex<TObject>& arg_a) { // it may be necessary to clear this vertex // clear(); // call the parent assign method which handles the arc list elements // SingleLinkedList< GraphArc<TObject> >::assign(arg_a); // call the Node assign method to assign the object // Node<TObject>::assign(arg_a); // set the parent graph // setParentGraph(arg_a.parent_graph_d); // exit gracefully // return true;}//-------------------------------------------------------------------------//// required clear method////-------------------------------------------------------------------------// 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.//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -