Text file implementations¶
-
class TextFileImpl¶
Abstract base class for readers used by text files. This is specialized for compressed files, and might get extended to network or memory mapped files.
Any failed operation should throw a
chemfiles::FileError
.Subclassed by chemfiles::Bz2File, chemfiles::GzFile, chemfiles::MemoryFile, chemfiles::PlainFile, chemfiles::XzFile
Public Functions
-
virtual void clear() noexcept = 0¶
clear error and eof flags on the file
-
virtual void seek(uint64_t position) = 0¶
Set file indicator to
position
characters after the start of the file.- Throws:
FileError – in case of I/O error while seeking
-
virtual void clear() noexcept = 0¶
-
class PlainFile : public chemfiles::TextFileImpl¶
Simple TextFileImpl reading plain, uncompressed files using
FILE*
.Public Functions
-
PlainFile(const std::string &path, File::Mode mode)¶
Open a text file with name
filename
and modemode
.
-
virtual size_t read(char *data, size_t count) override¶
Fill up the
data
buffer reading at mostcount
characters from the file.Returns the amount of characters read. A return value of 0 indicates that the end of file has been reached.
- Throws:
FileError – in case of I/O error
-
virtual void write(const char *data, size_t count) override¶
Write
count
characters starting atdata
to the file.- Throws:
FileError – if it could not write all of the data to the file
-
virtual void clear() noexcept override¶
clear error and eof flags on the file
-
PlainFile(const std::string &path, File::Mode mode)¶
-
class MemoryFile : public chemfiles::TextFileImpl¶
Simple TextFile implementation, that wraps memory for reading only.
Public Functions
Open
memory
as though it were a file in modemode
. No copy ofmemory
is made and the original object MUST not be freed until this object is destroyed
-
virtual size_t read(char *data, size_t count) override¶
Fill up the
data
buffer reading at mostcount
characters from the file.Returns the amount of characters read. A return value of 0 indicates that the end of file has been reached.
- Throws:
FileError – in case of I/O error
-
virtual void write(const char *data, size_t count) override¶
Write
count
characters starting atdata
to the file.- Throws:
FileError – if it could not write all of the data to the file
-
inline virtual void clear() noexcept override¶
clear error and eof flags on the file
-
class GzFile : public chemfiles::TextFileImpl¶
An implementation of TextFile for gzip files.
Public Functions
-
GzFile(const std::string &path, File::Mode mode)¶
Open a text file with name
filename
and modemode
.
-
virtual size_t read(char *data, size_t count) override¶
Fill up the
data
buffer reading at mostcount
characters from the file.Returns the amount of characters read. A return value of 0 indicates that the end of file has been reached.
- Throws:
FileError – in case of I/O error
-
virtual void write(const char *data, size_t count) override¶
Write
count
characters starting atdata
to the file.- Throws:
FileError – if it could not write all of the data to the file
-
virtual void clear() noexcept override¶
clear error and eof flags on the file
-
GzFile(const std::string &path, File::Mode mode)¶
-
class XzFile : public chemfiles::TextFileImpl¶
An implementation of TextFile for lzma/xz files.
Public Functions
-
XzFile(const std::string &path, File::Mode mode)¶
Open a text file with name
filename
and modemode
.
-
virtual size_t read(char *data, size_t count) override¶
Fill up the
data
buffer reading at mostcount
characters from the file.Returns the amount of characters read. A return value of 0 indicates that the end of file has been reached.
- Throws:
FileError – in case of I/O error
-
virtual void write(const char *data, size_t count) override¶
Write
count
characters starting atdata
to the file.- Throws:
FileError – if it could not write all of the data to the file
-
virtual void clear() noexcept override¶
clear error and eof flags on the file
-
XzFile(const std::string &path, File::Mode mode)¶
-
class Bz2File : public chemfiles::TextFileImpl¶
An implementation of TextFile for bzip2 files.
Public Functions
-
Bz2File(const std::string &path, File::Mode mode)¶
Open a text file with name
filename
and modemode
.
-
virtual size_t read(char *data, size_t count) override¶
Fill up the
data
buffer reading at mostcount
characters from the file.Returns the amount of characters read. A return value of 0 indicates that the end of file has been reached.
- Throws:
FileError – in case of I/O error
-
virtual void write(const char *data, size_t count) override¶
Write
count
characters starting atdata
to the file.- Throws:
FileError – if it could not write all of the data to the file
-
virtual void clear() noexcept override¶
clear error and eof flags on the file
-
Bz2File(const std::string &path, File::Mode mode)¶