Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members  

fun::Serializer Class Reference

Serializer is an abstract base class for objects which can store Serializable objects to files or streams. More...

#include <Serializer.h>

Inheritance diagram for fun::Serializer:

fun::SerialTree List of all members.

Public Methods

 Serializer ()
 Creates an empty Serializer node.

virtual void put (const QString &key, const QString &val)=0
 Adds a new element containing the given string value.

void put (const QString &key, const char *val)
 Adds a new element containing the given string value.

virtual void put (const QString &key, int val)
 This is just like the string version of put(), except that it converts the given int value to a string.

virtual void put (const QString &key, unsigned val)
 This is just like the string version of put(), except that it converts the given unsigned int value to a string.

virtual void put (const QString &key, bool val)
 This is just like the string version of put(), except that it converts the given bool value to a string.

virtual void put (const QString &key, float val)
 This is just like the string version of put(), except that it converts the given float value to a string.

virtual void put (const QString &key, double val)
 This is just like the string version of put(), except that it converts the given double value to a string.

virtual void put (const QString &key, const QColor &val)
 This is just like the string version of put(), except that it converts the given QColor value to a string in the format rrggbb.

virtual void put (const QString &key, const Serializable *val)=0
 Adds a new element containing the given Serializable value.

virtual void put (const QString &key, const QPtrList< Serializable > &list)
 Calls put() for each element in the list.

template<class InputIterator> void put (const QString &key, InputIterator begin, InputIterator end)
 Calls put() for each element in the list.

template<class SC> void put (const QString &key, const QPtrList< SC > &list)
 Calls put() for each Serializable element in the list.

template<class SC> void put (const QString &key, const SC *const *list, unsigned len)
 Calls put() for each Serializable element in the array of pointers.

virtual void put (const QString &key, const QStringList &list)
 Calls put() for each element in the list.

virtual void put (const QString &key, const QString *list, unsigned len)
 Calls put() for each element in the list.

virtual void put (const QString &key, const QPoint &val)
 This is just like the string version of put(), except that it converts the given QPoint value to a string in the format "x,y".

virtual void put (const QString &key, const QSize &val)
 This is just like the string version of put(), except that it converts the given QSize value to a string in the format "x,y".

virtual void setSerializableClass (const char *name)=0
 This sets the name of the Serializable subclass name, so that the same class can be instantiated during deserialization.

virtual void setComment (const QString &key, const QString &comment)
 Sets an optional comment which will be associated with a child element.


Detailed Description

Serializer is an abstract base class for objects which can store Serializable objects to files or streams.

Depending on the subclass' implementation, the data may be stored natively, or it may be converted to strings, or stuck in a database, etc.

Think of a Serializer as taking key/value pairs of data, where the values may be Serializable objects, which implies a tree structure. Duplicate keys are allowed, but note that the only way to get at the values for duplicate keys in a Deserializer is to use one of the forms of get() which takes a reference to a list of Serializables or QStrings.

As Serializer is abstract, subclasses must provide implementations for the following methods:

Definition at line 54 of file Serializer.h.


Member Function Documentation

void fun::Serializer::put const QString &    key,
const QString *    list,
unsigned    len
[virtual]
 

Calls put() for each element in the list.

Note that in the result there may be no way to tell "null" and "empty" strings apart.

Definition at line 93 of file Serializer.cpp.

References put().

void fun::Serializer::put const QString &    key,
const QStringList &    list
[virtual]
 

Calls put() for each element in the list.

Note that in the result there may be no way to tell "null" and "empty" strings apart.

Definition at line 84 of file Serializer.cpp.

References put().

template<class SC>
void fun::Serializer::put const QString &    key,
const SC *const *    list,
unsigned    len
 

Calls put() for each Serializable element in the array of pointers.

NULL elements in the list will be ignored... nuts, that means you can't rely on it to deserialize the same way. OK, how about the behavior is undefined in that case, ha ha.

Definition at line 225 of file Serializer.h.

References put().

template<class SC>
void fun::Serializer::put const QString &    key,
const QPtrList< SC > &    list
 

Calls put() for each Serializable element in the list.

This is because even if Foo is a subclass of Serializable, QPtrList<Foo> can't be (or isn't being) treated as a QPtrList<Serializable>.

Definition at line 210 of file Serializer.h.

References put().

template<class InputIterator>
void fun::Serializer::put const QString &    key,
InputIterator    begin,
InputIterator    end
[inline]
 

Calls put() for each element in the list.

To serialize an entire std::vector<Serializable *>, call put(key, vec.begin(), vec.end()).

Definition at line 130 of file Serializer.h.

References put().

virtual void fun::Serializer::put const QString &    key,
const Serializable   val
[pure virtual]
 

Adds a new element containing the given Serializable value.

Passing a NULL Serializable here has the same effect as not calling it at all.

This is one of the methods which subclasses must implement.

Implemented in fun::SerialTree.

void fun::Serializer::put const QString &    key,
const char *    val
[inline]
 

Adds a new element containing the given string value.

(this one is because put(key, "bleh") was calling the bool version!)

Definition at line 73 of file Serializer.h.

References put().

virtual void fun::Serializer::put const QString &    key,
const QString &    val
[pure virtual]
 

Adds a new element containing the given string value.

This is one of the methods which subclasses must implement.

Implemented in fun::SerialTree.

Referenced by put().

void fun::Serializer::setComment const QString &    key,
const QString &    comment
[virtual]
 

Sets an optional comment which will be associated with a child element.

Note that if you have multiple elements with the same key, you're probably only going to have one comment.

The default base class behavior is to do nothing.

Definition at line 113 of file Serializer.cpp.

virtual void fun::Serializer::setSerializableClass const char *    name [pure virtual]
 

This sets the name of the Serializable subclass name, so that the same class can be instantiated during deserialization.

Every Serializable's serialize() method should call this with its own class name after calling its superclass' serialize().

This is one of the methods which subclasses must implement.

Implemented in fun::SerialTree.

Referenced by fun::PropertyList::serialize(), fun::DieRoll::serialize(), and fun::ConfigFile::serialize().


The documentation for this class was generated from the following files:
Generated on Mon Aug 11 14:06:57 2003 for libfunutil by doxygen1.2.18