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

fun::SerialTree Class Reference

SerialTree is a simple Serializer and Deserializer which currently can be saved to & loaded from XML if your Qt has XML support. More...

#include <SerialTree.h>

Inheritance diagram for fun::SerialTree:

fun::Serializer fun::Deserializer List of all members.

Public Methods

 SerialTree ()
 Creates an empty SerialTree node.

void get (const QString &key, QString &rv, const QString &defaultVal=QString()) const
 Searches the given node for a child element with the given key, and places its contents in rv.

void get (const QString &key, Serializable *&rv, const QString &dfltClassName, Serializable *dflt=NULL) const
 This is just like the other getSerializable() method, except that it also takes a default class name to be used if the child element doesn't specify a class.

void get (const QString &key, std::vector< Serializable * > &list, const QString &dfltClassName=QString()) const
 See Deserializer::get(const QString &, std::vector<Serializable *> &, const QString &) for copious notes on this topic.

void get (const QString &key, QStringList &list) const
 Gets a list of QStrings with the given key.

void put (const QString &key, const QString &val)
 Creates and appends a new child node containing the given string value.

void put (const QString &key, const Serializable *val)
 This causes the given Serializable to store itself into a new node, which is appended as a child to the given node.

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.

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.

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.

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.

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.

void get (const QString &key, int &rv, int defaultVal=0) const
 This is just like the string version of get(), except that it converts the child node's contents to an int.

void get (const QString &key, unsigned &rv, unsigned defaultVal=0) const
 This is just like the string version of get(), except that it converts the child node's contents to an unsigned int.

void get (const QString &key, bool &rv, bool defaultVal=false) const
 This is just like the string version of get(), except that it converts the child node's contents to a bool.

void get (const QString &key, float &rv, float defaultVal=0.0) const
 This is just like the string version of get(), except that it converts the child node's contents to a float.

void get (const QString &key, double &rv, double defaultVal=0.0) const
 This is just like the string version of get(), except that it converts the child node's contents to a double.

void setSerializableClass (const char *name)
 This sets the name of the Serializable subclass name, so that the same class can be instantiated from this node later.

const char * getSerializableClass () const
 This returns the name of the class which stored itself to the given node, if any.

void dumpTree (QString indent="") const
 Print debugging information about the structure & contents of a node and all of its children to cout.

bool saveToXMLFile (const QString &filename, int mode=0, int gzipLevel=0)
 Opens the given filename and attempts to save the tree as XML.

bool saveXMLToStream (std::ostream &os)
 Writes XML data to the given ostream.

bool saveToTextStream (std::ostream &os)
 Save the tree as text to the given output stream.

QString toString ()
 Returns an XML string.

bool saveToTextFile (const QString &filename, int mode=0)
 Opens the given filename and attempts to save the tree as text.

bool saveToBinaryStream (QDataStream &os, int version=0)
 Save the tree as binary to the given output stream.

bool saveToBinaryFile (const QString &filename, int verson=0, int mode=0)
 Opens the given filename and attempts to save the tree as binary.


Static Public Methods

SerialTree * loadFromFile (const QString &filename)
 Opens the given filename and attempts to load its contents into a SerialTree.

template<class SC> void loadFromFile (const QString &filename, SC *&rv, const QString &node="wrapper")
 Opens the given filename and attempts to load its contents into a SerialTree.

SerialTree * loadFromXMLFile (const QString &filename)
 Opens the given filename and attempts to load its contents into a SerialTree.

SerialTree * loadFromDomDoc (QDomDocument &xdoc)
 buffer size notes: A single top-level gcom with 2800 near-identical children takes just under 3MB of internal mem, and about this filespace: stephan@jareth:~/gameroot >for i in 3 6 9; do gzip -$i -c biggie > biggie.$i; done stephan@jareth:~/gameroot >l biggie* -rw-r--r-- 1 stephan users 2703170 Jan 30 01:46 biggie -rw-r--r-- 1 stephan users 60110 Jan 30 01:58 biggie.3 -rw-r--r-- 1 stephan users 35473 Jan 30 01:58 biggie.6 -rw-r--r-- 1 stephan users 29315 Jan 30 01:58 biggie.9

SerialTree * loadFromXMLString (const QString &xmlstuff)
 Just like loadFromXLMFile() except that it takes a QString which contains XML code.

SerialTree * loadFromTextStream (QTextStream &is)
 Attempts to read a SerialTree as text from the given input stream.

SerialTree * loadFromTextFile (const QString &filename)
 Opens the given filename and attempts to load its contents into a SerialTree.

SerialTree * loadFromBinaryStream (QDataStream &is)
 Attempts to read a SerialTree in binary from the given input stream.

SerialTree * loadFromBinaryFile (const QString &filename)
 Opens the given filename and attempts to load its contents into a SerialTree.

template<class SC> SC * clone (const SC &rv, Deserializer::Context *context=NULL)
 Copies the object by serializing & deserializing it.


Detailed Description

