Fortran SFF API to data I/O streams in C++
fileunit.h
Go to the documentation of this file.
1 
39 // include guard
40 #ifndef TF_FILEUNIT_H_VERSION
41 
42 #define TF_FILEUNIT_H_VERSION \
43  "TF_FILEUNIT_H V1.2"
44 
45 #include<map>
46 #include<string>
47 #include<iostream>
48 #include<datrwxx/readany.h>
49 #include<datrwxx/writeany.h>
50 
51 namespace fapidxx {
52 
55  class IFileUnits {
56  public:
58  IFileUnits();
60  ~IFileUnits();
62  datrw::ianystream& open(const int& unit,
63  const std::string& filename);
65  datrw::ianystream& getstream(const int& unit);
67  bool isopen(const int& unit) const;
69  void close(const int& unit);
71  void setformat(const std::string& format);
73  datrw::ianystream& operator()(const int& unit)
74  { return(this->getstream(unit)); }
75  private:
77  struct IstreamCompound {
78  std::istream *Mistream;
79  datrw::ianystream *Mianystream;
80  }; // struct IstreamCompound
82  IFileUnits(const IFileUnits& ifu);
84  IFileUnits& operator= (const IFileUnits& ifu);
86  typedef std::map<int, IstreamCompound> Tstreammap;
88  std::string Mformat;
91  }; // clas IFileUnits
92 
93  /*----------------------------------------------------------------------*/
94 
97  class OFileUnits {
98  public:
100  OFileUnits();
102  ~OFileUnits();
104  datrw::oanystream& open(const int& unit,
105  const std::string& filename);
107  datrw::oanystream& getstream(const int& unit);
109  bool isopen(const int& unit) const;
111  void close(const int& unit);
113  void setformat(const std::string& format);
115  datrw::oanystream& operator()(const int& unit)
116  { return(this->getstream(unit)); }
117  private:
120  std::ostream *Mostream;
121  datrw::oanystream *Moanystream;
122  }; // struct OstreamCompound
124  OFileUnits(const OFileUnits& ifu);
126  OFileUnits& operator= (const OFileUnits& ifu);
128  typedef std::map<int, OstreamCompound> Tstreammap;
130  std::string Mformat;
133  }; // clas OFileUnits
134 
135  /*----------------------------------------------------------------------*/
136 
138  extern ::fapidxx::IFileUnits istreammanager;
139 
141  extern ::fapidxx::OFileUnits ostreammanager;
142 
143 } // namespace fapidxx
144 
145 #endif // TF_FILEUNIT_H_VERSION (includeguard)
146 
147 /* ----- END OF fileunit.h ----- */
std::map< int, OstreamCompound > Tstreammap
type of my oanystream container
Definition: fileunit.h:128
Definition: error.cc:44
datrw::ianystream & operator()(const int &unit)
quick access
Definition: fileunit.h:73
datrw::oanystream * Moanystream
Definition: fileunit.h:121
bool isopen(const int &unit) const
check whether a file is opened for this file unit
Definition: fileunit.cc:103
OFileUnits & operator=(const OFileUnits &ifu)
do not allow copying
datrw::ianystream * Mianystream
Definition: fileunit.h:79
void setformat(const std::string &format)
set file format to be used upon file open
Definition: fileunit.cc:121
datrw::oanystream & open(const int &unit, const std::string &filename)
open a new file
Definition: fileunit.cc:147
Tstreammap Mstreammap
place to hold my oanystream objects
Definition: fileunit.h:132
~OFileUnits()
destructor has to close all open files
Definition: fileunit.cc:136
std::map< int, IstreamCompound > Tstreammap
type of my ianystream container
Definition: fileunit.h:86
void setformat(const std::string &format)
set file format to be used upon file open
Definition: fileunit.cc:192
::fapidxx::OFileUnits ostreammanager
the global ostream manager
Definition: fileunit.cc:51
datrw::oanystream & operator()(const int &unit)
quick access
Definition: fileunit.h:115
datrw::ianystream & open(const int &unit, const std::string &filename)
open a new file
Definition: fileunit.cc:77
Tstreammap Mstreammap
place to hold my ianystream objects
Definition: fileunit.h:90
OFileUnits()
default contructor to initialize member data
Definition: fileunit.cc:128
bool isopen(const int &unit) const
check whether a file is opened for this file unit
Definition: fileunit.cc:174
IFileUnits()
default contructor to initialize member data
Definition: fileunit.cc:58
std::string Mformat
file type to be used
Definition: fileunit.h:88
A C++ stream has to be handled together with an ianystream.
Definition: fileunit.h:77
datrw::ianystream & getstream(const int &unit)
return a stream associated with a file unit
Definition: fileunit.cc:112
~IFileUnits()
destructor has to close all open files
Definition: fileunit.cc:66
IFileUnits & operator=(const IFileUnits &ifu)
do not allow copying
datrw::oanystream & getstream(const int &unit)
return a stream associated with a file unit
Definition: fileunit.cc:183
void close(const int &unit)
close the file associated with this file unit
Definition: fileunit.cc:162
std::string Mformat
file type to be used
Definition: fileunit.h:130
::fapidxx::IFileUnits istreammanager
the global istream manager
Definition: fileunit.cc:48
A C++ stream has to be handled together with an oanystream.
Definition: fileunit.h:119
void close(const int &unit)
close the file associated with this file unit
Definition: fileunit.cc:91