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.
Depending on the kind of format, either a TextFile or a BinaryFile is needed,
and will provide different informations.
These classes only define the interface, which as to be implemented by all sub-classes.
chemfiles::FileAbstract base class for file representation.
Public Type
Possible modes for opening a file.
Values:
READ = = 'r' - Open in read-only mode.
WRITE = = 'w' - Open in read-write mode, and replace the file if it is already present.
APPEND = = 'a' - Open in read-write mode, and append new data at the end of the file.
chemfiles::TextFileAbstract 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.
Public Functions
getline() = 0Read a line from the file.
operator>>(std::string & line) = 0Read a line from the file, stream version.
readlines(size_t n) = 0Read n lines from the file. 
rewind() = 0Reset the file cursor.
nlines() = 0Number of lines in the file.
eof() = 0Are we at the end of the file ?
writeline(const std::string &) = 0Write a string to the file.
writelines(const std::vector< std::string > &) = 0Write a vector of lines to the file.
operator<<(const char * val)Needed for resolving the overload ambiguity when using const char[] or const char* arguments.
chemfiles::BinaryFileAbstract base class for binary files representation
Because the binary formats can be everything, this class does not provides any of the usual methods for working with streams, and is not intended to be instanciated, but rather to serve as a base class for all the binary file classes.
These classes implement the interface defined previously.
chemfiles::BasicFileBasic text file, only a thin wrapper on top of standard C++ fstreams.
Public Functions
BasicFile(const std::string & filename, File::Mode mode)Open a text file with name filename and mode mode.
An FileError exception is thrown if the file does not exists in 'r' or 'a' mode. 
getline()Read a line from the file.
operator>>(std::string & line)Read a line from the file, stream version.
readlines(size_t n)Read n lines from the file. 
rewind()Reset the file cursor.
nlines()Number of lines in the file.
is_open()Is the file opended ?
eof()Are we at the end of the file ?
sync()Sync any content in the underlying buffer to the disk.
writeline(const std::string &)Write a string to the file.
writelines(const std::vector< std::string > &)Write a vector of lines to the file.
chemfiles::NcFileRAII 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 Type
Possible file mode. By default, files are in the DATA mode.
Values:
DEFINE - Files in DEFINE mode can have there attributes, dimmensions and variables modified, but no data can be read or written using NcVariable.
DATA - Files in data mode acces read and write access to NcVariables.
Public Functions
set_nc_mode(NcMode mode)Set the file mode for this file.
nc_mode() constGet the file mode for this file.
netcdf_id() constGet the NetCDF id of this file.
global_attribute(const std::string & name) constGet a global string attribut from the file.
add_global_attribute(const std::string & name, const std::string & value)Create a global attribut in the file_.
dimension(const std::string & name) constGet the value of a specific dimmension.
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. 
variable_exists(const std::string & name) constCheck if a variable exists.
variable(const std::string & name)Get a NetCDF variable.
add_variable(const std::string & name, Dims... dims)Create a new variable of type NcType with name name along the dimensions in dims. dims must be string or string-like values. 
is_open()Is the file opended ?
sync()Sync any content in the underlying buffer to the disk.