Chemical Data Processing Library C++ API - Version 1.4.0
Public Member Functions | List of all members
CDPL::Util::FileDataReader< ReaderImpl, DataType > Class Template Reference

Convenience wrapper that adapts a stream-based reader implementation ReaderImpl into a file-based Base::DataReader by opening an std::ifstream and forwarding all read operations to the wrapped reader. More...

#include <FileDataReader.hpp>

+ Inheritance diagram for CDPL::Util::FileDataReader< ReaderImpl, DataType >:

Public Member Functions

 FileDataReader (const std::string &file_name, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::binary)
 Constructs a FileDataReader instance that opens the file file_name in the given mode and forwards all read operations to a freshly constructed ReaderImpl wrapping the file stream. More...
 
FileDataReader & read (DataType &obj, bool overwrite=true)
 Reads the next record into obj via the wrapped reader. More...
 
FileDataReader & read (std::size_t idx, DataType &obj, bool overwrite=true)
 Reads the record at index idx into obj via the wrapped reader. More...
 
FileDataReader & skip ()
 Skips the next record via the wrapped reader. More...
 
bool hasMoreData ()
 Tells whether the wrapped reader has more records to read. More...
 
std::size_t getRecordIndex () const
 Returns the current record index of the wrapped reader. More...
 
void setRecordIndex (std::size_t idx)
 Sets the current record index of the wrapped reader. More...
 
std::size_t getNumRecords ()
 Returns the total number of records as reported by the wrapped reader. More...
 
 operator const void * () const
 Tells whether the reader is in a good (readable) state. More...
 
bool operator! () const
 Tells whether the reader is in a bad (non-readable) state. More...
 
void close ()
 Closes the wrapped reader and the underlying file stream. More...
 
- Public Member Functions inherited from CDPL::Base::DataReader< typename ReaderImpl::DataType >
virtual DataReader & read (DataType &obj, bool overwrite=true)=0
 Reads the data record at the current record index and stores the read data in obj. More...
 
virtual DataReader & read (std::size_t idx, DataType &obj, bool overwrite=true)=0
 Reads the data record at index idx and stores the read data in obj. More...
 
- Public Member Functions inherited from CDPL::Base::DataIOBase
std::size_t registerIOCallback (const IOCallbackFunction &func)
 Registers an I/O callback target function. More...
 
void unregisterIOCallback (std::size_t id)
 Unregisters the I/O callback function specified by id. More...
 
void invokeIOCallbacks (double progress) const
 Invokes all registered I/O callback functions with the argument *this. More...
 
void clearIOCallbacks ()
 Clears all registered I/O callback functions. More...
 
- Public Member Functions inherited from CDPL::Base::ControlParameterContainer
std::size_t getNumParameters () const
 Returns the number of container entries. More...
 
template<typename T >
void setParameter (const LookupKey &key, T &&val)
 Sets the value of the control-parameter specified by key to val. More...
 
const Any & getParameter (const LookupKey &key, bool throw_=false, bool local=false) const
 Returns the value of the control-parameter specified by key. More...
 
template<typename T >
const T & getParameter (const LookupKey &key, bool local=false) const
 Returns the value of the control-parameter specified by key as a const reference to an object of type T. More...
 
template<typename T >
const T & getParameterOrDefault (const LookupKey &key, const T &def_val, bool local=false) const
 Returns the value of the control-parameter specified by key as a const reference to an object of type T, or the default value def_val if an entry does not exist. More...
 
bool removeParameter (const LookupKey &key)
 Removes the entry for the control-parameter specified by key. More...
 
void clearParameters ()
 Erases all container entries. More...
 
bool isParameterSet (const LookupKey &key, bool local=false) const
 Tells whether or not a value has been assigned to the control-parameter specified by key. More...
 
void addParameters (const ControlParameterContainer &cntnr)
 Adds the control-parameter value entries of the ControlParameterContainer instance cntnr. More...
 
void copyParameters (const ControlParameterContainer &cntnr)
 Replaces the current control-parameter entries by a copy of the entries in cntnr. More...
 
ConstParameterIterator getParametersBegin () const
 Returns a constant iterator pointing to the beginning of the entries. More...
 
ConstParameterIterator getParametersEnd () const
 Returns a constant iterator pointing to the end of the entries. More...
 
ConstParameterIterator begin () const
 Returns a constant iterator pointing to the beginning of the entries. More...
 