SerialTree is a simple Serializer and Deserializer which currently can be saved to & loaded from XML if your Qt has XML support.

It should also have saveToTextFile and loadFromTextFile methods, but at the moment, it doesn't.

I would probably be using STL if I had a larger brain.

Definition at line 144 of file SerialTree.h.


Member Function Documentation

template<class SC>
SC * fun::SerialTree::clone const SC &    rv,
Deserializer::Context   context = NULL
[static]
 

Copies the object by serializing & deserializing it.

(Maybe not the most efficient way, but it's easy...)

If a Deserialization::Context is given, it will be passed to pushContext() before deserialization, and deleted afterwards.

Definition at line 561 of file SerialTree.h.

References fun::Deserializer::get(), fun::Deserializer::popContext(), and fun::Deserializer::pushContext().

void fun::SerialTree::get const QString &    key,
double &    rv,
double    defaultVal = 0.0
const [virtual]
 

This is just like the string version of get(), except that it converts the child node's contents to a double.

If no child with the given key is found, or the child can't be converted to a double, the given default value is returned.

Reimplemented from fun::Deserializer.

void fun::SerialTree::get const QString &    key,
float &    rv,
float    defaultVal = 0.0
const [virtual]
 

This is just like the string version of get(), except that it converts the child node's contents to a float.

If no child with the given key is found, or the child can't be converted to a float, the given default value is returned.

Reimplemented from fun::Deserializer.

void fun::SerialTree::get const QString &    key,
bool &    rv,
bool    defaultVal = false
const [virtual]
 

This is just like the string version of get(), except that it converts the child node's contents to a bool.

If no child with the given key is found, or the child can't be converted to a bool, the given default value is returned. The static stringIsBool and stringToBool methods will tell you whether a string can be converted to a bool.

Reimplemented from fun::Deserializer.

void fun::SerialTree::get const QString &    key,
unsigned &    rv,
unsigned    defaultVal = 0
const [virtual]
 

This is just like the string version of get(), except that it converts the child node's contents to an unsigned int.

If no child with the given key is found, or the child can't be converted to an unsigned int, the given default value is returned.

Reimplemented from fun::Deserializer.

void fun::SerialTree::get const QString &    key,
int &    rv,
int    defaultVal = 0
const [virtual]
 

This is just like the string version of get(), except that it converts the child node's contents to an int.

If no child with the given key is found, or the child can't be converted to an int, the given default value is returned.

Reimplemented from fun::Deserializer.

void fun::SerialTree::get const QString &    key,
QStringList &    list
const [virtual]
 

Gets a list of QStrings with the given key.

This is one of the methods which subclasses must implement.

Implements fun::Deserializer.

Definition at line 229 of file SerialTree.cpp.

void fun::SerialTree::get const QString &    key,
Serializable *&    rv,
const QString &    dfltClassName,
Serializable   dflt = NULL
const [virtual]
 

This is just like the other getSerializable() method, except that it also takes a default class name to be used if the child element doesn't specify a class.

This is just so that files which have dozens of objects all of the same class don't need to specify the class in every element.

Implements fun::Deserializer.

Definition at line 196 of file SerialTree.cpp.

void fun::SerialTree::get const QString &    key,
QString &    rv,
const QString &    defaultVal = QString()
const [virtual]
 

Searches the given node for a child element with the given key, and places its contents in rv.

If no child with the given key is found, the given default value is used.

Implements fun::Deserializer.

Definition at line 180 of file SerialTree.cpp.

SerialTree * fun::SerialTree::loadFromBinaryFile const QString &    filename [static]
 

Opens the given filename and attempts to load its contents into a SerialTree.

If successful, it returns the new tree, which the caller is responsible for deleting. Otherwise, it returns NULL, and you must consult steaming goat entrails to ascertain the reason.

Definition at line 38 of file SerialTree-bin.cpp.

References loadFromBinaryStream().

Referenced by loadFromFile().

SerialTree * fun::SerialTree::loadFromBinaryStream QDataStream &    is [static]
 

Attempts to read a SerialTree in binary from the given input stream.

If successful, it returns the new tree, which the caller is responsible for deleting. Otherwise, it returns NULL, and you must consult steaming goat entrails to ascertain the reason.

Definition at line 80 of file SerialTree-bin.cpp.

References children, childrenFromBinary1(), childrenFromBinary2(), contextFromBinary2(), and SerialTree().

Referenced by loadFromBinaryFile().

SerialTree * fun::SerialTree::loadFromDomDoc QDomDocument &    xdoc [static]
 

buffer size notes: A single top-level gcom with 2800 near-identical children takes just under 3MB of internal mem, and about this filespace: stephan@jareth:~/gameroot >for i in 3 6 9; do gzip -$i -c biggie > biggie.$i; done stephan@jareth:~/gameroot >l biggie* -rw-r--r-- 1 stephan users 2703170 Jan 30 01:46 biggie -rw-r--r-- 1 stephan users 60110 Jan 30 01:58 biggie.3 -rw-r--r-- 1 stephan users 35473 Jan 30 01:58 biggie.6 -rw-r--r-- 1 stephan users 29315 Jan 30 01:58 biggie.9

The .95 file is about the highest ratio we'll see, i think. (Turns out i've seen some at 97%.)

