SHORE API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
shore::ostreams Class Reference

Manages an array of output streams. More...

Inheritance diagram for shore::ostreams:
shore::streams_base

Public Types

enum  FileExistsOp { EXISTS_FAIL, EXISTS_REPLACE, EXISTS_APPEND }
 Specifies behaviour when trying to open an existing file.
 
enum  ErrorCheck { ERRCHECK_MANUAL, ERRCHECK_AUTO }
 
- Public Types inherited from shore::streams_base
enum  Codec { CODEC_PLAIN, CODEC_GZIP, CODEC_XZ }
 Supported compression codecs.
 
enum  RandomAccessGranularity { GRANULARITY_FAST, GRANULARITY_MEDIUM, GRANULARITY_SLOW }
 Presets for compression block sizes.
 

Public Member Functions

 ostreams ()
 Default constructor.
 
 ostreams (const std::string &fn, const FileExistsOp exo=EXISTS_FAIL)
 
 ostreams (const std::vector< std::string > &fn, const FileExistsOp exo=EXISTS_FAIL)
 
template<class Iter >
 ostreams (Iter f_beg, Iter f_end, const FileExistsOp exo=EXISTS_FAIL)
 
 ~ostreams ()
 Destructor.
 
void set_enc_blocksize (const size_t bs)
 Set the encoder block size for opening compressed files.
 
void set_enc_blocksize (const RandomAccessGranularity g)
 Set the encoder block size for opening compressed files using one of the presets.
 
std::ostream & open_file (const std::string &fn, const FileExistsOp exo=EXISTS_FAIL, const ErrorCheck ec=ERRCHECK_AUTO)
 Open a file, interpreting special file names and automatically set compression based on the file name. More...
 
std::ostream & open_file (const std::string &fn, const Codec c, const FileExistsOp exo=EXISTS_FAIL, const ErrorCheck ec=ERRCHECK_AUTO)
 Open a file, interpreting special file names. More...
 
template<class Iter >
void open_files (Iter f_beg, Iter f_end, const FileExistsOp exo=EXISTS_FAIL)
 Open files, interpreting special file names and automatically set compression based on the file name.
 
std::ostream & open_normalfile (const std::string &fn, const Codec c=CODEC_PLAIN, const FileExistsOp exists_op=EXISTS_FAIL, const ErrorCheck ec=ERRCHECK_AUTO)
 Open a file with name fn.
 
std::ostream & open_tempfile (const std::string &pathprefix, const std::string &rename_name, const Codec c=default_fastenc(), const FileExistsOp exists_op=EXISTS_FAIL, const ErrorCheck ec=ERRCHECK_AUTO)
 Open a temporary file. More...
 
std::ostream & open_tempfile (const std::string &pathprefix, const Codec c, const ErrorCheck ec=ERRCHECK_AUTO)
 Open a temporary file that is deleted on destruct.
 
std::ostream & open_tempfile (const std::string &pathprefix, const ErrorCheck ec=ERRCHECK_AUTO)
 Open a temporary file using DEFAULT_FASTENC that is deleted on destruct.
 
std::ostream & open_tmpdir_file (const std::string &fn_prefix, const Codec c, const ErrorCheck ec=ERRCHECK_AUTO)
 Open a temporary file in the current temporary file directory that is deleted on destruct.
 
std::ostream & open_tmpdir_file (const std::string &fn_prefix, const ErrorCheck ec=ERRCHECK_AUTO)
 Open a temporary file int the current temporary file directory using DEFAULT_FASTENC in that is deleted on destruct.
 
std::ostream & open_pipe (const std::string &command, const Codec c=CODEC_PLAIN, const ErrorCheck ec=ERRCHECK_AUTO)
 Open a pipe.
 
std::ostream & push_back (std::ostream &os, const std::string &name=std::string(), const Codec c=CODEC_PLAIN, const ErrorCheck ec=ERRCHECK_AUTO)
 Add a stream.
 
void add_codec (const size_t index, const Codec c, const ErrorCheck ec=ERRCHECK_AUTO)
 Change compression type for the given stream.
 
void write_error_check (const int index, const std::string &label=std::string())
 Check if the stream with the given index is in an error state, and if so throw an informative exception.
 
void close_all ()
 Close all streams. The file informations and size() remain unaltered.
 
void close_stream (const std::ostream *const s)
 Close the stream that corresponds to the pointer s.
 
void close_stream (const size_t i)
 Close one of the streams.
 
void close_stream (const int i)
 Close one of the streams.
 
size_t size () const
 Get the number of opened streams.
 
std::ostream & operator[] (int n)
 Get one of the opened streams.
 
std::ostream & front ()
 Get the last of the opened streams.
 
std::ostream & back ()
 Get the last of the opened streams.
 
const std::string & get_streamname (const size_t i) const
 Get the name of one of the opened streams.
 

Static Public Member Functions

static void set_default_enc (const Codec c)
 Set the default output file compression type (plain, xz, gz).
 
static void set_default_fastenc (const Codec c)
 Set a default compression type that may be used for temporary data.
 
static void set_default_enc_bs (const size_t t)
 Set the default block size for compression.
 
static void set_default_enc_bs (const RandomAccessGranularity g)
 Set the default block size for compression using a preset.
 
static Codec default_enc ()
 Get the default output file compression type (plain, xz, gz).
 
static size_t default_enc_bs ()
 Get the default block size for compression.
 
static Codec default_fastenc ()
 Get default compression type that may be used for temporary data.
 
static const std::string & default_ext ()
 Get the default file name extension for compressed files.
 
static void write_error_check (std::ostream &s, const std::string &stream_name, const std::string &label=std::string())
 Check if the given stream is in an error state, and if so throw an informative exception.
 

Additional Inherited Members

- Static Public Attributes inherited from shore::streams_base
static const int BLOCKSIZE_PRESET_VALUES [3]
 
static const std::string COMPRESSION_FILEEXTS [3]
 Recognized compression file name extensions.
 

Detailed Description

Manages an array of output streams.

Member Function Documentation

std::ostream& shore::ostreams::open_file ( const std::string &  fn,
const FileExistsOp  exo = EXISTS_FAIL,
const ErrorCheck  ec = ERRCHECK_AUTO 
)

Open a file, interpreting special file names and automatically set compression based on the file name.

File names "stdout" and "-" open standard output, "stderr" opens standard error, "null" opens a null stream, "|*" opens a pipe, "*~" opens a temporary file that is renamed to "*" on close.

std::ostream& shore::ostreams::open_file ( const std::string &  fn,
const Codec  c,
const FileExistsOp  exo = EXISTS_FAIL,
const ErrorCheck  ec = ERRCHECK_AUTO 
)

Open a file, interpreting special file names.

File names "stdout" and "-" open standard output, "stderr" opens standard error, "null" opens a null stream, "|*" opens a pipe, "*~" opens a temporary file that is renamed to "*" on close.

std::ostream& shore::ostreams::open_tempfile ( const std::string &  pathprefix,
const std::string &  rename_name,
const Codec  c = default_fastenc(),
const FileExistsOp  exists_op = EXISTS_FAIL,
const ErrorCheck  ec = ERRCHECK_AUTO 
)

Open a temporary file.

Parameters
path_prefixPrefix of the temporary file name.
rename_nameFile will be renamed to this name when closed, or deleted by the destructor if rename_name is empty.
cCompression codec.
exists_opSpecifies whether it is OK to overwrite rename_name. The file will only be overwritten in an explicit close() or close_all(), but not by the destructor. EXISTS_APPEND is not allowed.

The documentation for this class was generated from the following file: