File
classes¶
The File
classes provide abstraction of the IO operation, allowing for the
same format to be used with on-disk files, network files, memory-mapped files,
compressed files, etc.
Interface for files¶
-
class
File
¶ Abstract base class for file representation.
Subclassed by chemfiles::NcFile, chemfiles::TextFile, chemfiles::TNGFile
Public Types
Public Functions
-
const std::string &
path
() const¶ Get the file path used to open this file.
-
Compression
compression
() const¶ Get the compression used to open this file.
-
const std::string &
-
class
TextFile
: public chemfiles::File, public iostream¶ Abstract base class representing a text file. This class is inteded to be inherited by any form of text files: compressed files, memory-mapped files, etc.
All failling operations should throw a
FileError
instead of waiting for the user of the class to the current state.Subclassed by chemfiles::GzFile, chemfiles::PlainFile, chemfiles::XzFile
Public Functions
-
std::string
readline
()¶ Read a line from the file.
-
std::vector<std::string>
readlines
(size_t n)¶ Read
n
lines from the file.
-
void
rewind
()¶ Reset the file cursor.
-
bool
eof
()¶ Are we at the end of the file ?
Public Static Functions
-
std::string
Implemented classes¶
These classes implement the File
interface defined previously.
-
class
PlainFile
: public chemfiles::TextFile¶ Simple TextFile implementation, only a thin wrapper on top of standard C++ fstreams. Reads plain, uncompressed files
-
class
NcFile
: public chemfiles::File¶ RAII wrapper around NetCDF 3 binary files
This interface only provide basic functionalities needed by the Amber NetCDF format. All the operation are guaranteed to return a valid value or throw an error.
The template functions are manually specialized for float and char data types.
Public Types
Public Functions
-
nc::netcdf_id_t
netcdf_id
() const¶ Get the NetCDF id of this file.
-
std::string
global_attribute
(const std::string &name) const¶ Get a global string attribut from the file.
-
void
add_global_attribute
(const std::string &name, const std::string &value)¶ Create a global attribut in the file_.
-
size_t
dimension
(const std::string &name) const¶ Get the value of a specific dimmension.
-
size_t
optional_dimension
(const std::string &name, size_t value) const¶ Get the value of an optional dimmension, or the default
value
if the dimmension is not in the file
-
void
add_dimension
(const std::string &name, size_t value = NC_UNLIMITED)¶ Create a dimmension with the specified value. If
value == NC_UNLIMITED
, then the dimension is infinite.
-
bool
variable_exists
(const std::string &name) const¶ Check if a variable exists.
-
nc::netcdf_id_t