Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

TestPrefixTbl.C

Go to the documentation of this file.
00001 // Copyright (C) 2001, Compaq Computer Corporation
00002 // 
00003 // This file is part of Vesta.
00004 // 
00005 // Vesta is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 // 
00010 // Vesta is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with Vesta; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 // Created on Sat Mar 28 23:02:19 PST 1998 by heydon
00020 // Last modified on Thu Aug  5 10:12:42 EDT 2004 by ken@xorian.net
00021 //      modified on Mon Mar 30 18:34:09 PST 1998 by heydon
00022 
00023 /* A test of the "PrefixTbl" class. */
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     // check for correct # of arguments
00038     if (argc != 2) {
00039         cerr << "Incorrect number of arguments." << endl;
00040         cerr << "Syntax: TestPrefixTbl filename" << endl;
00041         return 1;
00042     }
00043 
00044     // read from stdin and create the table
00045     const int MaxLineLen = 80;
00046     char line[MaxLineLen + 1];
00047     PrefixTbl tbl(/*sizeHint=*/ 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, /*INOUT*/ tempTbl);
00054         cout << "  " << line << " -> " << idx << endl;
00055     }
00056     cout << endl;
00057 
00058     // print the table
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         // write the table out to disk
00066         cout << "Pickling table to " << fname << "..." << endl << endl;
00067         ofstream ofs;
00068         FS::OpenForWriting(fname, /*OUT*/ ofs);
00069         tbl.Write(ofs);
00070         FS::Close(ofs);
00071 
00072         // read it back in and print it
00073         ifstream ifs;
00074         FS::OpenReadOnly(fname, /*OUT*/ 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 }

Generated on Mon May 8 00:48:32 2006 for Vesta by  doxygen 1.4.2