Avogadro::Io::FileFormatManager#
-
class FileFormatManager#
Class to manage registration, searching and creation of file formats.
<avogadro/io/fileformatmanager.h>
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.
- Author
Marcus D. Hanwell
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.
Public Functions
-
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 thefileName
contents supplied, inferring thefileExtension
if it is empty. Theoptions
can be used to modify the behavior of the file format.- Returns:
True on success, false on failure.
-
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 thefileName
supplied, inferring thefileExtension
if it is empty. Theoptions
can be used to modify the behavior of the file format.- Returns:
True on success, false on failure.
-
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 ofstring
, using the suppliedfileExtension
to determine the format. Theoptions
can be used to modify the behavior of the file format.- Returns:
True on success, false on failure.
-
bool writeString(const Core::Molecule &molecule, std::string &string, const std::string &fileExtension, const std::string &options = std::string()) const#
Write
molecule
to thestring
, using the suppliedfileExtension
to determine the format. Theoptions
can be used to modify the behavior of the file format.- Returns:
True on success, false on failure.
-
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.
-
bool removeFormat(const std::string &identifier)#
Remove the format with the identifier identifier from the manager.
- Returns:
True on success, false on failure.
-
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:
identifier – The unique identifier of the format.
filter – Bitwise 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.
-
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:
mimeType – The MIME type (in lower case).
filter – Bitwise 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.
-
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:
extension – The file extension (in lower case).
filter – Bitwise 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.
-
std::vector<std::string> identifiers(FileFormat::Operations filter = FileFormat::None) const#
Get a list of all loaded identifiers, optionally matching the specified filter.
- Parameters:
filter – Bitwise combination of FileFormat::Operation values that represents the minimum required capabilities.
-
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:
filter – Bitwise combination of FileFormat::Operation values that represents the minimum required capabilities.
-
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:
filter – Bitwise combination of FileFormat::Operation values that represents the minimum required capabilities.
-
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:
filter – Bitwise combination of FileFormat::Operation values that represents the minimum required capabilities.
-
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:
mimeType – MIME type.
filter – Bitwise combination of FileFormat::Operation values that represents the minimum required capabilities.
-
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:
extension – File extension.
filter – Bitwise combination of FileFormat::Operation values that represents the minimum required capabilities.
-
std::string error() const#
Get any errors that have been logged when loading formats.
Public Static Functions
-
static FileFormatManager &instance()#
Get the singleton instance of the file format manager. This instance should not be deleted.
-
static bool registerFormat(FileFormat *format)#
Register a new file format with the format manager.
- Parameters:
format – An instance of the format to manage, the manager assumes ownership of the object passed in.
- Returns:
True on success, false on failure.
-
static bool unregisterFormat(const std::string &identifier)#
Unregister a file format from the format manager.
- Parameters:
identifier – The identifier for the format to remove.
- Returns:
True on success, false on failure.