#include <safe-file.h>
Public Types | |
enum | { is_open, is_open_gz, insist, no_insist, failed } |
Static Public Methods | |
int | open (std::ifstream &in, std::string const &filename) |
Try to open file filename. More... | |
int | open_gz (std::ifstream &in, std::string const &filename, int strictness=insist) |
! Try to open also filename.gz if filename does not exist. More... | |
void | close (std::ifstream &in, std::string const &nm, int gz=is_open) |
Close ifstream. If gz = is_open_gz, gzip the file. More... | |
int | open (std::ofstream &out, std::string const &filename) |
Open ofstream. More... | |
void | close (std::ofstream &in, std::string const &nm, int gz=is_open) |
close ofstream. More... |
This class povides some functions to open and close files in a robust (?) manner. If a file with a given name does not exist, the user is prompted for a valid filename. Also, the class may search for a compressed file with a .gz suffix.
The opened ifstream in will be returned, so that the following usages are possible:
ifstream in; file_interactive::open(in,"xyz.dat") >> x >> y >> z;
or
file_interactive::open_gz(in,"xyz.dat"); in >> x >> y >> z;
Definition at line 40 of file safe-file.h.
|
Definition at line 42 of file safe-file.h. |
|
Try to open file filename. If strictness = insist, do ask interactively if file could not be opened. Result is in { is_open, failed }. |
|
! Try to open also filename.gz if filename does not exist. If strictness = insist, do ask interactively if file could not be opened. Result is in { is_open, is_open_gz, failed }. Definition at line 35 of file safe-file.C. References failed, insist, is_open, and is_open_gz. |
|
Close ifstream. If gz = is_open_gz, gzip the file.
Definition at line 72 of file safe-file.C. References is_open_gz. |
|
Open ofstream.
Definition at line 88 of file safe-file.C. |
|
close ofstream. gz in { is_open, is_open_gz }. Parameter nm needed only if gz == is_open_gz (cannot deduce file name from stream). Definition at line 80 of file safe-file.C. References is_open_gz. |