Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

XMLLoadSave Class Reference

#include <XMLLoadSave.h>

Inheritance diagram for XMLLoadSave:

Inheritance graph
[legend]
List of all members.

Detailed Description

XMLLoadSave adds functions for XML format serialization, although if you write binary LoadSave functions as well, you can do either.

Definition at line 18 of file XMLLoadSave.h.

Public Member Functions

 XMLLoadSave ()
 constructor
 XMLLoadSave (const XMLLoadSave &xls)
 copy constructor
XMLLoadSaveoperator= (const XMLLoadSave &xls)
 assignment operator
virtual ~XMLLoadSave ()
 destructor
virtual void LoadXML (xmlNode *node)=0
 This is called when the subclass needs to update its values from those values in the parse tree.
virtual void SaveXML (xmlNode *node) const =0
 This is called when XMLLoadSave needs to have the subclass update values in the tree currently in memory -- may already be filled out by previous contents.
virtual unsigned int getBinSize () const
 calculates space needed to save - if you can't precisely add up the size, overestimate and things will still work.
virtual unsigned int LoadBuffer (const char buf[], unsigned int len)
 Load from a saved buffer.
virtual unsigned int SaveBuffer (char buf[], unsigned int len) const
 Save to a given buffer.
virtual unsigned int LoadFile (const char *filename)
 initiate opening of the specified file and loading/saving of all appropriate information.
virtual unsigned int SaveFile (const char *filename) const
 initiate opening of the specified file and loading/saving of all appropriate information.
virtual unsigned int LoadFileStream (FILE *f)
 Used recursively on member objects once a file is already open - DON'T CLOSE the file in your overridden functions.
virtual unsigned int SaveFileStream (FILE *f) const
 Used recursively on member objects once a file is already open - DON'T CLOSE the file in your overridden functions.
virtual void clearParseTree ()
 resets the parse tree currently in memory so that a future save will write a "fresh" copy from scratch.
virtual void setParseTree (xmlDoc *doc) const
 assigns a parse tree which you have obtained from some other source
virtual xmlDocgetParseTree () const
 returns the current parse tree, either from a previous Load, Save, or setParseTree()
virtual void readParseTree ()
 calls LoadXML with the root of the current parse tree
virtual void writeParseTree ()
 calls SaveXML with the root of the current parse tree
virtual void setCompression (int level)
 allows you to set the compression level used by libxml2 -- this corresponds to the compression level setting of zlib, i.e. 0-9
virtual int getCompression () const
 returns the current compression level setting used by libxml2 (via zlib)

Protected Member Functions

virtual xmlNodeFindRootXMLElement (xmlDoc *doc) const
 returns the root element of the xml document
void reportError (const std::string &context, const bad_format &err) const
 cleans up after an error occurs and sends a message to cerr

Static Protected Member Functions

static int fileReadCallback (void *f, char *buf, int len)
 called by libxml2 when it's ready for more data to be read from the source (in this case, a file)
static int fileCloseCallback (void *f)
 called by libxml2 when it's done reading data
static xmlNodeskipToElement (xmlNode *cur)
 returns the next element following cur
static xmlNodeskipToElement (xmlNode *cur, std::string &comment)
 returns the next element following cur; comment is set to the concatination of any comments is encountered in the interim

Protected Attributes

xmlDocxmldocument
 the cached xml parse tree -- contains additional formatting information such as white space and comments
int compressionLevel
 the current compression level, or level to be used for the next save
bool autoFormat
 if true, the saved document will use automatic indenting and formatting
XMLLoadSave::AutoInit libxmlInit
 allows automatic (de)initialization of libxml when the first or last XMLLoadSave class is created or destroyed allows tracking of libxml usage so the library can be initialized and destructed automatically

Classes

class  AutoInit
 allows automatic (de)initialization of libxml when the first or last XMLLoadSave class is created or destroyed More...
