AvogadroLibs  1.96.0
Public Member Functions | Static Public Member Functions | List of all members
FileFormatManager Class Reference

Class to manage registration, searching and creation of file formats. More...

#include <fileformatmanager.h>

Public Member Functions

bool readFile (Core::Molecule &molecule, const std::string &fileName, const std::string &fileExtension=std::string(), const std::string &options=std::string()) const
 
bool writeFile (const Core::Molecule &molecule, const std::string &fileName, const std::string &fileExtension=std::string(), const std::string &options=std::string()) const
 
bool readString (Core::Molecule &molecule, const std::string &string, const std::string &fileExtension, const std::string &options=std::string()) const
 
bool writeString (const Core::Molecule &molecule, std::string &string, const std::string &fileExtension, const std::string &options=std::string()) const
 
bool addFormat (FileFormat *format)
 
bool removeFormat (const std::string &identifier)
 
FileFormatnewFormatFromIdentifier (const std::string &identifier, FileFormat::Operations filter=FileFormat::None) const
 
FileFormatnewFormatFromMimeType (const std::string &mimeType, FileFormat::Operations filter=FileFormat::None) const
 
FileFormatnewFormatFromFileExtension (const std::string &extension, FileFormat::Operations filter=FileFormat::None) const
 
std::vector< std::string > identifiers (FileFormat::Operations filter=FileFormat::None) const
 
std::vector< std::string > mimeTypes (FileFormat::Operations filter=FileFormat::None) const
 
std::vector< std::string > fileExtensions (FileFormat::Operations filter=FileFormat::None) const
 
std::vector< const FileFormat * > fileFormats (FileFormat::Operations filter=FileFormat::None) const
 
std::vector< const FileFormat * > fileFormatsFromMimeType (const std::string &mimeType, FileFormat::Operations filter=FileFormat::None) const
 
std::vector< const FileFormat * > fileFormatsFromFileExtension (const std::string &extension, FileFormat::Operations filter=FileFormat::None) const
 
std::string error () const
 

Static Public Member Functions

static FileFormatManagerinstance ()
 
static bool registerFormat (FileFormat *format)
 Register a new file format with the format manager. More...
 
static bool unregisterFormat (const std::string &identifier)
 Unregister a file format from the format manager. More...
 

Detailed Description

<avogadro/io/fileformatmanager.h>

Author
Marcus D. Hanwell

The file format manager is a singleton class that handles the runtime registration, search, creation and eventual destruction of file formats. It can be used to gain a listing of available formats, register new formats and retrieve the correct format to facilitate file IO.

All files IO can take place independent of this manager, but for automated registration and look up this is the preferred API. It is possible to use the convenience API without ever dealing directly with a format class.

Member Function Documentation

◆ instance()

static FileFormatManager& instance ( )
static

Get the singleton instance of the file format manager. This instance should not be deleted.

◆ readFile()

bool readFile ( Core::Molecule molecule,
const std::string &  fileName,
const std::string &  fileExtension = std::string(),
const std::string &  options = std::string() 
) const

Load molecule with the fileName contents supplied, inferring the fileExtension if it is empty. The options can be used to modify the behavior of the file format.

Returns
True on success, false on failure.

◆ writeFile()

bool writeFile ( const Core::Molecule molecule,
const std::string &  fileName,
const std::string &  fileExtension = std::string(),
const std::string &  options = std::string() 
) const

Write molecule to the fileName supplied, inferring the fileExtension if it is empty. The options can be used to modify the behavior of the file format.

Returns
True on success, false on failure.

◆ readString()

bool readString ( Core::Molecule molecule,
const std::string &  string,
const std::string &  fileExtension,
const std::string &  options = std::string() 
) const

Load molecule with the contents of string, using the supplied fileExtension to determine the format. The options can be used to modify the behavior of the file format.

Returns
True on success, false on failure.

◆ writeString()

bool writeString ( const Core::Molecule molecule,
std::string &  string,
const std::string &  fileExtension,
const std::string &  options = std::string() 
) const

Write molecule to the string, using the supplied fileExtension to determine the format. The options can be used to modify the behavior of the file format.

Returns
True on success, false on failure.

◆ registerFormat()

static bool registerFormat ( FileFormat format)
static
Parameters
formatAn instance of the format to manage, the manager assumes ownership of the object passed in.
Returns
True on success, false on failure.

◆ unregisterFormat()

