storage::VVEStorage Class Reference

Abstract base class defining the interactions with the persistence module. More...

#include <storage/storage.h>

Inheritance diagram for storage::VVEStorage:
Inheritance graph
[legend]

List of all members.

Public Types

typedef std::map< size_t,
ReferencePtr > 
ref_map
typedef std::map< QString,
ref_map > 
ref_map_type
typedef ptrdiff_t reference_t
 Type of a reference identifier.

Public Member Functions

virtual bool checkNextField (const QString &name)=0
 Test if there is a field with matching name and type.
virtual void clear ()
 Clear the internal structures of the object.
virtual void clearLastError ()
 Remove any error message.
virtual bool endCompound ()=0
 End the current compound.
virtual bool endReference ()=0
 Stop the current reference.
template<typename T , typename Model >
bool field (const QString &name, T &value, Model *model)
 Create a new field, using the model to serialize it.
template<typename T >
bool field (const QString &name, T &value)
 Create a new field.
virtual QString filename () const =0
 Name of the file being processed.
const QStringfileVersion () const
 Version of the file.
virtual bool ignore (const QString &)
 Instruct a reader to ignore the next field if called name.
int lastError () const
 Retrieve the identifier for the last error.
QString lastErrorString () const
 Retrieve a string describing the last error that occured, if any.
virtual bool reader ()=0
template<typename Ptr >
bool reference (const QString &name, const QString &type, Ptr &value, Model *model)
 Create a reference to a field, using the model to serialize it.
template<typename Ptr >
bool reference (const QString &name, const QString &type, Ptr &value)
 Create a reference to a field.
virtual bool serialize (const QString &filename, Model *model)=0
 Load or save depending on the object.
virtual void setLastError (int error, const QString &error_str)
 Change the text of the last error.
virtual bool setOption (int, int)
 Change an option.
virtual bool startCompound (const QString &name)=0
 Start a new compound.
virtual int startReference (const QString &name, const QString &ref_type, reference_t ref)=0
 Start a reference.
int version () const
 Integer representing the version of the file for the model.
virtual bool writer ()=0
virtual ~VVEStorage ()
 Pure virtual destructor to allow for inheritance.
Fields with standard types

virtual bool field (const QString &name, std::string &value)=0
 Create a std::string field.
virtual bool field (const QString &name, QString &value)=0
 Create a QString field.
virtual bool field (const QString &name, long double &value)=0
 Create a long double field.
virtual bool field (const QString &name, double &value)=0
 Create a double field.
virtual bool field (const QString &name, float &value)=0
 Create a float field.
virtual bool field (const QString &name, unsigned long long &value)=0
 Create a unsigned long long integer field.
virtual bool field (const QString &name, unsigned long &value)=0
 Create a unsigned long integer field.
virtual bool field (const QString &name, unsigned int &value)=0
 Create an unsigned integer field.
virtual bool field (const QString &name, unsigned short &value)=0
 Create a unsigned short integer field.
virtual bool field (const QString &name, unsigned char &value)=0
 Create a unsigned char field.
virtual bool field (const QString &name, long long &value)=0
 Create a long long integer field.
virtual bool field (const QString &name, long &value)=0
 Create a long integer field.
virtual bool field (const QString &name, int &value)=0
 Create an integer field.
virtual bool field (const QString &name, short &value)=0
 Create a short integer field.
virtual bool field (const QString &name, signed char &value)=0
 Create a signed char field.
virtual bool field (const QString &name, char &value)=0
 Create a char field.
virtual bool field (const QString &name, wchar_t &value)=0
 Create a wchar_t field.
virtual bool field (const QString &name, bool &value)=0
 Create a boolean field.

Public Attributes

ref_map_type references

Protected Member Functions

template<typename Ptr >
bool find_reference (const QString &type, int ref, Ptr &value)

Protected Attributes

QString file_version
int last_error
QString last_error_string
int version_number

Detailed Description

Abstract base class defining the interactions with the persistence module.

Definition at line 387 of file storage.h.


Member Typedef Documentation


Constructor & Destructor Documentation

virtual storage::VVEStorage::~VVEStorage (  )  [inline, virtual]

Pure virtual destructor to allow for inheritance.

Definition at line 405 of file storage.h.

00405 {}


Member Function Documentation

virtual bool storage::VVEStorage::checkNextField ( const QString name  )  [pure virtual]

Test if there is a field with matching name and type.

For writer, this should always return False.

Implemented in storage::old::VVEStorage_BINReader, storage::VVEStorage_BINWriter, storage::VVEStorage_BINReader, storage::VVEStorage_XMLWriter, and storage::VVEStorage_XMLReader.

void storage::VVEStorage::clear (  )  [virtual]

