📄 digraphdiagnose.h
字号:
// file: $isip/class/dstr/DiGraph/DiGraphDiagnose.h// version: $Id: DiGraphDiagnose.h,v 1.15 2003/04/23 19:39:48 alphonso Exp $//// make sure definitions are only made once//#ifndef ISIP_DI_GRAPH_DIAGNOSE#define ISIP_DI_GRAPH_DIAGNOSE// isip include files//#ifndef ISIP_DI_GRAPH#include "DiGraph.h"#endif#ifndef ISIP_FILENAME#include "Filename.h"#endif// DiGraphDiagnose: a class that contains the diagnose method of DiGraph class.//template<class TObject>class DiGraphDiagnose : public DiGraph<TObject> { //--------------------------------------------------------------------------- // // public constants // //---------------------------------------------------------------------------public: // define the class name // //---------------------------------------- // // i/o related constants // //---------------------------------------- //---------------------------------------- // // default values and arguments // //---------------------------------------- // default values // // default arguments to methods // //---------------------------------------- // // error codes // //---------------------------------------- //--------------------------------------------------------------------------- // // protected data // //---------------------------------------------------------------------------protected: // define the object used to hold graph topology in read and write // typedef Triple< Pair<Long, Long>, Float, Boolean> TopoTriple; //--------------------------------------------------------------------------- // // required public methods // //---------------------------------------------------------------------------public: // methods: name // static const String& name() { return DiGraph<TObject>::name(); } // other static methods // static boolean diagnose(Integral::DEBUG debug_level); // debug methods // these methods are omitted since this class does not have data // members and operations // // destructor/constructor(s): // these methods are omitted since this class does not have data // members and operations // // assign methods: // these methods are omitted since this class does not have data // members and operations // // operator= methods: // these methods are omitted since this class does not have data // members and operations // // i/o methods: // these methods are omitted since this class does not have data // members and operations // // equality methods: // these methods are omitted since this class does not have data // members and operations // // memory-management methods: // these methods are omitted since this class does not have data // members and operations // //--------------------------------------------------------------------------- // // class-specific public methods // //--------------------------------------------------------------------------- // these methods are omitted since this class does not have data // members and operations // //--------------------------------------------------------------------------- // // private methods // //---------------------------------------------------------------------------private:}; // below are all the methods for the PairDiagnose template class////-----------------------------------------------------------------------------//// required static methods////-----------------------------------------------------------------------------// method: diagnose//// arguments:// Integral::DEBUG level: (input) debug level for diagnostics//// return: a boolean value indicating status//template<class TObject>boolean DiGraphDiagnose<TObject>::diagnose(Integral::DEBUG level_a) { //---------------------------------------------------------------------- // // 0. preliminaries // //---------------------------------------------------------------------- // output the class name // if (level_a > Integral::NONE) { SysString output(L"diagnosing class "); output.concat(CLASS_NAME); output.concat(L": "); Console::put(output); Console::increaseIndention(); } //--------------------------------------------------------------------- // // 1. required public methods // //--------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing required public methods...\n"); Console::increaseIndention(); } // test the debug methods // setDebug(debug_level_d); // test constructors and memory management methods // DiGraph<Char> def_graph; // create an arc from the first to the last node // def_graph.insertArc(def_graph.getStart(), def_graph.getTerm(), false, 0.75); // copy constructor // DiGraph<Char> copy_graph(def_graph); // the copy graph should now have an arc from its start node to its terminal // node with a weight of 0.75 // GraphArc<Char>* cstr_arc = (GraphArc<Char>*)NULL; if ((cstr_arc = copy_graph.getStart()->getFirst()) == (GraphArc<Char>*)NULL) { return Error::handle(name(), L"constructors", Error::TEST, __FILE__, __LINE__); } if ((cstr_arc->getVertex() != copy_graph.getTerm()) || cstr_arc->getEpsilon() || !Integral::almostEqual((double)cstr_arc->getWeight(), 0.75)) { return Error::handle(name(), L"constructors", Error::TEST, __FILE__, __LINE__); } // check the constructors and destructors for allocating on the dynamic // memory heap // DiGraph<Char>* def_dyn_graph = new DiGraph<Char>; // create an arc from the first to the last node // def_dyn_graph->insertArc(def_dyn_graph->getStart(), def_dyn_graph->getTerm(), false, 0.75); // copy constructor // DiGraph<Char>* copy_dyn_graph = new DiGraph<Char>(*def_dyn_graph); // the copy graph should now have an arc from its start node to its terminal // node with a weight of 0.75 // cstr_arc = (GraphArc<Char>*)NULL; if ((cstr_arc = copy_dyn_graph->getStart()->getFirst()) == (GraphArc<Char>*)NULL) { return Error::handle(name(), L"constructors", Error::TEST, __FILE__, __LINE__); } if ((cstr_arc->getVertex() != copy_dyn_graph->getTerm()) || cstr_arc->getEpsilon() || !Integral::almostEqual((double)cstr_arc->getWeight(), 0.75)) { return Error::handle(name(), L"constructors", Error::TEST, __FILE__, __LINE__); } // clear the respective graphs // ((DiGraph<TObject>)copy_graph).clear(Integral::FREE); def_dyn_graph->clear(Integral::FREE); def_graph.clear(Integral::FREE); copy_dyn_graph->clear(Integral::FREE); // see if we can dynamically delete // delete def_dyn_graph; delete copy_dyn_graph; { // test constructors and memory management methods in USER-allocation // DiGraph<Char> def_graph(USER); // create an arc from the first to the last node // def_graph.insertArc(def_graph.getStart(), def_graph.getTerm(), false, 0.75); // copy constructor // DiGraph<Char> copy_graph(def_graph); // the copy graph should now have an arc from its start node to its // terminal node with a weight of 0.75 // GraphArc<Char>* cstr_arc = (GraphArc<Char>*)NULL; if ((cstr_arc = copy_graph.getStart()->getFirst()) == (GraphArc<Char>*)NULL) { return Error::handle(name(), L"constructors", Error::TEST, __FILE__, __LINE__); } if ((cstr_arc->getVertex() != copy_graph.getTerm()) || cstr_arc->getEpsilon() || !Integral::almostEqual((double)cstr_arc->getWeight(), 0.75)) { return Error::handle(name(), L"constructors", Error::TEST, __FILE__, __LINE__); } // check the constructors and destructors for allocating on the dynamic // memory heap in USER-allocation mode // DiGraph<Char>* def_dyn_graph = new DiGraph<Char>(USER); // create an arc from the first to the last node // def_dyn_graph->insertArc(def_dyn_graph->getStart(), def_dyn_graph->getTerm(), false, 0.75); // copy constructor // DiGraph<Char>* copy_dyn_graph = new DiGraph<Char>(*def_dyn_graph); // the copy graph should now have an arc from its start node to its // terminal node with a weight of 0.75 // cstr_arc = (GraphArc<Char>*)NULL; if ((cstr_arc = copy_dyn_graph->getStart()->getFirst()) == (GraphArc<Char>*)NULL) { return Error::handle(name(), L"constructors", Error::TEST, __FILE__, __LINE__); } if ((cstr_arc->getVertex() != copy_dyn_graph->getTerm()) || cstr_arc->getEpsilon() || !Integral::almostEqual((double)cstr_arc->getWeight(), 0.75)) { return Error::handle(name(), L"constructors", Error::TEST, __FILE__, __LINE__); } // clear the respective graphs // copy_graph.clear(Integral::FREE); def_dyn_graph->clear(Integral::FREE); def_graph.clear(Integral::FREE); copy_dyn_graph->clear(Integral::FREE); // see if we can dynamically delete // delete def_dyn_graph; delete copy_dyn_graph; } // test large allocation construction and deletion in both modes // if (level_a >= Integral::ALL) { // output an informative message // Console::put(L"\ntesting large chunk memory allocation and deletion:\n"); // set the memory to a strange block size so we can hopefully catch any // frame overrun errors // DiGraph<TObject>::setGrowSize((long)731); // loop for a large number of times creating and deleting a large number // of vertices at each loop // for (long j = 1; j <= 100; j++) { DiGraph<TObject>** self_graphs = new DiGraph<TObject>*[j * 50]; DiGraph<TObject>** graphs = new DiGraph<TObject>*[j * 50]; // create the vertices // for (long i = 0; i < j * 50; i++) { self_graphs[i] = new DiGraph<TObject>(); graphs[i] = new DiGraph<TObject>(USER); } // delete nodes // for (long i = (j * 50) - 1; i >= 0; i--) { delete self_graphs[i]; delete graphs[i]; } delete [] self_graphs; delete [] graphs; } // perform the same test using the new[] and delete [] operators // for (long j = 1; j <= 100; j++) { // allocate a large number of nodes // DiGraph<TObject>* self_graphs = new DiGraph<TObject>[j * 50]; DiGraph<TObject>* graphs = new DiGraph<TObject>[j * 50](USER); // clean up memory // delete [] self_graphs; delete [] graphs; } } // test assign method in SYSTEM-allocation mode // DiGraph<Char> assn_graph_0; // create an arc from the first to a common node // Char* char1 = new Char('k'); assn_graph_0.insertArc(assn_graph_0.getStart(), assn_graph_0.insertVertex(char1), false, 0.75); GraphVertex<Char>* tmp_vertex; if ((tmp_vertex = (GraphVertex<Char>*)assn_graph_0.getFirst()) == (GraphVertex<Char>*)NULL) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } assn_graph_0.insertArc(tmp_vertex, assn_graph_0.getTerm(), false, -0.75); DiGraph<Char> assn_graph_1; assn_graph_1.assign(assn_graph_0); // the assigned graph should now have an arc from its start node to the // char1 with a weight of 0.75 and an arc from the char1 to the terminal // node with a weight of -0.75 // cstr_arc = (GraphArc<Char>*)NULL; if ((cstr_arc = assn_graph_1.getStart()->getFirst()) == (GraphArc<Char>*)NULL) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } if ((cstr_arc->getVertex()->getItem()->ne(*char1)) || cstr_arc->getEpsilon() || !Integral::almostEqual((double)cstr_arc->getWeight(), 0.75)) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } if ((cstr_arc = cstr_arc->getVertex()->getFirst()) == (GraphArc<Char>*)NULL) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } if ((cstr_arc->getVertex() != assn_graph_1.getTerm()) || cstr_arc->getEpsilon() || !Integral::almostEqual((double)cstr_arc->getWeight(), -0.75)) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } // clean up memory // delete char1; { // test assign method in USER-allocation mode // DiGraph<Char> assn_graph_0(USER); // create an arc from the first to a common node // Char* char1 = new Char('k'); assn_graph_0.insertArc(assn_graph_0.getStart(), assn_graph_0.insertVertex(char1), false, 0.75); GraphVertex<Char>* tmp_vertex;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -