Class Scine::Utils::FormattedStreamHandler

class FormattedStreamHandler

The interface for all classes handling formatted streaming IO.

Subclassed by Scine::Utils::MolStreamHandler, Scine::Utils::OpenBabelStreamHandler, Scine::Utils::XyzStreamHandler

Public Types

enum SupportType

Which operations are supported for a particular format.

Values:

ReadOnly
ReadWrite
WriteOnly
using FormatSupportPair = std::pair<std::string, SupportType>

Pair of a format filetype suffix and a SupportType.

Public Functions

FormattedStreamHandler()

Default Constructor.

virtual ~FormattedStreamHandler()

Default Destructor.

virtual std::pair<Utils::AtomCollection, Utils::BondOrderCollection> read(std::istream &is, const std::string &format) const = 0

Reads from an input stream, extracting element types, positions and bond orders (if present)

Return

An Atomcollection and BondOrderCollection

Parameters
  • is: The input stream to read

Exceptions

virtual void write(std::ostream &os, const std::string &format, const Utils::AtomCollection &atoms) const = 0

Writes element types and positional information to an arbitrary filetype.

Parameters
  • os: The output stream to write to

  • format: The format to write

  • atoms: The element type and positional information to write to a file

Exceptions

virtual void write(std::ostream &os, const std::string &format, const Utils::AtomCollection &atoms, const Utils::BondOrderCollection &bondOrders) const = 0

Writes element types and positional information to an arbitrary filetype.

Parameters
  • os: The output stream to write to.

  • format: The format to write

  • atoms: The element type and positional information to write to a file

  • bondOrders: The bond order collection to write to file

Exceptions

virtual std::vector<FormatSupportPair> formats() const = 0

Returns a list of supported file formats.

Note

These may, but do not have to be identical to each format’s conventional file suffix

virtual bool formatSupported(const std::string &format, SupportType operation = SupportType::ReadWrite) const = 0

Check whether a particular operation for a format is supported.

Return

true if the operation is supported for that format

Parameters
  • format: The format filetype suffix to check for

  • operation: The operation for which support is queried

virtual std::string name() const = 0

Getter for the name of the FormattedStreamHandler.

Return

Returns the name of the FormattedStreamHandler.

struct FormatMismatchException : public exception

Exception thrown if the specified format and the input stream mismatch.

struct FormatUnsupportedException : public exception

Exception thrown if the desired format is unsupported by the handler.

struct NoBondInformationException : public exception

Exception thrown if the function yielding or taking a BondOrderCollection reads from or writes to a stream whose format does not include bond order information.