ConstParameterIterator end () const
 Returns a constant iterator pointing to the end of the entries. More...
 
void setParent (const ControlParameterContainer *cntnr)
 Sets or removes the parent control-parameter container used to resolve requests for missing entries. More...
 
const ControlParameterContainer * getParent () const
 Returns a pointer to the parent control-parameter container. More...
 
std::size_t registerParameterChangedCallback (const ParameterChangedCallbackFunction &func)
 Registers a callback target function that gets invoked when the value of a control-parameter has changed. More...
 
void unregisterParameterChangedCallback (std::size_t id)
 Unregisters the callback specified by id. More...
 
std::size_t registerParameterRemovedCallback (const ParameterRemovedCallbackFunction &func)
 Registers a callback target function that gets invoked when a control-parameter entry has been removed. More...
 
void unregisterParameterRemovedCallback (std::size_t id)
 Unregisters the callback specified by id. More...
 
std::size_t registerParentChangedCallback (const ParentChangedCallbackFunction &func)
 Registers a callback target function that gets invoked when the parent container has been changed or was detached. More...
 
void unregisterParentChangedCallback (std::size_t id)
 Unregisters the callback specified by id. More...
 
const ControlParameterContainer & getParameters () const
 Returns a const reference to itself. More...
 

Additional Inherited Members

- Public Types inherited from CDPL::Base::DataReader< typename ReaderImpl::DataType >
typedef typename ReaderImpl::DataType DataType
 The type of the read data objects. More...
 
typedef std::shared_ptr< DataReader > SharedPointer
 A reference-counted smart pointer [SHPTR] for dynamically allocated DataReader instances. More...
 
- Public Types inherited from CDPL::Base::DataIOBase
typedef std::function< void(const DataIOBase &, double)> IOCallbackFunction
 A functor class used to wrap I/O callback target functions. More...
 
- Public Types inherited from CDPL::Base::ControlParameterContainer
typedef ParameterMap::value_type ParameterEntry
 A Base::LookupKey / Base::Any pair used to store the control-parameter values and associated keys. More...
 
typedef ParameterMap::const_iterator ConstParameterIterator
 A constant iterator used to iterate over the control-parameter entries. More...
 
typedef std::function< void(const LookupKey &, const Any &)> ParameterChangedCallbackFunction
 A functor class that wraps callback target functions which get invoked when the value of a control-parameter has changed. More...
 
typedef std::function< void(const LookupKey &)> ParameterRemovedCallbackFunction
 A functor class that wraps callback target functions which get invoked when a control-parameter entry has been removed. More...
 
typedef std::function< void()> ParentChangedCallbackFunction
 A functor class that wraps callback target functions which get invoked when the parent container has been changed or was detached. More...
 
- Protected Member Functions inherited from CDPL::Base::DataReader< typename ReaderImpl::DataType >
DataReader & operator= (const DataReader &reader)
 Assignment operator. More...
 
- Protected Member Functions inherited from CDPL::Base::DataIOBase
 DataIOBase ()
 Default constructor. More...
 
 DataIOBase (const DataIOBase &io_base)
 Copy constructor. More...
 
 ~DataIOBase ()
 Destructor. More...
 
DataIOBase & operator= (const DataIOBase &io_base)
 Assignment operator. More...
 
- Protected Member Functions inherited from CDPL::Base::ControlParameterContainer
 ControlParameterContainer ()
 Constructs an empty ControlParameterContainer instance. More...
 
 ControlParameterContainer (const ControlParameterContainer &cntnr)
 Constructs a copy of the ControlParameterContainer instance cntnr. More...
 
virtual ~ControlParameterContainer ()
 Virtual destructor. More...
 
ControlParameterContainer & operator= (const ControlParameterContainer &cntnr)
 Assignment operator. More...
 

Detailed Description

template<typename ReaderImpl, typename DataType = typename ReaderImpl::DataType>
class CDPL::Util::FileDataReader< ReaderImpl, DataType >

Convenience wrapper that adapts a stream-based reader implementation ReaderImpl into a file-based Base::DataReader by opening an std::ifstream and forwarding all read operations to the wrapped reader.

Template Parameters
ReaderImplThe underlying stream-based reader implementation type.
DataTypeThe data type read by ReaderImpl.

Constructor & Destructor Documentation

◆ FileDataReader()

template<typename ReaderImpl , typename DataType >
CDPL::Util::FileDataReader< ReaderImpl, DataType >::FileDataReader ( const std::string &  file_name,
std::ios_base::openmode  mode = std::ios_base::in | std::ios_base::binary 
)

