.\" .de Id .. .de Sp .if n .sp .if t .sp 0.4 .. .TH rheostream 2rheolef "rheolef-7.0" "rheolef-7.0" "rheolef-7.0" .\" label: /*Class:rheostream .SH NAME \fBirheostream\fP, \fBorheostream\fP - large data streams .\" skip: @clindex irheostream .\" skip: @clindex orheostream .\" skip: @clindex iorheo .\" skip: @fiindex @file{.gz} gzip .\" skip: @cindex RHEOPATH environment variable .\" skip: @findex scatch .\" skip: @findex has_suffix .\" skip: @findex delete_suffix .\" skip: @findex get_basename .\" skip: @findex get_dirname .\" skip: @findex get_full_name_from_rheo_path .\" skip: @findex append_dir_to_rheo_path .\" skip: @findex prepend_dir_to_rheo_path .\" skip: @findex file_exists .\" skip: @findex itos .\" skip: @findex ftos .\" skip: @toindex @code{gzip} .SH ABSTRACT This class provides a stream interface for large data management. File decompresion is assumed using \fBgzip\fP and a recursive search in a directory list is provided for input. .\" begin_example .Sp .nf orheostream foo("NAME", "suffix"); .Sp .fi .\" end_example is like .\" begin_example .Sp .nf ofstream foo("NAME.suffix"). .Sp .fi .\" end_example However, if \fINAME\fP does not end with `\fB.suffix'\fP, then `\fB.suffix'\fP is automatically added. By default, compression is performed on the fly with gzip, adding an additional `\fB.gz'\fP suffix. The \fBflush\fP action is nicely handled in compression mode: .\" begin_example .Sp .nf foo.flush(); .Sp .fi .\" end_example This feature allows intermediate results to be available during long computations. The compression can be deactivated while opening a file by an optional argument: .\" begin_example .Sp .nf orheostream foo("NAME", "suffix", io::nogz); .Sp .fi .\" end_example An existing compressed file can be reopen in \fBappend\fP mode: new results will be appended at the end of an existing file: .\" begin_example .Sp .nf orheostream foo("NAME", "suffix", io::app); .Sp .fi .\" end_example .PP Conversely, .\" begin_example .Sp .nf irheostream foo("NAME","suffix"); .Sp .fi .\" end_example is like .\" begin_example .Sp .nf ifstream foo("NAME.suffix"). .Sp .fi .\" end_example However, we look at a search path environment variable \fBRHEOPATH\fP in order to find \fINAME\fP while suffix is assumed. Moreover, \fBgzip\fP compressed files, ending with the `\fB.gz'\fP suffix is assumed, and decompression is done. .PP Finally, a set of useful functions are provided. .SH DESCRIPTION The following code: .\" begin_example .Sp .nf irheostream is("results", "data"); .Sp .fi .\" end_example will recursively look for a `\fBresults[.data[.gz]]'\fP file in the directory mentioned by the \fBRHEOPATH\fP environment variable. .PP For instance, if you insert in our ".cshrc" something like: .\" begin_example .Sp .nf setenv RHEOPATH ".:/home/dupont:/usr/local/math/demo" .Sp .fi .\" end_example the process will study the current directory `\fB.'\fP, then, if neither `\fBsquare.data.gz'\fP nor `\fBsquare.data'\fP exits, it scan all subdirectory of the current directory. Then, if file is not founded, it start recusively in `\fB/home/dupond'\fP and then in `\fB/usr/local/math/demo'\fP. .PP File decompression is performed by using the \fBgzip\fP command, and data are pipe-lined directly in memory. .PP .PP If the file start with `\fB.'\fP as `\fB./square'\fP or with a `\fB/'\fP as `\fB/home/oscar/square'\fP, no search occurs and \fBRHEOPATH\fP environment variable is not used. .PP Also, if the environment variable \fBRHEOPATH\fP is not set, the default value is the current directory `\fB.'\fP. .PP For output stream: .\" begin_example .Sp .nf orheostream os("newresults", "data"); .Sp .fi .\" end_example file compression is assumed, and "newresults.data.gz" will be created. .PP File loading and storing are mentioned by a message, either: .\" begin_example .Sp .nf ! load "./results.data.gz" .Sp .fi .\" end_example or: .\" begin_example .Sp .nf ! file "./newresults.data.gz" created. .Sp .fi .\" end_example on the \fBclog\fP stream. By adding the following: .\" begin_example .Sp .nf clog << noverbose; .Sp .fi .\" end_example you turn off these messages (see iorheo(4)). .PP .\" skip start:AUTHORS: .\" skip start:DATE: .\" skip start:METHODS: .\" END .SH IMPLEMENTATION .\" begin_example .Sp .nf class irheostream : public boost::iostreams::filtering_stream { public: irheostream() : boost::iostreams::filtering_stream() {} 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(); protected: std::ifstream _ifs; }; static const bool dont_gzip = false; class orheostream : public boost::iostreams::filtering_stream { public: orheostream() : boost::iostreams::filtering_stream() {} 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; } protected: void _open_internal (io::mode_type mode); void _close_internal (); // data: io::mode_type _mode; std::string _full_name; }; std::string itos (std::string::size_type i); 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); bool file_exists (const std::string& filename); // string to float bool is_float (const std::string&); Float to_float (const std::string&); // in TMPDIR environment variable or "/tmp" by default std::string get_tmpdir(); .Sp .fi .\" end_example .\" LENGTH = 1 .SH SEE ALSO iorheo(4) .SH COPYRIGHT Copyright (C) 2000-2018 Pierre Saramito GPLv3+: GNU GPL version 3 or later . This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.