📄 stackdiagnose.h
字号:
// file: $isip/class/dstr/Stack/StackDiagnose.h// version: $Id: StackDiagnose.h,v 1.13 2000/12/16 22:05:55 duncan Exp $//// make sure definitions are made only once//#ifndef ISIP_STACK_DIAGNOSE#define ISIP_STACK_DIAGNOSE// isip include files//#ifndef ISIP_STACK#include <Stack.h>#endif// StackDiagnose: a class that contains the diagnose method of Stack class.//template<class TObject>class StackDiagnose : public Stack<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: //--------------------------------------------------------------------------- // // required public methods // //---------------------------------------------------------------------------public: // method: name // static const String& name() { return Stack<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 StackDiagnose 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 StackDiagnose<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 destructor/consturctor(s) in refernece mode // prepare all of the character items to use in this stack diagnose // we will use the letters of the english alphabet // long num_elem = 26; Char** items = new Char*[num_elem]; for (long i = 0; i < num_elem; i++) { items[i] = new Char((unichar)((long)(L'a') + i)); } // test setDebug // setDebug(debug_level_d); // check the constructors for allocating on the stack // Stack<Char> def_stack; // default constructor def_stack.push(items[0]); def_stack.push(items[1]); def_stack.push(items[2]); Stack<Char> copy_stack(def_stack); // copy constructor // the two constructed stacks should have the same items in them now // if (def_stack.ne(copy_stack)) { return Error::handle(name(), L"copy constructor", Error::TEST, __FILE__, __LINE__); } // check the constructors and destructors for allocating on the dynamic // memory heap // Stack<Char>* def_dyn_stack = new Stack<Char>(); def_dyn_stack->push(items[0]); def_dyn_stack->push(items[1]); def_dyn_stack->push(items[2]); Stack<Char>* copy_dyn_stack = new Stack<Char>(*def_dyn_stack); // the two constructed stacks should have the same items in them now // if (def_dyn_stack->ne(copy_stack)) { return Error::handle(name(), L"copy constructor", Error::TEST, __FILE__, __LINE__); } // see if we can dynamically delete // delete def_dyn_stack; delete copy_dyn_stack; { // test destructor/consturctor(s) in reference mode // prepare all of the character items to use in this stack diagnose // we will use the letters of the english alphabet // Stack<Char> def_stack(USER); // default constructor def_stack.push(items[0]); def_stack.push(items[1]); def_stack.push(items[2]); Stack<Char> copy_stack(def_stack); // copy constructor // the two constructed stacks should have the same items in them now // if (def_stack.ne(copy_stack)) { return Error::handle(name(), L"copy constructor", Error::TEST, __FILE__, __LINE__); } // check the constructors and destructors for allocating on the dynamic // memory heap // Stack<Char>* def_dyn_stack = new Stack<Char>; def_dyn_stack->setAllocationMode(USER); if (def_dyn_stack->getAllocationMode() != USER) { return Error::handle(name(), L"getAllocationMode", Error::TEST, __FILE__, __LINE__); } def_dyn_stack->push(items[0]); def_dyn_stack->push(items[1]); def_dyn_stack->push(items[2]); Stack<Char>* copy_dyn_stack = new Stack<Char>(*def_dyn_stack); // the two constructed stacks should have the same items in them now // if (def_dyn_stack->ne(copy_stack)) { return Error::handle(name(), L"copy constructor", Error::TEST, __FILE__, __LINE__); } // see if we can dynamically delete // delete def_dyn_stack; delete copy_dyn_stack; } // test large allocation construction and deletion in reference mode // if (level_a >= Integral::ALL) { // output an informative message // Console::put(L"testing large chunk memory allocation and deletion\n"); // set the memory to a strange block size so we can hopefully catch any // frame overrun errors // Stack<TObject>::setGrowSize((long)731); // loop for a large number of times creating and deleting a large number // of Stacks at each loop // for (long j = 1; j <= 100; j++) { Stack<Char>** stacks = new Stack<Char>*[j * 100]; // create the items // for (long i = 0; i < j * 100; i++) { stacks[i] = new Stack<Char>(); } // delete lists // for (long i = (j * 100) - 1; i >= 0; i--) { delete stacks[i]; } // clean up memory // delete [] stacks; } } { // test large allocation construction and deletion in // SYSTEM-allocation mode // if (level_a >= Integral::ALL) { // output an informative message // Console::put(L"testing large chunk memory allocation and deletion\n"); // set the memory to a strange block size so we can hopefully catch any // frame overrun errors // Stack<TObject>::setGrowSize((long)731); // loop for a large number of times creating and deleting a large number // of Stacks at each loop // for (long j = 1; j <= 100; j++) { Stack<Char>** stacks = new Stack<Char>*[j * 100]; // create the items // for (long i = 0; i < j * 100; i++) { stacks[i] = new Stack<Char>(USER); } // delete lists // for (long i = (j * 100) - 1; i >= 0; i--) { delete stacks[i]; } // clean up memory // delete [] stacks; } } } // test assign methods in reference mode // Stack<Char> tmp_stack; Stack<Char>* tmp_dyn_stack = new Stack<Char>; // add all items onto the stack // tmp_stack.push(items, num_elem); // try the list assign method // tmp_dyn_stack->assign(tmp_stack); if (tmp_dyn_stack->ne(tmp_stack)) { return Error::handle(name(), L"list assign", Error::TEST, __FILE__, __LINE__); } // clean up memory // delete tmp_dyn_stack; { // test assign methods in reference mode // Stack<Char> tmp_stack(USER); Stack<Char>* tmp_dyn_stack = new Stack<Char>(USER); // add all items onto the stack // tmp_stack.push(items, num_elem); // try the list assign method // tmp_dyn_stack->assign(tmp_stack); if (tmp_dyn_stack->ne(tmp_stack)) { return Error::handle(name(), L"list assign", Error::TEST, __FILE__, __LINE__); } // clean up memory // delete tmp_dyn_stack; } // testing i/o methods in SYSTEM-allocation mode // String text_filename; Integral::makeTemp(text_filename); String bin_filename; Integral::makeTemp(bin_filename); // open files in write mode // Sof text_file; text_file.open(text_filename, File::WRITE_ONLY, File::TEXT); Sof bin_file; bin_file.open(bin_filename, File::WRITE_ONLY, File::BINARY); // prepare items for the lists // Char** write_chars = new Char*[5]; String** write_strings = new String*[5]; unichar tmp_char = L'a'; for (long i = 0; i < 5; i++) { write_chars[i] = new Char(tmp_char); write_strings[i] = new String(); tmp_char++; } write_strings[0]->assign(L"this "); write_strings[1]->assign(L"is"); write_strings[2]->assign(L"a"); write_strings[3]->assign(L"Stack"); write_strings[4]->assign(L"String"); // create stacks to write // Stack<Char> write_char_stack; write_char_stack.push(write_chars, 5); Stack<String> write_str_stack; write_str_stack.push(write_strings, 5); Stack<Stack<Char > > write_char_stack_stack; Stack<Stack<Stack<Char > > > write_char_sss; // create objects for reading in
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -