Public Member Functions | Private Attributes | List of all members
ecl::SharedFile Class Reference

Multi-instance (also thread-safe) output file device. More...

#include <shared_file.hpp>

Public Member Functions

unsigned int count ()
 Denotes how many instances are currently sharing this file. More...
 
const Errorerror () const
 
bool flush () ecl_debug_throw_decl(StandardException)
 Flush the internal buffer. More...
 
bool open (const std::string &name, WriteMode mode=New) ecl_throw_decl(StandardException)
 Opens the file for writing. More...
 
bool open ()
 Status flag indicating if the file is open/closed. More...
 
 SharedFile ()
 Non-RAII style constructor, doesn't open a file. More...
 
 SharedFile (const std::string &name, WriteMode mode=New) ecl_throw_decl(StandardException)
 Either opens a file for writing or a link to an existing shared instance. More...
 
long write (const char &c) ecl_debug_throw_decl(StandardException)
 Write a character to the buffer. More...
 
long write (const char *s, unsigned long n) ecl_debug_throw_decl(StandardException)
 Write a character string to the buffer. More...
 
virtual ~SharedFile ()
 Automatic cleaner for shared files. More...
 

Private Attributes

devices::CharBuffer buffer
 
devices::SharedFileCommonshared_instance
 

Detailed Description

Multi-instance (also thread-safe) output file device.

This allows multiple instantiations/connections (uniquely identified by string file name) to an OFile device. Each instantiation has its own buffer that protects data from multiple sources getting unnecessarily tangled. It is also thread-safe.

Usage:

Usage is exactly the same as that for regular OFile devices except that no new files are made if the same file name is used (instead, instantiations share this file). Everything else happens under the hood and cleanup occurs in the destructors.

See also
OFile.

Definition at line 118 of file shared_file.hpp.

Constructor & Destructor Documentation

ecl::SharedFile::SharedFile ( )
inline

Non-RAII style constructor, doesn't open a file.

Sometimes its more convenient to open manually rather than inside constructors. Use this with the open() command to do so. You can check for open status via the open accessor.

Definition at line 130 of file shared_file.hpp.

ecl::SharedFile::SharedFile ( const std::string &  name,
WriteMode  mode = New 
)

Either opens a file for writing or a link to an existing shared instance.

If a file by this name is not yet being shared, then it opens it directly. Otherwise it opens a link to the shared instance. Note, you may ignore the second argument (mode) if you are simply opening a second link to the shared instance.

Parameters
name: filename.
mode: mode for writing (New, Append), this must be the same for all instances.
Exceptions
StandardException: throws if the file could not be opened.

Definition at line 135 of file shared_file.cpp.

ecl::SharedFile::~SharedFile ( )
virtual

Automatic cleaner for shared files.

Automatically cleans up and closes io handles.

Definition at line 145 of file shared_file.cpp.

Member Function Documentation

unsigned int ecl::SharedFile::count ( )
inline

Denotes how many instances are currently sharing this file.

Denotes how many instances are currently sharing this file.

Returns
unsigned int : the number of shared instances.

Definition at line 178 of file shared_file.hpp.

const Error& ecl::SharedFile::error ( ) const
inline

Definition at line 230 of file shared_file.hpp.

bool ecl::SharedFile::flush ( )

Flush the internal buffer.

This writes to the shared file. Error handling the same for OFile's write function.

Exceptions
StandardException: throws from the underlying file if flushing returned an error [debug mode only].
See also
OFile

Definition at line 194 of file shared_file.cpp.

bool ecl::SharedFile::open ( const std::string &  name,
WriteMode  mode = New 
)

Opens the file for writing.

Configures and opens the file for writing in either New or Append mode. Note, that you don't need to do this if you constructed this class with the RAII style constructor as it gets automatically called.

Error handling the same for OFile's open() call.

Parameters
name: name of the file to open.
mode: mode of writing, either New or Append.
Exceptions
StandardException: throws if the connection failed to open.
See also
OFile

Definition at line 155 of file shared_file.cpp.

bool ecl::SharedFile::open ( )
inline

Status flag indicating if the file is open/closed.

Returns
bool : true if open, false otherwise.

Definition at line 188 of file shared_file.hpp.

long ecl::SharedFile::write ( const char &  c)

Write a character to the buffer.

Write a character to the buffer. It will automatically flush (write to the shared ofile instance) if the buffer exceeds its capacity.

Error handling the same for OFile's write function.

Parameters
c: the character to write.
Returns
long : the number of bytes written.
Exceptions
StandardException: throws from the underlying file if writing returned an error [debug mode only].
See also
OFile

Definition at line 171 of file shared_file.cpp.

long ecl::SharedFile::write ( const char *  s,
unsigned long  n 
)

Write a character string to the buffer.

Write a character string to the buffer. It will automatically flush (write to the shared ofile instance) if the buffer exceeds its capacity.

Error handling the same for OFile's write function.

Parameters
s: points to the beginning of the character string.
n: the number of characters to write.
Returns
long: the number of bytes written.
Exceptions
StandardException: throws from the underlying file if flushing returned an error [debug mode only].
See also
OFile

Definition at line 181 of file shared_file.cpp.

Member Data Documentation

devices::CharBuffer ecl::SharedFile::buffer
private

Definition at line 234 of file shared_file.hpp.

devices::SharedFileCommon* ecl::SharedFile::shared_instance
private

Definition at line 233 of file shared_file.hpp.


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


ecl_devices
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:08:46