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

TestCompactFV.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 Mon Mar 30 18:32:29 PST 1998 by heydon
00020 // Last modified on Thu Aug  5 10:09:58 EDT 2004 by ken@xorian.net
00021 //      modified on Tue Mar 31 10:17:43 PST 1998 by heydon
00022 
00023 /* A test of the "CompactFV::List" class. */
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     // check for correct # of arguments
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     // read from stdin and create the table
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     // print the table
00060     cout << "Here are the resulting names in compact form:" << endl << endl;
00061     CompactFV::List names2(names);
00062     names2.Print(cout, /*indent=*/ 2);
00063     cout << endl;
00064 
00065     try {
00066         // write the table out to disk
00067         ofstream ofs;
00068         FS::OpenForWriting(fname, /*OUT*/ ofs);
00069         names2.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         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, /*indent=*/ 2);
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