00001 #ifndef NMWR_GB_SAFE_FILEIO_H
00002 #define NMWR_GB_SAFE_FILEIO_H
00003
00004
00005
00006
00007
00008
00009 #include <fstream.h>
00010 #include "Forward/string_fwd.h"
00011
00012
00014
00015 This class povides some functions to open and close
00016 files in a robust (?) manner.
00017 If a file with a given name does not exist,
00018 the user is prompted for a valid filename.
00019 Also, the class may search for a compressed file with a .gz suffix.
00020
00021 The opened ifstream in will be returned, so that
00022 the following usages are possible:
00023
00024 \code
00025 ifstream in;
00026 file_interactive::open(in,"xyz.dat") >> x >> y >> z;
00027 \endcode
00028
00029 or
00030
00031 \code
00032 file_interactive::open_gz(in,"xyz.dat");
00033 in >> x >> y >> z;
00034 \endcode
00035 This tries to open "xyz.dat" or, failing this, "xyz.dat.gz".
00036 */
00037
00038
00039
00040 class file_interactive {
00041 public:
00042 enum { is_open,
00043 is_open_gz ,
00044 insist,
00045 no_insist,
00046 failed
00047 };
00049
00053 static int open(std::ifstream& in, std::string const& filename);
00054
00056
00061 static int open_gz(std::ifstream& in, std::string const& filename, int strictness = insist);
00063 static void close(std::ifstream& in, std::string const& nm, int gz = is_open);
00064
00066 static int open (std::ofstream& out, std::string const& filename);
00067
00068
00069
00070
00072
00076 static void close(std::ofstream& in, std::string const& nm, int gz = is_open);
00077 };
00078
00079 #endif