static bool unregisterFormat ( const std::string &  identifier)
static
Parameters
identifierThe identifier for the format to remove.
Returns
True on success, false on failure.

◆ addFormat()

bool addFormat ( FileFormat format)

Add the supplied format to the manager, registering its ID, MIME type, file extension and other relevant data for later lookup. The manager assumes ownership of the supplied object.

Returns
True on success, false on failure.

◆ removeFormat()

bool removeFormat ( const std::string &  identifier)

Remove the format with the identifier identifier from the manager.

Returns
True on success, false on failure.

◆ newFormatFromIdentifier()

FileFormat* newFormatFromIdentifier ( const std::string &  identifier,
FileFormat::Operations  filter = FileFormat::None 
) const

New instance of the format for the specified identifier. Ownership is passed to the caller.

Parameters
identifierThe unique identifier of the format.
filterBitwise combination of FileFormat::Operation values that represents the minimum required capabilities.
Returns
Instance of the format, nullptr if not found. Ownership passes to the caller.

◆ newFormatFromMimeType()

FileFormat* newFormatFromMimeType ( const std::string &  mimeType,
FileFormat::Operations  filter = FileFormat::None 
) const

New instance of the format for the specified mimeType. Ownership is passed to the caller.

Parameters
mimeTypeThe MIME type (in lower case).
filterBitwise combination of FileFormat::Operation values that represents the minimum required capabilities.
Returns
Instance of the format, nullptr if not found. Ownership passes to the caller.

◆ newFormatFromFileExtension()

FileFormat* newFormatFromFileExtension ( const std::string &  extension,
FileFormat::Operations  filter = FileFormat::None 
) const

New instance of the format for the specified file extension. Ownership is passed to the caller.

Parameters
extensionThe file extension (in lower case).
filterBitwise combination of FileFormat::Operation values that represents the minimum required capabilities.
Returns
Instance of the format, nullptr if not found. Ownership passes to the caller.

◆ identifiers()

std::vector<std::string> identifiers ( FileFormat::Operations  filter = FileFormat::None) const

Get a list of all loaded identifiers, optionally matching the specified filter.

Parameters
filterBitwise combination of FileFormat::Operation values that represents the minimum required capabilities.

◆ mimeTypes()

std::vector<std::string> mimeTypes ( FileFormat::Operations  filter = FileFormat::None) const

Get a list of all loaded MIME types, optionally matching the specified filter.

Parameters
filterBitwise combination of FileFormat::Operation values that represents the minimum required capabilities.

◆ fileExtensions()

std::vector<std::string> fileExtensions ( FileFormat::Operations  filter = FileFormat::None) const

Get a list of the file extensions supported, optionally matching the specified filter.

Parameters
filterBitwise combination of FileFormat::Operation values that represents the minimum required capabilities.

◆ fileFormats()

std::vector<const FileFormat*> fileFormats ( FileFormat::Operations  filter = FileFormat::None) const

Get a list of known FileFormat objects, optionally matching the specified filter.

Warning
The objects in the returned list are owned by the FileFormatManager and cannot be modified. Use FileFormat::newInstance() to create mutable copies.
Parameters
filterBitwise combination of FileFormat::Operation values that represents the minimum required capabilities.

◆ fileFormatsFromMimeType()

std::vector<const FileFormat*> fileFormatsFromMimeType ( const std::string &  mimeType,
FileFormat::Operations  filter = FileFormat::None 
) const

Get a list of known FileFormat objects that handle the specified MIME type, optionally matching a filter.

Warning
The objects in the returned list are owned by the FileFormatManager and cannot be modified. Use FileFormat::newInstance() to create mutable copies.
Parameters
mimeTypeMIME type.
filterBitwise combination of FileFormat::Operation values that represents the minimum required capabilities.

◆ fileFormatsFromFileExtension()

std::vector<const FileFormat*> fileFormatsFromFileExtension ( const std::string &  extension,
FileFormat::Operations  filter = FileFormat::None 
) const

Get a list of known FileFormat objects that handle the specified file extension, optionally matching a filter.

Warning
The objects in the returned list are owned by the FileFormatManager and cannot be modified. Use FileFormat::newInstance() to create mutable copies.
Parameters
extensionFile extension.
filterBitwise combination of FileFormat::Operation values that represents the minimum required capabilities.

◆ error()

std::string error ( ) const

Get any errors that have been logged when loading formats.


The documentation for this class was generated from the following file: