Rheolef  7.1
an efficient C++ finite element environment
rheostream.h
Go to the documentation of this file.
1 #ifndef _RHEOLEF_STREAM_H
2 #define _RHEOLEF_STREAM_H
3 // author: Pierre.Saramito@imag.fr
24 // date: 31 october 1997
25 
26 namespace rheolef {
157 }// namespace rheolef
158 
159 #include "rheolef/compiler.h"
160 #include <boost/iostreams/filtering_stream.hpp>
161 
162 namespace rheolef {
163 
164 // input & output modes:
165 namespace io {
166  typedef enum {
167  out = 0,
168  app = 1, // append mode
169  gz = 0, // default is to use gzip
170  nogz = 2 // force not using gzip
172 }
173 // [verbatim_irheostream]
174 class irheostream : public boost::iostreams::filtering_stream<boost::iostreams::input> {
175 public:
176  irheostream() : boost::iostreams::filtering_stream<boost::iostreams::input>(), _ifs() {}
177  irheostream(const std::string& name, const std::string& suffix = std::string());
178  virtual ~irheostream();
179  void open (const std::string& name, const std::string& suffix = std::string());
180  void close();
181 // [verbatim_irheostream]
182 protected:
183  std::ifstream _ifs;
184 // [verbatim_irheostream_cont]
185 };
186 // [verbatim_irheostream_cont]
187 static const bool dont_gzip = false;
188 // [verbatim_orheostream]
189 class orheostream : public boost::iostreams::filtering_stream<boost::iostreams::output> {
190 public:
191  orheostream() : boost::iostreams::filtering_stream<boost::iostreams::output>(), _mode(), _full_name() {}
192  orheostream(const std::string& name, const std::string& suffix = std::string(),
193  io::mode_type mode = io::out);
194  virtual ~orheostream();
195  void open (const std::string& name, const std::string& suffix = std::string(),
196  io::mode_type mode = io::out);
197  void flush();
198  void close();
199  const std::string& filename() const { return _full_name; }
200 // [verbatim_orheostream]
201 protected:
202  void _open_internal (io::mode_type mode);
203  void _close_internal ();
204 // data:
206  std::string _full_name;
207 // [verbatim_orheostream_cont]
208 };
209 // [verbatim_orheostream_cont]
210 
211 // [verbatim_functions]
213 // integer-to-string conversion
214 std::string itos (std::string::size_type i);
215 
217 // float-to-string conversion
218 std::string ftos (const Float& x);
219 
221 // catch first occurrence of string in file
222 bool scatch (std::istream& in, const std::string& ch, bool full_match = true);
223 
225 // has_suffix("toto.suffix", "suffix") -> true
226 bool has_suffix (const std::string& name, const std::string& suffix);
227 
229 // "toto.suffix" --> "toto"
230 std::string delete_suffix (const std::string& name, const std::string& suffix);
231 
233 // has_any_suffix("toto.any_suffix") -> true
234 bool has_any_suffix (const std::string& name);
235 
237 // delete_any_suffix("toto.any_suffix") --> "toto"
238 std::string delete_any_suffix (const std::string& name);
239 
241 // "/usr/local/dir/toto.suffix" --> "toto.suffix"
242 std::string get_basename (const std::string& name);
243 
245 // "/usr/local/dir/toto.suffix" --> "/usr/local/dir"
246 std::string get_dirname (const std::string& name);
247 
249 // "toto" --> "/usr/local/math/data/toto.suffix"
250 std::string get_full_name_from_rheo_path (const std::string& rootname, const std::string& suffix);
251 
253 // "." + "../geodir" --> ".:../geodir"
254 void append_dir_to_rheo_path (const std::string& dir);
255 
257 // "../geodir" + "." --> "../geodir:."
258 void prepend_dir_to_rheo_path (const std::string& dir);
259 
261 // predicate when a file exists
262 bool file_exists (const std::string& filename);
263 
265 // is_float("3.14") -> true
266 bool is_float (const std::string&);
267 
269 // string-to-float conversion
270 Float to_float (const std::string&);
271 
273 // in TMPDIR environment variable or "/tmp" by default
274 std::string get_tmpdir();
275 // [verbatim_functions]
276 
277 }// namespace rheolef
278 #endif // _RHEOLEF_STREAM_H
rheolef::orheostream::open
void open(const std::string &name, const std::string &suffix=std::string(), io::mode_type mode=io::out)
Definition: rheostream.cc:76
rheolef::orheostream::~orheostream
virtual ~orheostream()
Definition: rheostream.cc:71
rheolef::io::out
@ out
Definition: rheostream.h:167
rheolef::delete_suffix
string delete_suffix(const string &name, const string &suffix)
delete_suffix: see the rheostream page for the full documentation
Definition: rheostream.cc:222
rheolef::orheostream
Definition: rheostream.h:189
rheolef::get_full_name_from_rheo_path
string get_full_name_from_rheo_path(const string &rootname, const string &suffix)
get_full_name_from_rheo_path: see the rheostream page for the full documentation
Definition: rheostream.cc:445
rheolef::file_exists
bool file_exists(const std::string &filename)
file_exists: see the rheostream page for the full documentation
Definition: scatch.icc:42
rheolef::append_dir_to_rheo_path
void append_dir_to_rheo_path(const string &dir)
append_dir_to_rheo_path: see the rheostream page for the full documentation
Definition: rheostream.cc:330
rheolef::irheostream::_ifs
std::ifstream _ifs
Definition: rheostream.h:183
rheolef::orheostream::orheostream
orheostream()
Definition: rheostream.h:191
rheolef::io::mode_type
mode_type
Definition: rheostream.h:166
rheolef::get_tmpdir
std::string get_tmpdir()
get_tmpdir: see the rheostream page for the full documentation
Definition: rheostream.cc:50
rheolef::is_float
bool is_float(const string &s)
is_float: see the rheostream page for the full documentation
Definition: rheostream.cc:476
rheolef::orheostream::_full_name
std::string _full_name
Definition: rheostream.h:206
rheolef::delete_any_suffix
string delete_any_suffix(const string &name)
delete_any_suffix: see the rheostream page for the full documentation
Definition: rheostream.cc:239
rheolef::io::app
@ app
Definition: rheostream.h:168
rheolef::get_basename
string get_basename(const string &name)
get_basename: see the rheostream page for the full documentation
Definition: rheostream.cc:254
rheolef::irheostream
Definition: rheostream.h:174
boost
Definition: mpi_pair_datatype.h:46
rheolef::orheostream::_open_internal
void _open_internal(io::mode_type mode)
Definition: rheostream.cc:97
rheolef::io::nogz
@ nogz
Definition: rheostream.h:170
rheolef::irheostream::open
void open(const std::string &name, const std::string &suffix=std::string())
Definition: rheostream.cc:158
rheolef::irheostream::irheostream
irheostream()
Definition: rheostream.h:176
rheolef::prepend_dir_to_rheo_path
void prepend_dir_to_rheo_path(const string &dir)
prepend_dir_to_rheo_path: see the rheostream page for the full documentation
Definition: rheostream.cc:339
rheolef::orheostream::_close_internal
void _close_internal()
Definition: rheostream.cc:111
rheolef::orheostream::flush
void flush()
Definition: rheostream.cc:146
rheolef::scatch
bool scatch(std::istream &in, const std::string &ch, bool full_match=true)
scatch: see the rheostream page for the full documentation
Definition: scatch.icc:52
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
Float
see the Float page for the full documentation
rheolef::orheostream::_mode
io::mode_type _mode
Definition: rheostream.h:205
rheolef::dont_gzip
static const bool dont_gzip
Definition: rheostream.h:187
rheolef::has_suffix
bool has_suffix(const string &name, const string &suffix)
has_suffix: see the rheostream page for the full documentation
Definition: rheostream.cc:208
rheolef::ftos
string ftos(const Float &x)
itof: see the rheostream page for the full documentation
Definition: rheostream.cc:55
rheolef::to_float
Float to_float(const string &s)
to_float: see the rheostream page for the full documentation
Definition: rheostream.cc:494
size_type
field::size_type size_type
Definition: branch.cc:425
rheolef::io::gz
@ gz
Definition: rheostream.h:169
rheolef::irheostream::~irheostream
virtual ~irheostream()
Definition: rheostream.cc:201
rheolef::orheostream::close
void close()
Definition: rheostream.cc:139
rheolef::irheostream::close
void close()
Definition: rheostream.cc:188
rheolef::itos
std::string itos(std::string::size_type i)
itos: see the rheostream page for the full documentation
rheolef::orheostream::filename
const std::string & filename() const
Definition: rheostream.h:199
mkgeo_contraction.name
string name
Definition: mkgeo_contraction.sh:133
rheolef::has_any_suffix
bool has_any_suffix(const string &name)
has_any_suffix: see the rheostream page for the full documentation
Definition: rheostream.cc:229
rheolef::get_dirname
string get_dirname(const string &name)
get_dirname: see the rheostream page for the full documentation
Definition: rheostream.cc:263