Class handling access to adsk::Data::Structures and adsk::Data::Associations located in a file.
This class is used to read and rewrite a collection of adsk::Data::Structure and adsk::Data::Associtions from/to an existing file.
#include <adskDataAccessor.h>
Classes | |
| struct | StructureNameLessThan |
| Functor for Structure ordering in a std::set. More... | |
Public Types | |
|
typedef std::set< const Structure *, StructureNameLessThan > | StructureSet |
| Structures are kept in a set the forbids duplicated names. | |
| typedef std::map< std::string, Associations > | AssociationsMap |
| Associations are kept in a map that forbids duplicated names. | |
Public Member Functions | |
| virtual | ~Accessor () |
| Releases any Structure and Associations objects currently held. | |
| bool | read (const std::string &fileName, std::string &errors) |
| Reads the structures and associations from the specified file. | |
| virtual bool | write (std::string &errors) const |
| Rewrites the file with the edited structures and associations. | |
| const std::string & | fileName () const |
| Returns the file name passed to the last invocation of read(). | |
| const StructureSet & | structures () const |
| Get the adsk::Data::Structures currently held by this instance. | |
| void | setStructures (const StructureSet &structures) |
| Changes the adsk::Data::Structures currently held by this class. | |
| const AssociationsMap & | associations () const |
| Get the adsk::Data::Associations currently held by this instance. | |
| AssociationsMap & | associations () |
| Get the adsk::Data::Associations currently held by this instance. | |
| void | clear () |
| Clears the structures and associations present in the instance. | |
Static Public Member Functions | |
| static std::set< std::string > | supportedExtensions () |
| Returns the supported filename extensions. | |
| static std::auto_ptr< Accessor > | readFile (const std::string &fileName, std::string &errors) |
| Creates and returns an accessor that can handle the specified file. | |
Protected Member Functions | |
| Accessor () | |
| Constructs an empty accessor. | |
| virtual bool | performRead (std::string &errors)=0 |
| Invoked by read() to access the current file. | |
| typedef std::map< std::string, Associations > AssociationsMap |
Associations are kept in a map that forbids duplicated names.
The actual file format defines the semantic for the Associations names. For example, for certain formats, an empty-name may mean file-level associations rather than per-object associations.
| ~Accessor | ( | ) | [virtual] |
Releases any Structure and Associations objects currently held.
If the object gets destroyed before any call to write() is made, the changes will be dropped without any change done to the file.
| Accessor | ( | ) | [protected] |
Constructs an empty accessor.
Upon construction, the accessor is not bound to any file. Calls to read() will load the Structure/Associations object from a given file, provided they are of the format supported by this instance.
| bool read | ( | const std::string & | fileName, |
| std::string & | errors | ||
| ) |
Reads the structures and associations from the specified file.
Structures and associations are read into the current accessor instance and can then be read and changed through other methods in this API prior to rewriting them in the file, if needed, through write().
Previous data will be cleared and will not be written to the previous file. Unseccessful read will cause the structures and associations to be emptied, but the new file name will stay.
| [in] | fileName | Name of the file to open and read the structures/associations from. |
| [out] | errors | Errors that happened during reading, if any. |
| bool write | ( | std::string & | errors | ) | const [virtual] |
Rewrites the file with the edited structures and associations.
The file is changed in place, so if the caller requires any type of versioning, a copy of the original file must first be taken prior to this call as this does not do it. However, concrete implementations may choose to do so.
The default implementation does nothing and returns false.
| [out] | errors | Errors that happened during writing, if any. |
| const std::string & fileName | ( | ) | const |
| const Accessor::StructureSet & structures | ( | ) | const |
Get the adsk::Data::Structures currently held by this instance.
These are the structures found on the last call to read(), or that were set through setStructures.
| void setStructures | ( | const StructureSet & | structures | ) |
Changes the adsk::Data::Structures currently held by this class.
These are the Structures that will be written to the file when it will be written via write(). It is the caller's responsibility to make sure all structures used by the Associations found in this instance's Associations map are present in this set.
Previous adsk::Data::Structures will be unref()'ed, and the new structures will be ref()'ed.
| [in] | structures | The new structures. |
| const Accessor::AssociationsMap & associations | ( | ) | const |
Get the adsk::Data::Associations currently held by this instance.
| Accessor::AssociationsMap & associations | ( | ) |
Get the adsk::Data::Associations currently held by this instance.
| void clear | ( | ) |
Clears the structures and associations present in the instance.
The file name stays unchanged.
| std::set< std::string > supportedExtensions | ( | ) | [static] |
Returns the supported filename extensions.
For debugging or informational purposes. The extensions are converted to lowercase.
| std::auto_ptr< Accessor > readFile | ( | const std::string & | fileName, |
| std::string & | errors | ||
| ) | [static] |
Creates and returns an accessor that can handle the specified file.
Finds the factory whose file name extension matches that of the file name passed in, if any, and creates a new Accessor with the factory's create() method. On success it calls read() on the Accessor and only returns the newly created Accessor if the read has succeeded.
| [in] | fileName | Name of the file to open and read. |
| [out] | errors | Errors that occured during file read, if any. |
| bool performRead | ( | std::string & | errors | ) | [protected, pure virtual] |
Invoked by read() to access the current file.
The current file's name is obtained with fileName(). Concrete implementations must read the structures/associations. Upon success, the structures are read from adsk::Data::Structure::allStructures() and kept in this instance. The associations, on the other hand, must be set by the derived class by editing the associations map returned from associations().
The caller (the read() method) deals with saving/restoring the content of adsk::Data::Structure::allStructures() before/after the call, and clearing the existing structures/associations present in the instance before calling performRead().
| [out] | errors | Errors that happended during reading, if any. |