Definition at line 187 of file SerialTree-qxml.cpp.

References children, and context.

Referenced by loadFromXMLFile(), and loadFromXMLString().

template<class SC>
void fun::SerialTree::loadFromFile const QString &    filename,
SC *&    rv,
const QString &    node = "wrapper"
[static]
 

Opens the given filename and attempts to load its contents into a SerialTree.

If successful, it tries to retrieve a Serializable of the given class from the given node. If successful, it sets rv to the new Serializable, which the caller is responsible for deleting. Otherwise, it returns NULL, and you must consult steaming goat entrails to ascertain the reason.

Definition at line 550 of file SerialTree.h.

References fun::Deserializer::get(), and loadFromFile().

SerialTree * fun::SerialTree::loadFromFile const QString &    filename [static]
 

Opens the given filename and attempts to load its contents into a SerialTree.

If successful, it returns the new tree, which the caller is responsible for deleting. Otherwise, it returns NULL, and you must consult steaming goat entrails to ascertain the reason.

(Basically this attempts to determine whether the file contains XML or plain text, and then calls loadFromXMLFile() or loadFromTextFile().)

Definition at line 528 of file SerialTree.cpp.

References loadFromBinaryFile(), loadFromTextFile(), and loadFromXMLFile().

Referenced by loadFromFile().

SerialTree * fun::SerialTree::loadFromTextFile const QString &    filename [static]
 

Opens the given filename and attempts to load its contents into a SerialTree.

If successful, it returns the new tree, which the caller is responsible for deleting. Otherwise, it returns NULL, and you must consult steaming goat entrails to ascertain the reason.

Definition at line 315 of file SerialTree-text.cpp.

References loadFromTextStream().

Referenced by loadFromFile().

SerialTree * fun::SerialTree::loadFromTextStream QTextStream &    is [static]
 

Attempts to read a SerialTree as text from the given input stream.

If successful, it returns the new tree, which the caller is responsible for deleting. Otherwise, it returns NULL, and you must consult steaming goat entrails to ascertain the reason.

Definition at line 75 of file SerialTree-text.cpp.

References fun::Progress::cancelled(), children, childrenFromText(), fun::Progress::finish(), SerialTree(), and fun::Progress::start().

Referenced by loadFromTextFile().

SerialTree * fun::SerialTree::loadFromXMLFile const QString &    filename [static]
 

Opens the given filename and attempts to load its contents into a SerialTree.

If successful, it returns the new tree, which the caller is responsible for deleting. Otherwise, it returns NULL, and you must consult steaming goat entrails to ascertain the reason.

Definition at line 122 of file SerialTree-qxml.cpp.

References loadFromDomDoc().

Referenced by loadFromFile().

bool fun::SerialTree::saveToBinaryFile const QString &    filename,
int    verson = 0,
int    mode = 0
 

Opens the given filename and attempts to save the tree as binary.

If you want to append to the file instead of stomping its contents, the optional mode argument should be IO_Append (defined in qiodevice.h). NOTE that's being ignored right now.

The version number is 1 for version 1, 2 for version 2, or 0 for the default (which depends on whether BOZO_CONTEXT is set in SerialTree.h).

Definition at line 27 of file SerialTree-bin.cpp.

References saveToBinaryStream().

bool fun::SerialTree::saveToBinaryStream QDataStream &    os,
int    version = 0
 

Save the tree as binary to the given output stream.

The version number is 1 for version 1, 2 for version 2, or 0 for the default (which depends on whether BOZO_CONTEXT is set in SerialTree.h).

Definition at line 47 of file SerialTree-bin.cpp.

Referenced by saveToBinaryFile().

bool fun::SerialTree::saveToTextFile const QString &    filename,
int    mode = 0
 

Opens the given filename and attempts to save the tree as text.

If you want to append to the file instead of stomping its contents, the optional mode argument should be IO_Append (defined in qiodevice.h). NOTE that's being ignored right now.

Definition at line 325 of file SerialTree-text.cpp.

References saveToTextStream().

bool fun::SerialTree::saveToXMLFile const QString &    filename,
int    mode = 0,
int    gzipLevel = 0
 

Opens the given filename and attempts to save the tree as XML.

If you want to append to the file instead of stomping its contents, the optional mode argument should be IO_Append (defined in qiodevice.h). NOTE that's being ignored right now.

Definition at line 236 of file SerialTree-qxml.cpp.

References toString().

Referenced by fun::ConfigFile::saveToXML().

bool fun::SerialTree::saveXMLToStream std::ostream &    os
 

Writes XML data to the given ostream.

Returns false if the XML data is 0 bytes, else true.

Definition at line 297 of file SerialTree-qxml.cpp.

References toString().


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