Loading...
Searching...
No Matches
rheostream.h
Go to the documentation of this file.
#ifndef _RHEOLEF_STREAM_H
#define _RHEOLEF_STREAM_H
// author: Pierre.Saramito@imag.fr
// date: 31 october 1997
namespace rheolef {
}// namespace rheolef
#include "rheolef/compiler.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wparentheses"
#include <boost/iostreams/filtering_stream.hpp>
#pragma GCC diagnostic pop
namespace rheolef {
// input & output modes:
namespace io {
typedef enum {
out = 0,
app = 1, // append mode
gz = 0, // default is to use gzip
nogz = 2 // force not using gzip
} mode_type;
}
// [verbatim_irheostream]
class irheostream : public boost::iostreams::filtering_stream<boost::iostreams::input> {
public:
irheostream() : boost::iostreams::filtering_stream<boost::iostreams::input>(), _ifs() {}
irheostream(const std::string& name, const std::string& suffix = std::string());
virtual ~irheostream();
void open (const std::string& name, const std::string& suffix = std::string());
void close();
// [verbatim_irheostream]
protected:
std::ifstream _ifs;
// [verbatim_irheostream_cont]
};
// [verbatim_irheostream_cont]
static const bool dont_gzip = false;
// [verbatim_orheostream]
class orheostream : public boost::iostreams::filtering_stream<boost::iostreams::output> {
public:
orheostream() : boost::iostreams::filtering_stream<boost::iostreams::output>(), _mode(), _full_name() {}
orheostream(const std::string& name, const std::string& suffix = std::string(),
io::mode_type mode = io::out);
virtual ~orheostream();
void open (const std::string& name, const std::string& suffix = std::string(),
io::mode_type mode = io::out);
void flush();
void close();
const std::string& filename() const { return _full_name; }
// [verbatim_orheostream]
protected:
void _open_internal (io::mode_type mode);
void _close_internal ();
// data:
io::mode_type _mode;
std::string _full_name;
// [verbatim_orheostream_cont]
};
// [verbatim_orheostream_cont]
// [verbatim_functions]
// float-to-string conversion
std::string ftos (const Float& x);
// catch first occurrence of string in file
bool scatch (std::istream& in, const std::string& ch, bool full_match = true);
// has_suffix("toto.suffix", "suffix") -> true
bool has_suffix (const std::string& name, const std::string& suffix);
// "toto.suffix" --> "toto"
std::string delete_suffix (const std::string& name, const std::string& suffix);
// has_any_suffix("toto.any_suffix") -> true
bool has_any_suffix (const std::string& name);
// delete_any_suffix("toto.any_suffix") --> "toto"
std::string delete_any_suffix (const std::string& name);
// "/usr/local/dir/toto.suffix" --> "toto.suffix"
std::string get_basename (const std::string& name);
// "/usr/local/dir/toto.suffix" --> "/usr/local/dir"
std::string get_dirname (const std::string& name);
// "toto" --> "/usr/local/math/data/toto.suffix"
std::string get_full_name_from_rheo_path (const std::string& rootname, const std::string& suffix);
// "." + "../geodir" --> ".:../geodir"
void append_dir_to_rheo_path (const std::string& dir);
// "../geodir" + "." --> "../geodir:."
void prepend_dir_to_rheo_path (const std::string& dir);
// predicate when a file exists
bool file_exists (const std::string& filename);
// is_float("3.14") -> true
bool is_float (const std::string&);
// string-to-float conversion
Float to_float (const std::string&);
// in TMPDIR environment variable or "/tmp" by default
std::string get_tmpdir();
// [verbatim_functions]
// integer-to-string conversion (backward compatibility)
inline std::string itos (std::size_t i) { return std::to_string(i); }
}// namespace rheolef
#endif // _RHEOLEF_STREAM_H
Float
see the Float page for the full documentation
rheolef::irheostream
Definition rheostream.h:179
rheolef::irheostream::_ifs
std::ifstream _ifs
Definition rheostream.h:188
rheolef::irheostream::irheostream
irheostream()
Definition rheostream.h:181
rheolef::irheostream::close
void close()
Definition rheostream.cc:192
rheolef::irheostream::~irheostream
virtual ~irheostream()
Definition rheostream.cc:205
rheolef::irheostream::open
void open(const std::string &name, const std::string &suffix=std::string())
Definition rheostream.cc:162
rheolef::orheostream
Definition rheostream.h:194
rheolef::orheostream::_open_internal
void _open_internal(io::mode_type mode)
Definition rheostream.cc:101
rheolef::orheostream::orheostream
orheostream()
Definition rheostream.h:196
rheolef::orheostream::filename
const std::string & filename() const
Definition rheostream.h:204
rheolef::orheostream::close
void close()
Definition rheostream.cc:143
rheolef::orheostream::_close_internal
void _close_internal()
Definition rheostream.cc:115
rheolef::orheostream::_mode
io::mode_type _mode
Definition rheostream.h:210
rheolef::orheostream::~orheostream
virtual ~orheostream()
Definition rheostream.cc:75
rheolef::orheostream::_full_name
std::string _full_name
Definition rheostream.h:211
rheolef::orheostream::flush
void flush()
Definition rheostream.cc:150
rheolef::orheostream::open
void open(const std::string &name, const std::string &suffix=std::string(), io::mode_type mode=io::out)
Definition rheostream.cc:80
rheolef::dont_gzip
static const bool dont_gzip
Definition rheostream.h:192
boost
Definition mpi_pair_datatype.h:51
rheolef::io::mode_type
mode_type
Definition rheostream.h:171
rheolef::io::gz
@ gz
Definition rheostream.h:174
rheolef::io::out
@ out
Definition rheostream.h:172
rheolef::io::app
@ app
Definition rheostream.h:173
rheolef::io::nogz
@ nogz
Definition rheostream.h:175
rheolef
This file is part of Rheolef.
Definition compiler_eigen.h:39
rheolef::get_dirname
string get_dirname(const string &name)
get_dirname: see the rheostream page for the full documentation
Definition rheostream.cc:267
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:226
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:343
rheolef::itos
std::string itos(std::size_t i)
Definition rheostream.h:279
rheolef::to_float
Float to_float(const string &s)
to_float: see the rheostream page for the full documentation
Definition rheostream.cc:498
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:44
rheolef::get_basename
string get_basename(const string &name)
get_basename: see the rheostream page for the full documentation
Definition rheostream.cc:258
rheolef::get_tmpdir
std::string get_tmpdir()
get_tmpdir: see the rheostream page for the full documentation
Definition rheostream.cc:54
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:212
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:334
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:243
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:449
rheolef::is_float
bool is_float(const string &s)
is_float: see the rheostream page for the full documentation
Definition rheostream.cc:480
rheolef::ftos
string ftos(const Float &x)
itof: see the rheostream page for the full documentation
Definition rheostream.cc:59
rheolef::file_exists
bool file_exists(const std::string &filename)
file_exists: see the rheostream page for the full documentation
Definition scatch.icc:34
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:233