Go to Overview over all GrAL packages.
Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

file_interactive Class Reference

Try to open a file and ask if it does not exist. More...

#include <safe-file.h>

List of all members.

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...


Detailed Description

Try to open a file and ask if it does not exist.

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;
This tries to open "xyz.dat" or, failing this, "xyz.dat.gz".

Definition at line 40 of file safe-file.h.


Member Enumeration Documentation

anonymous enum
 

Enumeration values:
is_open  open ok.
is_open_gz  open ok, file was gzipped.
insist  if open fails: Ask while no valid file name.
no_insist  ask only once, then proceed.
failed  open has failed.

Definition at line 42 of file safe-file.h.


Member Function Documentation

int file_interactive::open std::ifstream &    in,
std::string const &    filename
[static]
 

Try to open file filename.

If strictness = insist, do ask interactively if file could not be opened.

Result is in { is_open, failed }.

int file_interactive::open_gz std::ifstream &    in,
std::string const &    filename,
int    strictness = insist
[static]
 

! 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.

void file_interactive::close std::ifstream &    in,
std::string const &    nm,
int    gz = is_open
[static]
 

Close ifstream. If gz = is_open_gz, gzip the file.

Definition at line 72 of file safe-file.C.

References is_open_gz.

int file_interactive::open std::ofstream &    out,
std::string const &    filename
[static]
 

Open ofstream.

Definition at line 88 of file safe-file.C.

void file_interactive::close std::ofstream &    in,
std::string const &    nm,
int    gz = is_open
[static]
 

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.


The documentation for this class was generated from the following files:
Copyright (c) Guntram Berti 1997-2002. See the GrAL Homepage for up-to-date information.

Generated at Tue Feb 26 15:57:04 2002 for Utilities by doxygen 1.2.11-20011104 written by Dimitri van Heesch, © 1997-2000