Namespace containing all functions and classes related to VVE persistence. More...
Classes | |
struct | ConvertType |
Convert object of type from to object of type to. More... | |
struct | Frame |
Data holding properties of a frame. More... | |
struct | TypeTraits |
Defines main traits for types directly handled. More... | |
class | VVEStorage |
Abstract base class defining the interactions with the persistence module. More... | |
class | VVEStorage_BINReader |
Implementation reading an BIN file. More... | |
class | VVEStorage_BINWriter |
Implementation writing an BIN file. More... | |
class | VVEStorage_XMLReader |
Implementation reading an XML file. More... | |
class | VVEStorage_XMLWriter |
Implementation writing an XML file. More... | |
Enumerations | |
enum | BIN_TYPES { BT_BOOL = 0, BT_WCHART, BT_CHAR, BT_SIGNED_CHAR, BT_UNSIGNED_CHAR, BT_SHORT, BT_UNSIGNED_SHORT, BT_INT, BT_UNSIGNED_INT, BT_LONG, BT_UNSIGNED_LONG, BT_LONG_LONG, BT_UNSIGNED_LONG_LONG, BT_FLOAT, BT_DOUBLE, BT_LONG_DOUBLE, BT_STRING, BT_START_REFERENCE, BT_START_COMPOUND } |
enum | NUMBER_CLASS { SIGNED_INTEGER, UNSIGNED_INTEGER, FLOATING_POINT, CHAR, NOT_A_NUMBER } |
enum | Options { TypeChecking } |
Common options for reader/writer. More... | |
enum | STORAGE_ERROR { NO__ERROR = 0, IO_ERROR, BAD_CONTENT, TYPE_CHECK_ERROR, TYPE_CONVERSION_ERROR, NO_FIELD_ERROR, REFERENCE_ERROR, USER_ERROR, UNKNOWN_ERROR } |
Enumeration describing the basic errors. More... | |
enum | TypeCheckingOption { TCO_Exact, TCO_Strict, TCO_Permissive, TCO_PermissiveNoWarning, TCO_NoCheck } |
Enumeration describing how the type of the elements should be handled. More... | |
enum | TYPES { T_INVALID = -1, T_BOOL = 0, T_WCHART, T_CHAR, T_SIGNED_CHAR, T_UNSIGNED_CHAR, T_SHORT, T_UNSIGNED_SHORT, T_INT, T_UNSIGNED_INT, T_LONG, T_UNSIGNED_LONG, T_LONG_LONG, T_UNSIGNED_LONG_LONG, T_FLOAT, T_DOUBLE, T_LONG_DOUBLE, T_STRING } |
Functions | |
template<typename From , typename To > | |
bool | convert_type (const From &from, To &to) |
Function converting from to to . | |
template<typename Ptr > | |
Ptr | create_object (Ptr const &p) |
TYPES | find_type (NUMBER_CLASS klass, size_t bytes) |
FOR_ALL_TYPES_NOSTRING (CONVERT_FROM_STDSTRING) | |
FOR_ALL_TYPES_NOSTRING (CONVERT_TO_STDSTRING) | |
bool | isStrictConversion (TYPES from, TYPES to) |
template<typename Ptr > | |
ReferencePtr | make_reference (Ptr &p) |
TYPES | read_type (QFile *file) |
template<typename T > | |
bool | serialization (VVEStorage &storage, T &value) |
Function implementing the serialization. | |
template<typename T > | |
TYPES | type_id (const T &=T()) |
template<typename T > | |
const QString & | type_name (const T &=T()) |
const QString & | typeid_to_name (TYPES id) |
TYPES | typename_to_id (const QString &name) |
int | versionNumber (const QString &file_version) |
Helper function to parse version number. |
Namespace containing all functions and classes related to VVE persistence.
The storage works using the storage::VVEStorage objects. This abstract class defines the generic behavior of a serialized storage for VVE. The implementations are created by the interpreter and given to the model. The storage implement an interface that is the same for reading and writing.
To allow for serialization the model should implement at least one method:
bool serialize(storage::VVEStorage& store);
This method actually implements the serialization of the model. It should returns true if the serialization worked, false otherwise. To test for the existence of this method, the interpreter will call it using a dummy storage object, simulating a storage writer always succeeding. If the result of this dummy call is true, then the object is recognised as being able to serialize data.
For every object, other than the model itself, you want to serialize, you can define its serialization in two ways:
bool serialize(storage::VVEStorage& store);
bool serialization(storage::VVEStorage& store, MyClass& object);
The first way is more intrusive but has the advantage to be inherited. The second way is non-intrusive but won't be inherited by sub-classes. In case the serialization
method does not exist, the serialize
method will be looked for.
Optionnally, the model can define a version string. To do so, the class should define the method:
QString version() const;
The method will be called when saving a file.
Once the version is obtained (either from a file or by calling the version
method), the storage object will call the method:
int versionNumber(const QString& version);
the version given is the model or file version prepended with the file format and a hyphen. For example, if the version of a model is 1.2.3
and the current file is an XML one, the version will be: XML-1.2.3
The number returned by the versionNumber()
method is stored by the storage object and can be retrieved using the VVEStorage::version() method. As a helper, you can use the function storage::versionNumber(const QString&).
The VVEStorage object allows you to define your data structure as a hierarchical set of named fields. As the system is a serialization one, fields should always be read and written in the same order. The storage object is not a random access object but a serial one.
To help you structure your data, you can create three kind of elements:
serialization
function associated or a serialize
method. If a field contains an object, a compound will actually be created. A field is created by the method: template <typename T> bool VVEStorage::field(const QString& name, T& value);
struct MyStructure { int value; bool serialize(storage::VVEStorage& store) { return store.field("", value); } };
template <typename Ptr> bool VVEStorage::reference(const QString& name, const QString& ref_type, Ptr& p);
serialization
function defined in <storage/graph.h>
is defined as: bool serialization(storage::VVEStorage& store, vertex& v) { return store.reference("", "Vertex", v); }
bool VVEStorage::startCompound(const QString& name); bool VVEStorage::endCompound();
enum storage::Options |
Common options for reader/writer.
Definition at line 185 of file storage.h.
00186 { 00188 TypeChecking 00189 };
Enumeration describing the basic errors.
Definition at line 226 of file storage.h.
00227 { 00233 NO__ERROR = 0, 00239 IO_ERROR, 00246 BAD_CONTENT, 00254 TYPE_CHECK_ERROR, 00262 TYPE_CONVERSION_ERROR, 00266 NO_FIELD_ERROR, 00273 REFERENCE_ERROR, 00279 USER_ERROR, 00283 UNKNOWN_ERROR 00284 };
Enumeration describing how the type of the elements should be handled.
Definition at line 194 of file storage.h.
00195 { 00197 TCO_Exact, 00204 TCO_Strict, 00211 TCO_Permissive, 00215 TCO_PermissiveNoWarning, 00220 TCO_NoCheck 00221 };
bool storage::convert_type | ( | const From & | from, | |
To & | to | |||
) | [inline] |
TYPES storage::find_type | ( | NUMBER_CLASS | klass, | |
size_t | bytes | |||
) |
If no such type exist, return T_INVALID
Referenced by storage::VVEStorage_BINReader::serialize(), and storage::old::VVEStorage_BINReader::serialize().
bool storage::isStrictConversion | ( | TYPES | from, | |
TYPES | to | |||
) |
from
to to
without loosing any information bool storage::serialization | ( | VVEStorage & | storage, | |
T & | value | |||
) | [inline] |
Function implementing the serialization.
The default implementation expects a serialize method in the type:
bool T::serialize(VVEStorage&)
Definition at line 703 of file storage.h.
Referenced by storage::VVEStorage::field().
const QString & storage::typeid_to_name | ( | TYPES | id | ) |
TYPES storage::typename_to_id | ( | const QString & | name | ) |
int storage::versionNumber | ( | const QString & | file_version | ) |
Helper function to parse version number.
This function will find any version on the form MAJOR[.MINOR[.MICRO]] and will return a unique integer on 32 bits supposing MAJOR and MINOR are less than 256 and micro is less than 65536. If the version numbers are too big, only the least significant bits are kept.
Any string other than the version number will be ignored.
Examples of valid versions:
File Version Version Number VVE 1.2.20 1.2.20 0x01020014 XML 1.3 1.3 0x01030000 MyModel1.3.2a 1.3.2 0x01030002 OBJ 12.32.254 26.32.254 0x1a2000fe FILE 12 12 0x0c000000