Clear the internal structures of the object.

Definition at line 21 of file storage.cpp.

00022   {
00023     references.clear();
00024   }

virtual void storage::VVEStorage::clearLastError (  )  [inline, virtual]

Remove any error message.

Definition at line 645 of file storage.h.

References storage::NO__ERROR.

00645 { last_error = NO__ERROR; last_error_string = QString(); }

virtual bool storage::VVEStorage::endCompound (  )  [pure virtual]
virtual bool storage::VVEStorage::endReference (  )  [pure virtual]
template<typename T , typename Model >
bool storage::VVEStorage::field ( const QString name,
T &  value,
Model model 
) [inline]

Create a new field, using the model to serialize it.

Parameters:
name Name of the field
value Variable to associate
model Model used for serialization
Returns:
Always true when writing, or False if reading and the field does not exist

Definition at line 550 of file storage.h.

References endCompound(), QString::isEmpty(), Model::serialize(), and startCompound().

00551     {
00552       bool result = false;
00553       bool no_name = name.isEmpty();
00554       if(startCompound(name))
00555       {
00556         result = model->serialize(*this, value);
00557         result &= endCompound();
00558       }
00559       return result;
00560     }

template<typename T >
bool storage::VVEStorage::field ( const QString name,
T &  value 
) [inline]

Create a new field.

Parameters:
name Name of the field
value Variable to associate
Returns:
Always true when writing, or False if reading and the field does not exist

Definition at line 526 of file storage.h.

References endCompound(), storage::serialization(), and startCompound().

00527     {
00528       bool result = false;
00529       if(startCompound(name))
00530       {
00531         result = serialization(*this, value);
00532         if(!result)
00533           return false;
00534         result &= endCompound();
00535       }
00536       return result;
00537     }

virtual bool storage::VVEStorage::field ( const QString name,
std::string &  value 
) [pure virtual]

Create a std::string field.

virtual bool storage::VVEStorage::field ( const QString name,
QString value 
) [pure virtual]

Create a QString field.

virtual bool storage::VVEStorage::field ( const QString name,
long double &  value 
) [pure virtual]

Create a long double field.

virtual bool storage::VVEStorage::field ( const QString name,
double &  value 
) [pure virtual]

Create a double field.

virtual bool storage::VVEStorage::field ( const QString name,
float &  value 
) [pure virtual]

Create a float field.

virtual bool storage::VVEStorage::field ( const QString name,
unsigned long long &  value 
) [pure virtual]

Create a unsigned long long integer field.

virtual bool storage::VVEStorage::field ( const QString name,
unsigned long &  value 
) [pure virtual]

Create a unsigned long integer field.

virtual bool storage::VVEStorage::field ( const QString name,
unsigned int &  value 
) [pure virtual]

Create an unsigned integer field.

virtual bool storage::VVEStorage::field ( const QString name,
unsigned short &  value 
) [pure virtual]

Create a unsigned short integer field.

virtual bool storage::VVEStorage::field ( const QString name,
unsigned char &  value 
) [pure virtual]

Create a unsigned char field.

virtual bool storage::VVEStorage::field ( const QString name,
long long &  value 
) [pure virtual]

Create a long long integer field.

virtual bool storage::VVEStorage::field ( const QString name,
long &  value 
) [pure virtual]

Create a long integer field.

virtual bool storage::VVEStorage::field ( const QString name,
int &  value 
) [pure virtual]

Create an integer field.

virtual bool storage::VVEStorage::field ( const QString name,
short &  value 
) [pure virtual]

Create a short integer field.

virtual bool storage::VVEStorage::field ( const QString name,
signed char &  value 
) [pure virtual]

Create a signed char field.

virtual bool storage::VVEStorage::field ( const QString name,
char &  value 
) [pure virtual]

Create a char field.

virtual bool storage::VVEStorage::field ( const QString name,
wchar_t &  value 
) [pure virtual]

Create a wchar_t field.

virtual bool storage::VVEStorage::field ( const QString name,
bool &  value 
) [pure virtual]
virtual QString storage::VVEStorage::filename (  )  const [pure virtual]
const QString& storage::VVEStorage::fileVersion (  )  const [inline]

Version of the file.

Definition at line 658 of file storage.h.

00658 { return file_version; }

virtual bool storage::VVEStorage::ignore ( const QString  )  [inline, virtual]

Instruct a reader to ignore the next field if called name.

This method is useful only for truly serial reader (like the BIN one)

Reimplemented in storage::VVEStorage_BINReader.

Definition at line 432 of file storage.h.

00432 { return true; }

int storage::VVEStorage::lastError (  )  const [inline]

Retrieve the identifier for the last error.

See also:
STORAGE_ERROR