class  bad_format
 an exception to be thrown when a bad XML file is parsed, allows file position information to be passed to the user More...


Constructor & Destructor Documentation

XMLLoadSave::XMLLoadSave  ) 
 

constructor

Definition at line 31 of file XMLLoadSave.cc.

XMLLoadSave::XMLLoadSave const XMLLoadSave xls  ) 
 

copy constructor

Definition at line 35 of file XMLLoadSave.cc.

XMLLoadSave::~XMLLoadSave  )  [virtual]
 

destructor

Definition at line 50 of file XMLLoadSave.cc.


Member Function Documentation

void XMLLoadSave::clearParseTree  )  [virtual]
 

resets the parse tree currently in memory so that a future save will write a "fresh" copy from scratch.

You may also want to call this in order to save memory after a Load so that the parse tree information isn't retained in memory if you don't care about retaining the file formatting

Definition at line 266 of file XMLLoadSave.cc.

Referenced by operator=(), and ~XMLLoadSave().

int XMLLoadSave::fileCloseCallback void *  f  )  [static, protected]
 

called by libxml2 when it's done reading data

Definition at line 322 of file XMLLoadSave.cc.

Referenced by LoadFileStream().

int XMLLoadSave::fileReadCallback void *  f,
char *  buf,
int  len
[static, protected]
 

called by libxml2 when it's ready for more data to be read from the source (in this case, a file)

Definition at line 319 of file XMLLoadSave.cc.

Referenced by LoadFileStream().

xmlNode * XMLLoadSave::FindRootXMLElement xmlDoc doc  )  const [protected, virtual]
 

returns the root element of the xml document

Reimplemented in plist::ObjectBase.

Definition at line 307 of file XMLLoadSave.cc.

Referenced by plist::ObjectBase::FindRootXMLElement(), getBinSize(), LoadBuffer(), LoadFile(), LoadFileStream(), readParseTree(), SaveBuffer(), SaveFile(), SaveFileStream(), and writeParseTree().

unsigned int XMLLoadSave::getBinSize  )  const [virtual]
 

calculates space needed to save - if you can't precisely add up the size, overestimate and things will still work.

Returns:
number of bytes read/written, 0 if error (or empty)

Implements LoadSave.

Reimplemented in EventBase, LocomotionEvent, TextMsgEvent, and VisionObjectEvent.

Definition at line 64 of file XMLLoadSave.cc.

Referenced by EventBase::getBinSize().

virtual int XMLLoadSave::getCompression  )  const [inline, virtual]
 

returns the current compression level setting used by libxml2 (via zlib)

Definition at line 86 of file XMLLoadSave.h.

virtual xmlDoc* XMLLoadSave::getParseTree  )  const [inline, virtual]
 

returns the current parse tree, either from a previous Load, Save, or setParseTree()

Definition at line 76 of file XMLLoadSave.h.

unsigned int XMLLoadSave::LoadBuffer const char  buf[],
unsigned int  len
[virtual]
 

Load from a saved buffer.

Parameters:
buf pointer to the memory where you should begin loading
len length of buf available (this isn't all yours, might be more stuff saved after yours)
Returns:
the number of bytes actually used

Implements LoadSave.

Reimplemented in EventBase.

Definition at line 82 of file XMLLoadSave.cc.

Referenced by EventBase::LoadBuffer().

unsigned int XMLLoadSave::LoadFile const char *  filename  )  [virtual]
 

initiate opening of the specified file and loading/saving of all appropriate information.

Parameters:
filename the file to load/save
Returns:
number of bytes read/written, 0 if error (or empty)

Reimplemented from LoadSave.

Reimplemented in EventBase.

Definition at line 148 of file XMLLoadSave.cc.

Referenced by EventBase::LoadFile().

unsigned int XMLLoadSave::LoadFileStream FILE *  f  )  [virtual]
 

Used recursively on member objects once a file is already open - DON'T CLOSE the file in your overridden functions.

