00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <Basics.H>
00026 #include <FS.H>
00027 #include "PrefixTbl.H"
00028
00029 using std::ofstream;
00030 using std::ifstream;
00031 using std::cout;
00032 using std::cin;
00033 using std::cerr;
00034 using std::endl;
00035
00036 int main(int argc, char *argv[]) {
00037
00038 if (argc != 2) {
00039 cerr << "Incorrect number of arguments." << endl;
00040 cerr << "Syntax: TestPrefixTbl filename" << endl;
00041 return 1;
00042 }
00043
00044
00045 const int MaxLineLen = 80;
00046 char line[MaxLineLen + 1];
00047 PrefixTbl tbl( 10);
00048 TextIntTbl tempTbl;
00049 cout << "Adding paths:" << endl;
00050 while (cin.peek() != EOF) {
00051 cin.getline(line, MaxLineLen, '\n');
00052 FV2::T seq(line);
00053 int idx = tbl.Put(seq, tempTbl);
00054 cout << " " << line << " -> " << idx << endl;
00055 }
00056 cout << endl;
00057
00058
00059 cout << "Here is the resulting table:" << endl << endl;
00060 tbl.Print(cout);
00061 cout << endl;
00062
00063 Text fname(argv[1]);
00064 try {
00065
00066 cout << "Pickling table to " << fname << "..." << endl << endl;
00067 ofstream ofs;
00068 FS::OpenForWriting(fname, ofs);
00069 tbl.Write(ofs);
00070 FS::Close(ofs);
00071
00072
00073 ifstream ifs;
00074 FS::OpenReadOnly(fname, ifs);
00075 PrefixTbl newTbl(ifs);
00076 if (!FS::AtEOF(ifs)) {
00077 cerr << "Error: stream not at end-of-file as expected!" << endl;
00078 }
00079 FS::Close(ifs);
00080 cout << "Here is the unpickled version of the table:" << endl << endl;
00081 newTbl.Print(cout);
00082 } catch (const FS::Failure &f) {
00083 cerr << "Error pickling table: " << f << "; exiting..." << endl;
00084 return 1;
00085 }
00086 return 0;
00087 }