Constructs a FileDataReader instance that opens the file file_name in the given mode and forwards all read operations to a freshly constructed ReaderImpl wrapping the file stream.

Parameters
file_nameThe path of the input file to open.
modeThe open mode of the underlying std::ifstream.
Exceptions
Base::IOErrorif the file could not be opened.

Member Function Documentation

◆ read() [1/2]

template<typename ReaderImpl , typename DataType >
CDPL::Util::FileDataReader< ReaderImpl, DataType > & CDPL::Util::FileDataReader< ReaderImpl, DataType >::read ( DataType &  obj,
bool  overwrite = true 
)

Reads the next record into obj via the wrapped reader.

Parameters
objThe output object.
overwriteIf true, the output object is cleared before the record is copied into it.
Returns
A reference to itself.
Exceptions
Base::IOErroron read failure.

◆ read() [2/2]

template<typename ReaderImpl , typename DataType >
CDPL::Util::FileDataReader< ReaderImpl, DataType > & CDPL::Util::FileDataReader< ReaderImpl, DataType >::read ( std::size_t  idx,
DataType &  obj,
bool  overwrite = true 
)

Reads the record at index idx into obj via the wrapped reader.

Parameters
idxThe zero-based record index.
objThe output object.
overwriteIf true, the output object is cleared before the record is copied into it.
Returns
A reference to itself.
Exceptions
Base::IOErroron read failure.

◆ skip()

template<typename ReaderImpl , typename DataType >
CDPL::Util::FileDataReader< ReaderImpl, DataType > & CDPL::Util::FileDataReader< ReaderImpl, DataType >::skip
virtual

Skips the next record via the wrapped reader.

Returns
A reference to itself.
Exceptions
Base::IOErroron read failure.

Implements CDPL::Base::DataReader< typename ReaderImpl::DataType >.

◆ hasMoreData()

template<typename ReaderImpl , typename DataType >
bool CDPL::Util::FileDataReader< ReaderImpl, DataType >::hasMoreData
virtual

Tells whether the wrapped reader has more records to read.

Returns
true if at least one more record is available, and false otherwise.

Implements CDPL::Base::DataReader< typename ReaderImpl::DataType >.

◆ getRecordIndex()

template<typename ReaderImpl , typename DataType >
std::size_t CDPL::Util::FileDataReader< ReaderImpl, DataType >::getRecordIndex
virtual

Returns the current record index of the wrapped reader.

Returns
The zero-based record index of the next record to read.

Implements CDPL::Base::DataReader< typename ReaderImpl::DataType >.

◆ setRecordIndex()

template<typename ReaderImpl , typename DataType >
void CDPL::Util::FileDataReader< ReaderImpl, DataType >::setRecordIndex ( std::size_t  idx)
virtual

Sets the current record index of the wrapped reader.

Parameters
idxThe new zero-based record index.

Implements CDPL::Base::DataReader< typename ReaderImpl::DataType >.

◆ getNumRecords()

template<typename ReaderImpl , typename DataType >
std::size_t CDPL::Util::FileDataReader< ReaderImpl, DataType >::getNumRecords
virtual

Returns the total number of records as reported by the wrapped reader.

Returns
The record count.

Implements CDPL::Base::DataReader< typename ReaderImpl::DataType >.

◆ operator const void *()

template<typename ReaderImpl , typename DataType >
CDPL::Util::FileDataReader< ReaderImpl, DataType >::operator const void *
virtual

Tells whether the reader is in a good (readable) state.

Returns
A non-nullptr pointer if the reader is in a good state, and nullptr otherwise.

Implements CDPL::Base::DataReader< typename ReaderImpl::DataType >.

◆ operator!()

template<typename ReaderImpl , typename DataType >
bool CDPL::Util::FileDataReader< ReaderImpl, DataType >::operator!
virtual

Tells whether the reader is in a bad (non-readable) state.

Returns
true if the reader is in a bad state, and false otherwise.

Implements CDPL::Base::DataReader< typename ReaderImpl::DataType >.

◆ close()

template<typename ReaderImpl , typename DataType >
void CDPL::Util::FileDataReader< ReaderImpl, DataType >::close
virtual

Closes the wrapped reader and the underlying file stream.

Reimplemented from CDPL::Base::DataReader< typename ReaderImpl::DataType >.


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