All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Valuable::ArchiveElement Class Reference

ArchiveElement defines the serialization API. More...

#include <Valuable/Archive.hpp>

Public Types

typedef Valuable::ArchiveIterator Iterator
 Child iterator for ArchiveElement.
 

Public Member Functions

void add (const ArchiveElement &element)
 Adds a new child element. More...
 
void add (const QString &name, const QString &value)
 Writes a new named attribute, name should be unique along this object. More...
 
 ArchiveElement (std::shared_ptr< ArchiveElementImpl > impl=std::shared_ptr< ArchiveElementImpl >())
 Constructs a new element with given implementation. More...
 
Iterator children () const
 Returns the child iterator to children of this class. More...
 
QString get (const QString &name) const
 Reads a named attribute. More...
 
QString get () const
 Reads the element contents. More...
 
bool isNull () const
 Is this a NULL element, created by the default constructor. More...
 
QString name () const
 Reads the element name. More...
 
void set (const QString &s)
 Writes the element contents. More...
 
void setName (const QString &name)
 Sets the element name. More...
 
const DOMElementxml () const
 If the implementation is actually a XMLArchiveElement, return the wrapped DOMElement. More...
 

Detailed Description

ArchiveElement defines the serialization API.

The (de)serialize() methods should use this interface to actually read/write data. The actual implementation is provided by instance of ArchiveElementImpl, so this same class can be used and copied freely without caring about underlying serialization format.

For one object, the element can write the object name, it's contents, any number of named attributes (key/value pairs), and any number of child objects. It can respectively read the name, contents, attributes by name, and iterate over all child objects. Every backend should implement this kind of data structure.

There is also special "NULL" or "empty" element, that is usually used in case of errors or similar. It can be created by using the default ArchiveElement constructor.

Constructor & Destructor Documentation

Valuable::ArchiveElement::ArchiveElement ( std::shared_ptr< ArchiveElementImpl impl = std::shared_ptr< ArchiveElementImpl >())

Constructs a new element with given implementation.

Parameters
implSerialization implementation to use. If implementation is null, the whole ArchiveElement is "NULL" element.

Member Function Documentation

void Valuable::ArchiveElement::add ( const ArchiveElement element)

Adds a new child element.

Parameters
elementNew child element
void Valuable::ArchiveElement::add ( const QString &  name,
const QString &  value 
)

Writes a new named attribute, name should be unique along this object.

Parameters
nameName of the attribute
valueValue of the attribute
Iterator Valuable::ArchiveElement::children ( ) const

Returns the child iterator to children of this class.

Returns
New child iterator that points to the first child
QString Valuable::ArchiveElement::get ( const QString &  name) const

Reads a named attribute.

Parameters
nameName of the attribute to read
Returns
Attribute value as a string, or empty string if no attribute was found.
QString Valuable::ArchiveElement::get ( ) const

Reads the element contents.

Returns
The contents of the element
bool Valuable::ArchiveElement::isNull ( ) const

Is this a NULL element, created by the default constructor.

Returns
True if this element has no implementation.
QString Valuable::ArchiveElement::name ( ) const

Reads the element name.

Returns
The name of the element
void Valuable::ArchiveElement::set ( const QString &  s)

Writes the element contents.

Parameters
sNew contents of the element
void Valuable::ArchiveElement::setName ( const QString &  name)

Sets the element name.

Parameters
nameThe new name of the element
const DOMElement* Valuable::ArchiveElement::xml ( ) const

If the implementation is actually a XMLArchiveElement, return the wrapped DOMElement.

This function is provided only for keeping backwards compatibility.

Returns
Wrapped DOM element