Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
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
26namespace 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
167namespace rheolef {
168
169// input & output modes:
170namespace 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]
179class irheostream : public boost::iostreams::filtering_stream<boost::iostreams::input> {
180public:
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]
187protected:
188 std::ifstream _ifs;
189// [verbatim_irheostream_cont]
190};
191// [verbatim_irheostream_cont]
192static const bool dont_gzip = false;
193// [verbatim_orheostream]
194class orheostream : public boost::iostreams::filtering_stream<boost::iostreams::output> {
195public:
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]
206protected:
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
219std::string ftos (const Float& x);
220
222// catch first occurrence of string in file
223bool scatch (std::istream& in, const std::string& ch, bool full_match = true);
224
226// has_suffix("toto.suffix", "suffix") -> true
227bool has_suffix (const std::string& name, const std::string& suffix);
228
230// "toto.suffix" --> "toto"
231std::string delete_suffix (const std::string& name, const std::string& suffix);
232
234// has_any_suffix("toto.any_suffix") -> true
235bool has_any_suffix (const std::string& name);
236
238// delete_any_suffix("toto.any_suffix") --> "toto"
239std::string delete_any_suffix (const std::string& name);
240
242// "/usr/local/dir/toto.suffix" --> "toto.suffix"
243std::string get_basename (const std::string& name);
244
246// "/usr/local/dir/toto.suffix" --> "/usr/local/dir"
247std::string get_dirname (const std::string& name);
248
250// "toto" --> "/usr/local/math/data/toto.suffix"
251std::string get_full_name_from_rheo_path (const std::string& rootname, const std::string& suffix);
252
254// "." + "../geodir" --> ".:../geodir"
255void append_dir_to_rheo_path (const std::string& dir);
256
258// "../geodir" + "." --> "../geodir:."
259void prepend_dir_to_rheo_path (const std::string& dir);
260
262// predicate when a file exists
263bool file_exists (const std::string& filename);
264
266// is_float("3.14") -> true
267bool is_float (const std::string&);
268
270// string-to-float conversion
271Float to_float (const std::string&);
272
274// in TMPDIR environment variable or "/tmp" by default
275std::string get_tmpdir();
276// [verbatim_functions]
277
278// integer-to-string conversion (backward compatibility)
279inline 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
void open(const std::string &name, const std::string &suffix=std::string())
void _open_internal(io::mode_type mode)
const std::string & filename() const
Definition rheostream.h:204
io::mode_type _mode
Definition rheostream.h:210
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_dirname(const string &name)
get_dirname: see the rheostream page for the full documentation
string delete_suffix(const string &name, const string &suffix)
delete_suffix: see the rheostream page for the full documentation
void prepend_dir_to_rheo_path(const string &dir)
prepend_dir_to_rheo_path: see the rheostream page for the full documentation
std::string itos(std::size_t i)
Definition rheostream.h:279
Float to_float(const string &s)
to_float: see the rheostream page for the full documentation
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
string get_basename(const string &name)
get_basename: see the rheostream page for the full documentation
std::string get_tmpdir()
get_tmpdir: see the rheostream page for the full documentation
Definition rheostream.cc:54
bool has_suffix(const string &name, const string &suffix)
has_suffix: see the rheostream page for the full documentation
void append_dir_to_rheo_path(const string &dir)
append_dir_to_rheo_path: see the rheostream page for the full documentation
string delete_any_suffix(const string &name)
delete_any_suffix: see the rheostream page for the full documentation
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
bool is_float(const string &s)
is_float: see the rheostream page for the full documentation
string ftos(const Float &x)
itof: see the rheostream page for the full documentation
Definition rheostream.cc:59
bool file_exists(const std::string &filename)
file_exists: see the rheostream page for the full documentation
Definition scatch.icc:34
bool has_any_suffix(const string &name)
has_any_suffix: see the rheostream page for the full documentation