Chemfiles internals

Sources organisation

You will find the following directory in chemfiles source code:

  • cmake: CMake modules used for build configuration;
  • doc: the source for this documentation;
  • examples: usage examples for C and C++ interfaces;
  • external: external libraries used by chemfiles;
  • include: the headers of chemfiles;
  • scripts: some python and bash scripts used in developpement.
  • src: the sources of the library;
  • tests: the sources of the unit tests;

Classes organisation

Chemfiles is written in C++11, in an object-oriented fashion. A Trajectory is built on the top of two other private classes: a File and a Format. These are pure abstract class defining the interface for reading and writing data.

Adding new formats and tweaking behaviour of existing formats should be done either in the File implementation for everything related to interactions with the actual file, or in the Format implementation for everything related with parsing data from the file.

Every Format class can be associated to an extension and a format name, the associations are managed by the FormatFactory class. New file and formats should be registered with this class.

class chemfiles::FormatFactory

This class allow to register Format with names and file extensions.

Public Functions

format_creator_t format(const std::string &name)

Get a `format_creator_t` from a format type name.

Throws an error if the format can not be found

Return
A `format_creator_t` corresponding to the format, if the format name is found in the list of registered formats.
Parameters
  • name: the format name

format_creator_t by_extension(const std::string &ext)

Get a `format_creator_t` from a format extention.

Throws an error if the format can not be found

Return
A `format_creator_t` corresponding to the format, if the format extension is found in the list of registered extensions.
Parameters
  • ext: the format extention

void register_format(const std::string &name, format_creator_t creator)

Register a `format_creator_t` in the internal format names list.

void register_extension(const std::string &ext, format_creator_t creator)

Register a `format_creator_t` in the internal extensions list.

Public Static Functions

FormatFactory &get()

Get the instance of the TrajectoryFactory.