Parameters:
f a pointer to the file to load
Warning:
could potentially be very inefficient if root-level objects override LoadFile but leaf-level ones use this implementation, but leaf-level ones won't even get this call unless you override the ones above them - hence, this is all or nothing
Returns:
number of bytes read, 0 if error (or empty)

Reimplemented from LoadSave.

Reimplemented in EventBase.

Definition at line 214 of file XMLLoadSave.cc.

Referenced by EventBase::LoadFileStream().

virtual void XMLLoadSave::LoadXML xmlNode node  )  [pure virtual]
 

This is called when the subclass needs to update its values from those values in the parse tree.

node is the current node in the tree -- it may be the root, but it may also be a subnode within the tree if a recursive structure is used

Implemented in EventBase, LocomotionEvent, TextMsgEvent, VisionObjectEvent, plist::Dictionary, plist::Primitive< bool >, plist::Primitive< char >, plist::Primitive< unsigned char >, plist::Primitive< std::string >, and plist::NamedEnumeration< T >.

Referenced by LoadBuffer(), LoadFile(), LoadFileStream(), and readParseTree().

XMLLoadSave & XMLLoadSave::operator= const XMLLoadSave xls  ) 
 

assignment operator

Definition at line 39 of file XMLLoadSave.cc.

Referenced by SegmentedColorFilterBankEvent::operator=(), plist::PrimitiveBase::operator=(), plist::Dictionary::operator=(), FilterBankEvent::operator=(), and DataEvent< T >::operator=().

void XMLLoadSave::readParseTree  )  [virtual]
 

calls LoadXML with the root of the current parse tree

Definition at line 276 of file XMLLoadSave.cc.

void XMLLoadSave::reportError const std::string &  context,
const bad_format err
const [protected]
 

cleans up after an error occurs and sends a message to cerr

Definition at line 54 of file XMLLoadSave.cc.

Referenced by getBinSize(), LoadBuffer(), LoadFile(), LoadFileStream(), readParseTree(), SaveBuffer(), SaveFile(), SaveFileStream(), and writeParseTree().

unsigned int XMLLoadSave::SaveBuffer char  buf[],
unsigned int  len
const [virtual]
 

Save to a given buffer.

Parameters:
buf pointer to the memory where you should begin writing
len length of buf available. (this isn't all yours, constrain yourself to what you returned in getBinSize() )
Returns:
the number of bytes actually used

Implements LoadSave.

Reimplemented in EventBase.

Definition at line 124 of file XMLLoadSave.cc.

Referenced by EventBase::SaveBuffer().

unsigned int XMLLoadSave::SaveFile const char *  filename  )  const [virtual]
 

initiate opening of the specified file and loading/saving of all appropriate information.

Parameters:
filename the file to load/save
Returns:
number of bytes read/written, 0 if error (or empty)

Reimplemented from LoadSave.

Reimplemented in EventBase.

Definition at line 193 of file XMLLoadSave.cc.

Referenced by EventBase::SaveFile().

unsigned int XMLLoadSave::SaveFileStream FILE *  f  )  const [virtual]
 

Used recursively on member objects once a file is already open - DON'T CLOSE the file in your overridden functions.

Parameters:
f a pointer to the file to save
Warning:
could potentially be very inefficient if root-level objects override SaveFile but leaf-level ones use this implementation, but leaf-level ones won't even get this call unless you override the ones above them - hence, this is all or nothing
Returns:
number of bytes written, 0 if error (or empty)

Reimplemented from LoadSave.

Reimplemented in EventBase.

Definition at line 248 of file XMLLoadSave.cc.

Referenced by EventBase::SaveFileStream().

virtual void XMLLoadSave::SaveXML xmlNode node  )  const [pure virtual]
 

This is called when XMLLoadSave needs to have the subclass update values in the tree currently in memory -- may already be filled out by previous contents.

node is the current node in the tree -- it may be the root, but it may also be a subnode within the tree if a recursive structure is used

