📄 bigraphvertex.h
字号:
//template<class TObject>const String& BiGraphVertex<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 BiGraphVertex<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 BiGraph // 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 // parents_d.debug(L"parents arcs"); // call the parent debug method to debug the list itself // children_d.debug(L"children arcs"); // that's it for sub-items, decrease indentation // Console::decreaseIndention(); // exit gracefully // return true;}//------------------------------------------------------------------------//// required assign methods////-------------------------------------------------------------------------// method: assign//// arguments:// const BiGraphVertex<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 BiGraphVertex<TObject>::assign(const BiGraphVertex<TObject>& arg_a) { // it may be necessary to clear this vertex // clear(); // call the parent assign method which handles the arc list elements // children_d.assign(*(const_cast<BiGraphVertex<TObject>& > (arg_a).getChildren())); // call the parent assign method which handles the arc list elements // parents_d.assign(*(const_cast<BiGraphVertex<TObject>& > (arg_a).getParents())); // call the Node assign method to assign the object // Node<TObject>::assign(arg_a); // set the parent BiGraph // 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.// template<class TObject>boolean BiGraphVertex<TObject>::clear(Integral::CMODE cmode_a) { // switch on cmode // if (cmode_a == Integral::RETAIN) { if (item_d != (TObject*)NULL) { item_d->clear(cmode_a); } } else if ((cmode_a == Integral::RESET) || (cmode_a == Integral::RELEASE)) { // clear the references to the data // item_d = (TObject*)NULL; // clear the reference to the parent BiGraph // parent_graph_d = (BiGraph<TObject>*)NULL; } else { // deallocate the allocated memory if necessary // if (item_d != (TObject*)NULL) { item_d->clear(Integral::FREE); delete item_d; item_d = (TObject*)NULL; } // clear the reference to the parent BiGraph // parent_graph_d = (BiGraph<TObject>*)NULL; } // clear the arc list // boolean return_val = removeAllArcsChild(); return_val &= removeAllArcsParent(); // exit gracefully // return return_val;}//---------------------------------------------------------------------------//// class-specific public methods:// vertex manipulation methods////--------------------------------------------------------------------------- // method: insertArcChild//// arguments:// BiGraphVertex<TObject>* vertex: (input) the vertex to connect to// double weight: (input) the weight on the generated arc// boolean is_epsilon: (input) is this an epsilon transition?//// return: a boolean value indicating status//// this method inserts a weighted arc connecting this vertex to the input// vertex.//template<class TObject>boolean BiGraphVertex<TObject>::insertArcChild(BiGraphVertex<TObject>* vertex_a, double weight_a, boolean is_epsilon_a) { // check that the input vertex is not null // if (vertex_a == (BiGraphVertex<TObject>*)NULL) { return Error::handle(name(), L"insertArcChild", Error::ARG, __FILE__, __LINE__); } // create a new Arc // BiGraphArc<TObject>* new_arc = new BiGraphArc<TObject>(vertex_a, weight_a); new_arc->setEpsilon(is_epsilon_a); // insert the arc to the list // insertChild(new_arc); // exit gracefully // return true;}// method: insertArcParent//// arguments:// BiGraphVertex<TObject>* vertex: (input) the vertex to connect to// double weight: (input) the weight on the generated arc// boolean is_epsilon: (input) is this an epsilon transition?//// return: a boolean value indicating status//// this method inserts a weighted arc connecting this vertex to the input// vertex.//template<class TObject>boolean BiGraphVertex<TObject>::insertArcParent(BiGraphVertex<TObject>* vertex_a, double weight_a, boolean is_epsilon_a) { // check that the input vertex is not null // if (vertex_a == (BiGraphVertex<TObject>*)NULL) { return Error::handle(name(), L"insertArcParent", Error::ARG, __FILE__, __LINE__); } // create a new Arc // BiGraphArc<TObject>* new_arc = new BiGraphArc<TObject>(vertex_a, weight_a); new_arc->setEpsilon(is_epsilon_a); // insert the arc to the list // insertParent(new_arc); // exit gracefully // return true;}// method: insertArcChild//// arguments:// BiGraphVertex<TObject>* vertex: (input) the vertex to connect to// boolean is_epsilon: (input) is this an epsilon transition?//// return: a boolean value indicating status//// this method inserts an arc connecting this vertex to the input// vertex.//template<class TObject>boolean BiGraphVertex<TObject>::insertArcChild(BiGraphVertex<TObject>* vertex_a, boolean is_epsilon_a) { // check that the input vertex is not null // if (vertex_a == (BiGraphVertex<TObject>*)NULL) { return Error::handle(name(), L"insertArcChild", Error::ARG, __FILE__, __LINE__); } // create a new Arc // BiGraphArc<TObject>* new_arc = new BiGraphArc<TObject>(vertex_a); new_arc->setEpsilon(is_epsilon_a); // insert the arc to the list // insertChild(new_arc); // exit gracefully // return true;}// method: insertArcParent//// arguments:// BiGraphVertex<TObject>* vertex: (input) the vertex to connect to// boolean is_epsilon: (input) is this an epsilon transition?//// return: a boolean value indicating status//// this method inserts an arc connecting this vertex to the input// vertex.//template<class TObject>boolean BiGraphVertex<TObject>::insertArcParent(BiGraphVertex<TObject>* vertex_a, boolean is_epsilon_a) { // check that the input vertex is not null // if (vertex_a == (BiGraphVertex<TObject>*)NULL) { return Error::handle(name(), L"insertArcParent", Error::ARG, __FILE__, __LINE__); } // create a new Arc // BiGraphArc<TObject>* new_arc = new BiGraphArc<TObject>(vertex_a); new_arc->setEpsilon(is_epsilon_a); // insert the arc to the list // insertParent(new_arc); // exit gracefully // return true;}// method: removeArcChild//// arguments:// BiGraphVertex<TObject>* vertex: (input) the vertex to unlink from//// return: a boolean value indicating status//// this method unlinks this vertex from the input vertex. if the BiGraph is// not directed, then an arc from the input vertex is removed as well//template<class TObject>boolean BiGraphVertex<TObject>::removeArcChild(BiGraphVertex<TObject>* vertex_a) { // make sure the list is not empty // if (this->isEmptyChild()) { return false; } // save the current state // this->setMarkChild(); // find the input vertex in the adjacency list by looping over all arcs // BiGraphArc<TObject>* tmp_item = (BiGraphArc<TObject>*)NULL; if (this->gotoFirstChild()) { tmp_item = this->getCurrChild(); } // declare temporary objects // BiGraphVertex<TObject>* tmp_vert = (BiGraphVertex<TObject>*) NULL; // loop over each element and look for the input vertex // boolean vertex_found = false; while ((tmp_item != (BiGraphArc<TObject>*)NULL) && !vertex_found) { // get the vertex out of the arc // tmp_vert = tmp_item->getVertex(); // check to see if the found vertex is the one we are looking for // if (tmp_vert == vertex_a) { vertex_found = true; } else { if (this->gotoNextChild()) { tmp_item = this->getCurrChild(); } else { tmp_item = (BiGraphArc<TObject>*)NULL; } } } // if we found the vertex then break the arcs, else return an error. // if (vertex_found) { // if the found vertex was at the current node position then remove the // node // if (this->getMarkChild() == tmp_item) { // remove the arc from the graph // boolean status = false; BiGraphArc<TObject>* graph_arc; status = removeChild(graph_arc); delete graph_arc; if (!status) { return false; } } else { // remove the node // boolean status = false; BiGraphArc<TObject>* graph_arc; status = removeChild(graph_arc); delete graph_arc; if (!status) { return false; } } } else { return false; } // restore the saved state // this->gotoMarkChild(); // exit gracefully // return true;}// method: removeArcParent//// arguments:// BiGraphVertex<TObject>* vertex: (input) the vertex to unlink from//// return: a boolean value indicating status//// this method unlinks this vertex from the input vertex. if the BiGraph is// not directed, then an arc from the input vertex is removed as well//template<class TObject>boolean BiGraphVertex<TObject>::removeArcParent(BiGraphVertex<TObject>* vertex_a) { // make sure the list is not empty // if (this->isEmptyParent()) { return false; } // save the current state // this->setMarkParent(); // find the input vertex in the adjacency list by looping over all arcs // BiGraphArc<TObject>* tmp_item = (BiGraphArc<TObject>*)NULL; if (this->gotoFirstParent()) { tmp_item = this->getCurrParent(); } // declare temporary objects // BiGraphVertex<TObject>* tmp_vert = (BiGraphVertex<TObject>*) NULL; // loop over each element and look for the input vertex // boolean vertex_found = false; while ((tmp_item != (BiGraphArc<TObject>*)NULL) && !vertex_found) { // get the vertex out of the arc // tmp_vert = tmp_item->getVertex(); // check to see if the found vertex is the one we are looking for // if (tmp_vert == vertex_a) { vertex_found = true; } else { if (this->gotoNextParent()) { tmp_item = this->getCurrParent(); } else { tmp_item = (BiGraphArc<TObject>*)NULL; } } } // if we found the vertex then break the arcs, else return an error.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -