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 "FV.H"
00028 #include "CompactFV.H"
00029
00030 using std::ofstream;
00031 using std::ifstream;
00032 using std::cout;
00033 using std::cin;
00034 using std::cerr;
00035 using std::endl;
00036
00037 int main(int argc, char *argv[]) {
00038
00039 if (argc != 2) {
00040 cerr << "Incorrect number of arguments." << endl;
00041 cerr << "Syntax: TestCompactFV filename" << endl;
00042 return 1;
00043 }
00044 Text fname(argv[1]);
00045
00046
00047 const int MaxLineLen = 80;
00048 char line[MaxLineLen + 1];
00049 FV::ListApp names;
00050 cout << "Adding paths:" << endl;
00051 while (cin.peek() != EOF) {
00052 cin.getline(line, MaxLineLen, '\n');
00053 FV::T path(line);
00054 (void) names.Append(path);
00055 cout << " " << line << endl;
00056 }
00057 cout << endl;
00058
00059
00060 cout << "Here are the resulting names in compact form:" << endl << endl;
00061 CompactFV::List names2(names);
00062 names2.Print(cout, 2);
00063 cout << endl;
00064
00065 try {
00066
00067 ofstream ofs;
00068 FS::OpenForWriting(fname, ofs);
00069 names2.Write(ofs);
00070 FS::Close(ofs);
00071
00072
00073 ifstream ifs;
00074 FS::OpenReadOnly(fname, ifs);
00075 CompactFV::List newNames2(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 names:" << endl << endl;
00081 newNames2.Print(cout, 2);
00082 } catch (const FS::Failure &f) {
00083 cerr << "Error pickling table: " << f << "; exiting..." << endl;
00084 return 1;
00085 }
00086 return 0;
00087 }