Definition at line 633 of file storage.h.

00633 { return last_error; }

QString storage::VVEStorage::lastErrorString (  )  const [inline]

Retrieve a string describing the last error that occured, if any.

Definition at line 626 of file storage.h.

00626 { return last_error_string; }

virtual bool storage::VVEStorage::reader (  )  [pure virtual]
template<typename Ptr >
bool storage::VVEStorage::reference ( const QString name,
const QString type,
Ptr &  value,
Model model 
) [inline]

Create a reference to a field, using the model to serialize it.

The value is supposed to be a pointer on the variable, not the variable itself.

Note:
This could be typically a smart pointer.

Definition at line 598 of file storage.h.

References endReference(), field(), reader(), and startReference().

00599     {
00600       int ref = startReference(name, type, (char*)(&*value) - (char*)0);
00601       if(ref < 0)
00602         return false;
00603       if(!find_reference(type, ref, value))
00604       {
00605         if(reader())
00606           value = create_object(value);
00607         if(!field("", *value, model))
00608         {
00609           return false;
00610         }
00611         references[type][ref] = make_reference(value);
00612       }
00613       return endReference();
00614     }

template<typename Ptr >
bool storage::VVEStorage::reference ( const QString name,
const QString type,
Ptr &  value 
) [inline]

Create a reference to a field.

The value is supposed to be a pointer on the variable, not the variable itself.

Note:
This could be typically a smart pointer.

Definition at line 571 of file storage.h.

References endReference(), field(), reader(), and startReference().

00572     {
00573       int ref = startReference(name, type, (char*)(&*value) - (char*)0);
00574       if(ref < 0)
00575         return false;
00576       if(!find_reference(type, ref, value))
00577       {
00578         if(reader())
00579           value = create_object(value);
00580         if(!field("", *value))
00581         {
00582           return false;
00583         }
00584         references[type][ref] = make_reference(value);
00585       }
00586       return endReference();
00587     }

virtual bool storage::VVEStorage::serialize ( const QString filename,
Model model 
) [pure virtual]
virtual void storage::VVEStorage::setLastError ( int  error,
const QString error_str 
) [inline, virtual]

Change the text of the last error.

Any specific implementation might alter the text.

Reimplemented in storage::old::VVEStorage_BINReader, storage::VVEStorage_BINReader, and storage::VVEStorage_XMLReader.

Definition at line 640 of file storage.h.

References storage::NO__ERROR.

Referenced by storage::VVEStorage_XMLWriter::endCompound(), storage::VVEStorage_BINWriter::endCompound(), storage::VVEStorage_XMLWriter::endReference(), storage::VVEStorage_XMLWriter::serialize(), and storage::VVEStorage_BINWriter::serialize().

00640 { if(last_error == NO__ERROR) { last_error = error; last_error_string = error_str; } }

virtual bool storage::VVEStorage::setOption ( int  ,
int   
) [inline, virtual]

Change an option.

The options are implementation-dependent. If the option is not supported, the function returns 0.

Reimplemented in storage::old::VVEStorage_BINReader, storage::VVEStorage_BINReader, storage::VVEStorage_XMLWriter, and storage::VVEStorage_XMLReader.

Definition at line 413 of file storage.h.

00413 { return false; }

virtual bool storage::VVEStorage::startCompound ( const QString name  )  [pure virtual]

Start a new compound.

Useful to organize complicated data structure

When writing, always returns true. When reading, returns true only if the compound exists.

Implemented in storage::old::VVEStorage_BINReader, storage::VVEStorage_BINWriter, storage::VVEStorage_BINReader, storage::VVEStorage_XMLWriter, and storage::VVEStorage_XMLReader.

Referenced by field().

virtual int storage::VVEStorage::startReference ( const QString name,
const QString ref_type,
reference_t  ref 
) [pure virtual]

Start a reference.

All operations preceding the call to stopReference should be stored in a section reserved for references.

References should be loaded only on need.

When writing, always returns true. When reading, returns true only if the reference exists. If the reference does not exist, it will create it, so the reader has to set the fields.

Returns:
the reference identifier or -1 if no reference is available.

Implemented in storage::old::VVEStorage_BINReader, storage::VVEStorage_BINWriter, storage::VVEStorage_BINReader, storage::VVEStorage_XMLWriter, and storage::VVEStorage_XMLReader.

Referenced by reference().

int storage::VVEStorage::version (  )  const [inline]

Integer representing the version of the file for the model.

This number is defined for a given model and will never appear in a file.

Definition at line 653 of file storage.h.

00653 { return version_number; }

virtual bool storage::VVEStorage::writer (  )  [pure virtual]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Fri May 31 15:38:14 2013 for VVE by  doxygen 1.6.3