29 #ifndef CDPL_UTIL_FILEDATAREADER_HPP
30 #define CDPL_UTIL_FILEDATAREADER_HPP
53 template <
typename ReaderImpl,
typename DataType =
typename ReaderImpl::DataType>
66 std::ios_base::openmode mode = std::ios_base::in | std::ios_base::binary);
122 operator const void*()
const;
136 std::ifstream stream;
137 std::string fileName;
146 template <
typename ReaderImpl,
typename DataType>
148 stream(file_name.c_str(), mode), fileName(file_name), reader(stream)
153 reader.setParent(
this);
157 template <
typename ReaderImpl,
typename DataType>
162 reader.
read(obj, overwrite);
164 }
catch (
const std::exception& e) {
165 throw Base::IOError(
"FileDataReader: while reading file '" + fileName +
"': " + e.what());
171 template <
typename ReaderImpl,
typename DataType>
176 reader.
read(idx, obj, overwrite);
178 }
catch (
const std::exception& e) {
179 throw Base::IOError(
"FileDataReader: while reading file '" + fileName +
"': " + e.what());
185 template <
typename ReaderImpl,
typename DataType>
192 }
catch (
const std::exception& e) {
193 throw Base::IOError(
"FileDataReader: while reading file '" + fileName +
"': " + e.what());
199 template <
typename ReaderImpl,
typename DataType>
202 return reader.hasMoreData();
205 template <
typename ReaderImpl,
typename DataType>
208 return reader.getRecordIndex();
211 template <
typename ReaderImpl,
typename DataType>
214 reader.setRecordIndex(idx);
217 template <
typename ReaderImpl,
typename DataType>
220 return reader.getNumRecords();
223 template <
typename ReaderImpl,
typename DataType>
226 return reader.operator
const void*();
229 template <
typename ReaderImpl,
typename DataType>
232 return reader.operator!();
235 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.
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
Convenience wrapper that adapts a stream-based reader implementation ReaderImpl into a file-based Bas...
Definition: FileDataReader.hpp:55
void close()
Closes the wrapped reader and the underlying file stream.
Definition: FileDataReader.hpp:236
bool hasMoreData()
Tells whether the wrapped reader has more records to read.
Definition: FileDataReader.hpp:200
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...
Definition: FileDataReader.hpp:147
FileDataReader & read(DataType &obj, bool overwrite=true)
Reads the next record into obj via the wrapped reader.
Definition: FileDataReader.hpp:159
std::size_t getNumRecords()
Returns the total number of records as reported by the wrapped reader.
Definition: FileDataReader.hpp:218
void setRecordIndex(std::size_t idx)
Sets the current record index of the wrapped reader.
Definition: FileDataReader.hpp:212
bool operator!() const
Tells whether the reader is in a bad (non-readable) state.
Definition: FileDataReader.hpp:230
std::size_t getRecordIndex() const
Returns the current record index of the wrapped reader.
Definition: FileDataReader.hpp:206
FileDataReader & skip()
Skips the next record via the wrapped reader.
Definition: FileDataReader.hpp:187
The namespace of the Chemical Data Processing Library.