Implemented in EventBase, LocomotionEvent, TextMsgEvent, VisionObjectEvent, plist::Dictionary, plist::Primitive< bool >, plist::Primitive< char >, plist::Primitive< unsigned char >, plist::Primitive< std::string >, and plist::NamedEnumeration< T >.

Referenced by getBinSize(), SaveBuffer(), SaveFile(), SaveFileStream(), and writeParseTree().

void XMLLoadSave::setCompression int  level  )  [virtual]
 

allows you to set the compression level used by libxml2 -- this corresponds to the compression level setting of zlib, i.e. 0-9

Definition at line 301 of file XMLLoadSave.cc.

void XMLLoadSave::setParseTree xmlDoc doc  )  const [virtual]
 

assigns a parse tree which you have obtained from some other source

This doesn't update the contents of the subclass's values. The values in doc will be overwritten by those in the subclass on the next Save. If you wish to have the subclass's values updated from doc, call readParseTree() after calling this.

Reimplemented in plist::ObjectBase.

Definition at line 270 of file XMLLoadSave.cc.

Referenced by getBinSize(), operator=(), SaveBuffer(), SaveFile(), SaveFileStream(), plist::ObjectBase::setParseTree(), and writeParseTree().

xmlNode * XMLLoadSave::skipToElement xmlNode cur,
std::string &  comment
[static, protected]
 

returns the next element following cur; comment is set to the concatination of any comments is encountered in the interim

You should call this with node->next, otherwise you'll just keep getting the same node back again

Definition at line 332 of file XMLLoadSave.cc.

xmlNode * XMLLoadSave::skipToElement xmlNode cur  )  [static, protected]
 

returns the next element following cur

You should call this with node->next, otherwise you'll just keep getting the same node back again

Definition at line 326 of file XMLLoadSave.cc.

Referenced by VisionObjectEvent::LoadXML(), TextMsgEvent::LoadXML(), plist::Dictionary::LoadXML(), LocomotionEvent::LoadXML(), VisionObjectEvent::SaveXML(), TextMsgEvent::SaveXML(), plist::Dictionary::SaveXML(), and LocomotionEvent::SaveXML().

void XMLLoadSave::writeParseTree  )  [virtual]
 

calls SaveXML with the root of the current parse tree

Definition at line 288 of file XMLLoadSave.cc.


Member Data Documentation

bool XMLLoadSave::autoFormat [protected]
 

if true, the saved document will use automatic indenting and formatting

Definition at line 116 of file XMLLoadSave.h.

Referenced by plist::Dictionary::Dictionary(), getBinSize(), operator=(), SaveBuffer(), SaveFile(), and SaveFileStream().

int XMLLoadSave::compressionLevel [protected]
 

the current compression level, or level to be used for the next save

Definition at line 113 of file XMLLoadSave.h.

Referenced by getBinSize(), getCompression(), operator=(), SaveBuffer(), SaveFile(), SaveFileStream(), setCompression(), and writeParseTree().

class XMLLoadSave::AutoInit XMLLoadSave::libxmlInit [protected]
 

allows automatic (de)initialization of libxml when the first or last XMLLoadSave class is created or destroyed allows tracking of libxml usage so the library can be initialized and destructed automatically

xmlDoc* XMLLoadSave::xmldocument [mutable, protected]
 

the cached xml parse tree -- contains additional formatting information such as white space and comments

Definition at line 110 of file XMLLoadSave.h.

Referenced by clearParseTree(), getBinSize(), getParseTree(), LoadBuffer(), LoadFile(), LoadFileStream(), operator=(), readParseTree(), SaveBuffer(), SaveFile(), SaveFileStream(), setCompression(), setParseTree(), plist::ObjectBase::setParseTree(), and writeParseTree().


The documentation for this class was generated from the following files:

Tekkotsu v2.4.1
Generated Tue Aug 16 16:35:13 2005 by Doxygen 1.4.4