📄 stackdiagnose.h
字号:
// Stack<Char> read_char_stack_text; Stack<Char> read_char_stack_bin; Stack<String> read_str_stack_text; Stack<String> read_str_stack_bin; Stack<Stack<Char > > read_char_stack_stack_bin; Stack<Stack<Char > > read_char_stack_stack_text; Stack<Stack<Stack<Char > > > read_char_sss_bin; Stack<Stack<Stack<Char > > > read_char_sss_text; Stack<Stack<Char > >* wc_ss_0 = new Stack<Stack<Char > >; Stack<Stack<Char > >* wc_ss_1 = new Stack<Stack<Char > >; long s1 = 2; long s2 = 5; for (long i = 0; i < s1; i++) { Stack<Char>* temp = new Stack<Char>; Stack<Char>* t1 = new Stack<Char>; Stack<Char>* t2 = new Stack<Char>; for (long j = 0; j < s2; j++) { Char* c1 = new Char(); Char* c2 = new Char(); Char* c3 = new Char(); c1->assign((unichar)(i * (s2+1) + j + (int)'A')); c2->assign((unichar)(i * (s2+1) + j + (int)'A')); c3->assign((unichar)(i * (s2+1) + j + (int)'a')); temp->push(c1); t1->push(c2); t2->push(c3); delete c1; delete c2; delete c3; } write_char_stack_stack.push(temp); wc_ss_0->push(t1); wc_ss_1->push(t2); delete temp; delete t1; delete t2; } // 10 channel vector data // s1 = 3; s2 = 20; write_char_sss.push(wc_ss_0); write_char_sss.push(wc_ss_1); // write the values // write_char_stack.write(text_file, (long)0); write_char_stack.write(bin_file, (long)0); write_str_stack.write(text_file, (long)0); write_str_stack.write(bin_file, (long)0); write_char_stack_stack.write(text_file, (long)0); write_char_stack_stack.write(bin_file, (long)0); write_char_sss.write(text_file, (long)0); write_char_sss.write(bin_file, (long)0); // close the files // text_file.close(); bin_file.close(); // open the files in read mode // text_file.open(text_filename); bin_file.open(bin_filename); // read in the lists and test for equivalence // if (!read_char_stack_text.read(text_file, (long)0) || (read_char_stack_text.ne(write_char_stack))) { return Error::handle(name(), L"read char text", Error::TEST, __FILE__, __LINE__); } if (!read_str_stack_text.read(text_file, (long)0) || (read_str_stack_text.ne(write_str_stack))) { return Error::handle(name(), L"read str text", Error::TEST, __FILE__, __LINE__); } if (!read_char_stack_bin.read(bin_file, (long)0) || (read_char_stack_bin.ne(write_char_stack))) { return Error::handle(name(), L"write char bin", Error::TEST, __FILE__, __LINE__); } if (!read_str_stack_bin.read(bin_file, (long)0) || (read_str_stack_bin.ne(write_str_stack))) { return Error::handle(name(), L"write str bin", Error::TEST, __FILE__, __LINE__); } if (!read_char_stack_stack_text.read(text_file, (long)0) || (read_char_stack_stack_text.ne(write_char_stack_stack))) { return Error::handle(name(), L"read chr chr text", Error::TEST, __FILE__, __LINE__); } if (!read_char_stack_stack_bin.read(bin_file, (long)0) || (read_char_stack_stack_bin.ne(write_char_stack_stack))) { return Error::handle(name(), L"read chr chr bin", Error::TEST, __FILE__, __LINE__); } if (!read_char_sss_text.read(text_file, (long)0) || (read_char_sss_text.ne(write_char_sss))) { return Error::handle(name(), L"read chr chr chr text", Error::TEST, __FILE__, __LINE__); } if (!read_char_sss_bin.read(bin_file, (long)0) || (read_char_sss_bin.ne(write_char_sss))) { return Error::handle(name(), L"read chr chr bin", Error::TEST, __FILE__, __LINE__); } // close and delete the temporary files // text_file.close(); bin_file.close(); File::remove(text_filename); File::remove(bin_filename); // cleanup the memory that was created by the Stack read // read_char_stack_text.clear(Integral::FREE); read_char_stack_bin.clear(Integral::FREE); read_str_stack_text.clear(Integral::FREE); read_str_stack_bin.clear(Integral::FREE); // delete things from the nested stacks // Stack<Char> temp_stack2; while((write_char_stack_stack.pop(&temp_stack2)) != (Stack<Char>*)NULL) { Char temp_char1; while ((temp_stack2.pop(&temp_char1)) != (Char*)NULL) { } } while ((read_char_stack_stack_bin.pop(&temp_stack2)) != (Stack<Char>*)NULL) { Char temp_char1; while ((temp_stack2.pop(&temp_char1)) != (Char*)NULL) { } } while ((read_char_stack_stack_text.pop(&temp_stack2)) != (Stack<Char>*)NULL) { Char temp_char1; while ((temp_stack2.pop(&temp_char1)) != (Char*)NULL) { } } // delete things from the triple-nested stacks // Stack< Stack<Char> > temp_ss; while (write_char_sss.pop(&temp_ss) != (Stack< Stack<Char> >*)NULL) { Stack<Char> temp_s; while (temp_ss.pop(&temp_s) != (Stack<Char>*)NULL) { Char temp_char1; while (temp_s.pop(&temp_char1) != (Char*)NULL) { } } } while (read_char_sss_text.pop(&temp_ss) != (Stack< Stack<Char> >*)NULL) { Stack<Char> temp_s; while (temp_ss.pop(&temp_s) != (Stack<Char>*)NULL) { Char temp_char1; while (temp_s.pop(&temp_char1) != (Char*)NULL) { } } } while (read_char_sss_bin.pop(&temp_ss) != (Stack< Stack<Char> >*)NULL) { Stack<Char> temp_s; while (temp_ss.pop(&temp_s) != (Stack<Char>*)NULL) { Char temp_char1; while (temp_s.pop(&temp_char1) != (Char*)NULL) { } } } // cleanup dynamically allocated memory // for (long i = 0; i < 5; i++) { delete write_chars[i]; delete write_strings[i]; } delete [] write_chars; delete [] write_strings; delete wc_ss_0; delete wc_ss_1; { // testing i/o methods for reference 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); 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(USER); write_char_stack.push(write_chars, 5); Stack<String> write_str_stack(USER); write_str_stack.push(write_strings, 5); Stack<Stack<Char > > write_char_stack_stack(USER); Stack<Stack<Stack<Char > > > write_char_sss(USER); Stack<Stack<Char > >* wc_ss_0 = new Stack<Stack<Char > >(USER); Stack<Stack<Char > >* wc_ss_1 = new Stack<Stack<Char > >(USER); // create objects for reading in // Stack<Char> read_char_stack_text(USER); Stack<Char> read_char_stack_bin(USER); Stack<String> read_str_stack_text(USER); Stack<String> read_str_stack_bin(USER); Stack<Stack<Char > > read_char_stack_stack_bin(USER); Stack<Stack<Char > > read_char_stack_stack_text(USER); Stack<Stack<Stack<Char > > > read_char_sss_bin(USER); Stack<Stack<Stack<Char > > > read_char_sss_text(USER); long s1 = 2; long s2 = 5; for (long i = 0; i < s1; i++) { Stack<Char>* temp = new Stack<Char>(USER); Stack<Char>* t1 = new Stack<Char>(USER); Stack<Char>* t2 = new Stack<Char>(USER); for (long j = 0; j < s2; j++) { Char* c1 = new Char(); Char* c2 = new Char(); Char* c3 = new Char(); c1->assign((unichar)(i * (s2+1) + j + (int)'A')); c2->assign((unichar)(i * (s2+1) + j + (int)'A')); c3->assign((unichar)(i * (s2+1) + j + (int)'a')); temp->push(c1); t1->push(c2); t2->push(c3); } write_char_stack_stack.push(temp); wc_ss_0->push(t1); wc_ss_1->push(t2); } // 10 channel vector data // s1 = 3; s2 = 20; write_char_sss.push(wc_ss_0); write_char_sss.push(wc_ss_1); // write the values // write_char_stack.write(text_file, (long)0); write_char_stack.write(bin_file, (long)0); write_str_stack.write(text_file, (long)0); write_str_stack.write(bin_file, (long)0); write_char_stack_stack.write(text_file, (long)0); write_char_stack_stack.write(bin_file, (long)0); write_char_sss.write(text_file, (long)0); write_char_sss.write(bin_file, (long)0); // close the files // text_file.close(); bin_file.close(); // open the files in read mode // text_file.open(text_filename); bin_file.open(bin_filename); // read in the lists and test for equivalence // if (!read_char_stack_text.read(text_file, (long)0) || (read_char_stack_text.ne(write_char_stack))) { return Error::handle(name(), L"read char text", Error::TEST, __FILE__, __LINE__); } if (!read_str_stack_text.read(text_file, (long)0) || (read_str_stack_text.ne(write_str_stack))) { return Error::handle(name(), L"read str text", Error::TEST, __FILE__, __LINE__); } if (!read_char_stack_bin.read(bin_file, (long)0) || (read_char_stack_bin.ne(write_char_stack))) { return Error::handle(name(), L"write char bin", Error::TEST, __FILE__, __LINE__); } if (!read_str_stack_bin.read(bin_file, (long)0) || (read_str_stack_bin.ne(write_str_stack))) { return Error::handle(name(), L"write str bin", Error::TEST, __FILE__, __LINE__); } if (!read_char_stack_stack_text.read(text_file, (long)0) || (read_char_stack_stack_text.ne(write_char_stack_stack))) { return Error::handle(name(), L"read chr chr text", Error::TEST, __FILE__, __LINE__); } if (!read_char_stack_stack_bin.read(bin_file, (long)0) || (read_char_stack_stack_bin.ne(write_char_stack_stack))) { return Error::handle(name(), L"read chr chr bin", Error::TEST, __FILE__, __LINE__); } if (!read_char_sss_text.read(text_file, (long)0) || (read_char_sss_text.ne(write_char_sss))) { return Error::handle(name(), L"read chr chr chr text", Error::TEST, __FILE__, __LINE__); } if (!read_char_sss_bin.read(bin_file, (long)0) || (read_char_sss_bin.ne(write_char_sss))) { return Error::handle(name(), L"read chr chr bin", Error::TEST, __FILE__, __LINE__); } // close and delete the temporary files // text_file.close(); bin_file.close(); File::remove(text_filename); File::remove(bin_filename); // cleanup the memory that was created by the Stack read // read_char_stack_text.clear(Integral::FREE); read_char_stack_bin.clear(Integral::FREE); read_str_stack_text.clear(Integral::FREE); read_str_stack_bin.clear(Integral::FREE); // delete things from the nested stacks // Stack<Char>* temp_stack2; while((temp_stack2 = write_char_stack_stack.pop()) != (Stack<Char>*)NULL) { Char* temp_char; while ((temp_char = temp_stack2->pop()) != (Char*)NULL) { delete temp_char; } delete temp_stack2; } while ((temp_stack2 = read_char_stack_stack_bin.pop()) != (Stack<Char>*)NULL) { Char temp_char1; while ((temp_stack2->pop(&temp_char1)) != (Char*)NULL) { } delete temp_stack2; } while ((temp_stack2 = read_char_stack_stack_text.pop()) != (Stack<Char>*)NULL) { Char temp_char1; while ((temp_stack2->pop(&temp_char1)) != (Char*)NULL) { } delete temp_stack2; } // delete things from the triple-nested stacks // Stack<Stack<Char > >* temp_ss; while ((temp_ss = write_char_sss.pop()) != (Stack< Stack<Char> >*)NULL) { Stack<Char>* temp_s; while ((temp_s = temp_ss->pop()) != (Stack<Char>*)NULL) { Char* temp_char; while ((temp_char = temp_s->pop()) != (Char*)NULL) { delete temp_char; } delete temp_s;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -