29 #ifndef CDPL_UTIL_FILEDATAREADER_HPP
30 #define CDPL_UTIL_FILEDATAREADER_HPP
49 template <
typename ReaderImpl,
typename DataType =
typename ReaderImpl::DataType>
55 std::ios_base::openmode mode = std::ios_base::in | std::ios_base::binary);
71 operator const void*()
const;
87 template <
typename ReaderImpl,
typename DataType>
89 stream(file_name.c_str(), mode), fileName(file_name), reader(stream)
94 reader.setParent(
this);
98 template <
typename ReaderImpl,
typename DataType>
103 reader.
read(obj, overwrite);
105 }
catch (
const std::exception& e) {
106 throw Base::IOError(
"FileDataReader: while reading file '" + fileName +
"': " + e.what());
112 template <
typename ReaderImpl,
typename DataType>
117 reader.
read(idx, obj, overwrite);
119 }
catch (
const std::exception& e) {
120 throw Base::IOError(
"FileDataReader: while reading file '" + fileName +
"': " + e.what());
126 template <
typename ReaderImpl,
typename DataType>
133 }
catch (
const std::exception& e) {
134 throw Base::IOError(
"FileDataReader: while reading file '" + fileName +
"': " + e.what());
140 template <
typename ReaderImpl,
typename DataType>
143 return reader.hasMoreData();
146 template <
typename ReaderImpl,
typename DataType>
149 return reader.getRecordIndex();
152 template <
typename ReaderImpl,
typename DataType>
155 reader.setRecordIndex(idx);
158 template <
typename ReaderImpl,
typename DataType>
161 return reader.getNumRecords();
164 template <
typename ReaderImpl,
typename DataType>
167 return reader.operator
const void*();
170 template <
typename ReaderImpl,
typename DataType>
173 return reader.operator!();
176 template <
typename ReaderImpl,
typename DataType>
Definition of exception classes.
Definition of class CDPL::Base::DataReader.
void invokeIOCallbacks(double progress) const
Invokes all registered I/O callback functions with the argument *this.
An interface for reading data objects of a given type from an arbitrary data source.
Definition: DataReader.hpp:73
typename ReaderImpl::DataType DataType
The type of the read data objects.
Definition: DataReader.hpp:79
Thrown to indicate that an I/O operation has failed because of physical (e.g. broken pipe) or logical...
Definition: Base/Exceptions.hpp:250
FileDataReader.
Definition: FileDataReader.hpp:51
void close()
Performs a reader specific shutdown operation (if required).
Definition: FileDataReader.hpp:177
bool hasMoreData()
Tells if there are any data records left to read.
Definition: FileDataReader.hpp:141
FileDataReader(const std::string &file_name, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::binary)
Definition: FileDataReader.hpp:88
FileDataReader & read(DataType &obj, bool overwrite=true)
Definition: FileDataReader.hpp:100
std::size_t getNumRecords()
Returns the total number of available data records.
Definition: FileDataReader.hpp:159
void setRecordIndex(std::size_t idx)
Sets the index of the current data record to idx.
Definition: FileDataReader.hpp:153
bool operator!() const
Tells whether the reader is in a bad state.
Definition: FileDataReader.hpp:171
std::size_t getRecordIndex() const
Returns the index of the current data record.
Definition: FileDataReader.hpp:147
FileDataReader & skip()
Skips the data record at the current record index.
Definition: FileDataReader.hpp:128
The namespace of the Chemical Data Processing Library.