Rheolef  7.2
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
23 // author: Pierre.Saramito@imag.fr
24 // date: 31 october 1997
25 
26 namespace rheolef {
157 }// namespace rheolef
158 
159 #include "rheolef/compiler.h"
160 
161 #pragma GCC diagnostic push
162 #pragma GCC diagnostic ignored "-Weffc++"
163 #pragma GCC diagnostic ignored "-Wparentheses"
164 #include <boost/iostreams/filtering_stream.hpp>
165 #pragma GCC diagnostic pop
166 
167 namespace rheolef {
168 
169 // input & output modes:
170 namespace io {
171  typedef enum {
172  out = 0,
173  app = 1, // append mode
174  gz = 0, // default is to use gzip
175  nogz = 2 // force not using gzip
177 }
178 // [verbatim_irheostream]
179 class irheostream : public boost::iostreams::filtering_stream<boost::iostreams::input> {
180 public:
181  irheostream() : boost::iostreams::filtering_stream<boost::iostreams::input>(), _ifs() {}
182  irheostream(const std::string& name, const std::string& suffix = std::string());
183  virtual ~irheostream();
184  void open (const std::string& name, const std::string& suffix = std::string());
185  void close();
186 // [verbatim_irheostream]
187 protected:
188  std::ifstream _ifs;
189 // [verbatim_irheostream_cont]
190 };
191 // [verbatim_irheostream_cont]
192 static const bool dont_gzip = false;
193 // [verbatim_orheostream]
194 class orheostream : public boost::iostreams::filtering_stream<boost::iostreams::output> {
195 public:
196  orheostream() : boost::iostreams::filtering_stream<boost::iostreams::output>(), _mode(), _full_name() {}
197  orheostream(const std::string& name, const std::string& suffix = std::string(),
198  io::mode_type mode = io::out);
199  virtual ~orheostream();
200  void open (const std::string& name, const std::string& suffix = std::string(),
201  io::mode_type mode = io::out);
202  void flush();
203  void close();
204  const std::string& filename() const { return _full_name; }
205 // [verbatim_orheostream]
206 protected:
207  void _open_internal (io::mode_type mode);
208  void _close_internal ();
209 // data:
211  std::string _full_name;
212 // [verbatim_orheostream_cont]
213 };
214 // [verbatim_orheostream_cont]
215 
216 // [verbatim_functions]
218 // float-to-string conversion
219 std::string ftos (const Float& x);
220 
222 // catch first occurrence of string in file
223 bool scatch (std::istream& in, const std::string& ch, bool full_match = true);
224 
226 // has_suffix("toto.suffix", "suffix") -> true
227 bool has_suffix (const std::string& name, const std::string& suffix);
228 
230 // "toto.suffix" --> "toto"
231 std::string delete_suffix (const std::string& name, const std::string& suffix);
232 
234 // has_any_suffix("toto.any_suffix") -> true
235 bool has_any_suffix (const std::string& name);
236 
238 // delete_any_suffix("toto.any_suffix") --> "toto"
239 std::string delete_any_suffix (const std::string& name);
240 
242 // "/usr/local/dir/toto.suffix" --> "toto.suffix"
243 std::string get_basename (const std::string& name);
244 
246 // "/usr/local/dir/toto.suffix" --> "/usr/local/dir"
247 std::string get_dirname (const std::string& name);
248 
250 // "toto" --> "/usr/local/math/data/toto.suffix"
251 std::string get_full_name_from_rheo_path (const std::string& rootname, const std::string& suffix);
252 
254 // "." + "../geodir" --> ".:../geodir"
255 void append_dir_to_rheo_path (const std::string& dir);
256 
258 // "../geodir" + "." --> "../geodir:."
259 void prepend_dir_to_rheo_path (const std::string& dir);
260 
262 // predicate when a file exists
263 bool file_exists (const std::string& filename);
264 
266 // is_float("3.14") -> true
267 bool is_float (const std::string&);
268 
270 // string-to-float conversion
271 Float to_float (const std::string&);
272 
274 // in TMPDIR environment variable or "/tmp" by default
275 std::string get_tmpdir();
276 // [verbatim_functions]
277 
278 // integer-to-string conversion (backward compatibility)
279 inline std::string itos (std::size_t i) { return std::to_string(i); }
280 
281 }// namespace rheolef
282 #endif // _RHEOLEF_STREAM_H
see the Float page for the full documentation
std::ifstream _ifs
Definition: rheostream.h:188
virtual ~irheostream()
Definition: rheostream.cc:205
void open(const std::string &name, const std::string &suffix=std::string())
Definition: rheostream.cc:162
void _open_internal(io::mode_type mode)
Definition: rheostream.cc:101
const std::string & filename() const
Definition: rheostream.h:204
io::mode_type _mode
Definition: rheostream.h:210
virtual ~orheostream()
Definition: rheostream.cc:75
std::string _full_name
Definition: rheostream.h:211
void open(const std::string &name, const std::string &suffix=std::string(), io::mode_type mode=io::out)
Definition: rheostream.cc:80
static const bool dont_gzip
Definition: rheostream.h:192
This file is part of Rheolef.
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:449
string delete_any_suffix(const string &name)
delete_any_suffix: see the rheostream page for the full documentation
Definition: rheostream.cc:243
string delete_suffix(const string &name, const string &suffix)
delete_suffix: see the rheostream page for the full documentation
Definition: rheostream.cc:226
bool has_any_suffix(const string &name)
has_any_suffix: see the rheostream page for the full documentation
Definition: rheostream.cc:233
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:343
string get_basename(const string &name)
get_basename: see the rheostream page for the full documentation
Definition: rheostream.cc:258
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:44
std::string itos(std::size_t i)
Definition: rheostream.h:279
bool is_float(const string &s)
is_float: see the rheostream page for the full documentation
Definition: rheostream.cc:480
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:334
string ftos(const Float &x)
itof: see the rheostream page for the full documentation
Definition: rheostream.cc:59
string get_dirname(const string &name)
get_dirname: see the rheostream page for the full documentation
Definition: rheostream.cc:267
std::string get_tmpdir()
get_tmpdir: see the rheostream page for the full documentation
Definition: rheostream.cc:54
bool file_exists(const std::string &filename)
file_exists: see the rheostream page for the full documentation
Definition: scatch.icc:34
bool has_suffix(const string &name, const string &suffix)
has_suffix: see the rheostream page for the full documentation
Definition: rheostream.cc:212
Float to_float(const string &s)
to_float: see the rheostream page for the full documentation
Definition: rheostream.cc:498