Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

XMLLoadSave Class Reference

#include <XMLLoadSave.h>

Inheritance diagram for XMLLoadSave:

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 20 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, just make sure to overestimate and things will still work.
virtual unsigned int loadBuffer (const char buf[], unsigned int len)
 Load from a saved buffer in memory.
virtual unsigned int saveBuffer (char buf[], unsigned int len) const
 Save to a given buffer in memory.
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
class XMLLoadSave::AutoInit libxmlInit
 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

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, LookoutPointAtEvent, LookoutIREvent, PitchEvent, TextMsgEvent, TimerEvent, VisionObjectEvent, InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >, plist::PolymorphicLoader, plist::ObjectBase, plist::ObjectBase, plist::DictionaryBase, plist::ArrayBase, plist::Primitive< T >, plist::Primitive< char >, plist::Primitive< unsigned char >, plist::Primitive< std::string >, plist::NamedEnumeration< T >, plist::Primitive< float >, plist::Primitive< int >, plist::Primitive< unsigned int >, plist::Primitive< bool >, plist::NamedEnumeration< J_DCT_METHOD >, plist::NamedEnumeration< Config::vision_config::shutter_speeds >, plist::NamedEnumeration< Config::main_config::consoleMode_t >, plist::NamedEnumeration< Config::sound_config::volume_levels >, plist::NamedEnumeration< Config::vision_config::white_balance_levels >, plist::NamedEnumeration< Config::transports >, plist::NamedEnumeration< Config::vision_config::RawCamConfig::encoding_t >, plist::NamedEnumeration< Config::vision_config::RawCamConfig::compression_t >, plist::NamedEnumeration< Config::vision_config::SegCamConfig::compression_t >, and plist::NamedEnumeration< Config::vision_config::gain_levels >.

Referenced by loadBuffer(), loadFile(), loadFileStream(), and readParseTree().

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, LookoutPointAtEvent, LookoutIREvent, PitchEvent, TextMsgEvent, TimerEvent, VisionObjectEvent, plist::PolymorphicLoader, plist::ObjectBase, plist::DictionaryBase, plist::ArrayBase, plist::Primitive< T >, plist::Primitive< char >, plist::Primitive< unsigned char >, plist::Primitive< std::string >, plist::NamedEnumeration< T >, plist::Primitive< float >, plist::Primitive< int >, plist::Primitive< unsigned int >, plist::Primitive< bool >, plist::NamedEnumeration< J_DCT_METHOD >, plist::NamedEnumeration< Config::vision_config::shutter_speeds >, plist::NamedEnumeration< Config::main_config::consoleMode_t >, plist::NamedEnumeration< Config::sound_config::volume_levels >, plist::NamedEnumeration< Config::vision_config::white_balance_levels >, plist::NamedEnumeration< Config::transports >, plist::NamedEnumeration< Config::vision_config::RawCamConfig::encoding_t >, plist::NamedEnumeration< Config::vision_config::RawCamConfig::compression_t >, plist::NamedEnumeration< Config::vision_config::SegCamConfig::compression_t >, and plist::NamedEnumeration< Config::vision_config::gain_levels >.

Referenced by getBinSize(), 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, just make sure to overestimate and things will still work.

getBinSize is used for reserving buffers during serialization, but does not necessarily determine the actual size of what is written -- the return value of saveBuffer() specifies that after the data actually has been written. If getBinSize overestimates, the extra memory allocation is only temporary, no extra filler bytes are actually stored.

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

Implements LoadSave.

Reimplemented in EventBase, LocomotionEvent, LookoutPointAtEvent, LookoutIREvent, PitchEvent, TextMsgEvent, TimerEvent, and VisionObjectEvent.

Definition at line 64 of file XMLLoadSave.cc.

Referenced by EventBase::getBinSize().

unsigned int XMLLoadSave::loadBuffer ( const char  buf[],
unsigned int  len 
) [virtual]

Load from a saved buffer in memory.

Parameters:
buf pointer to the memory where you should begin loading
len length of buf available (this isn't necessarily all yours, there might be other things following your data)
Returns:
the number of bytes actually used

Implements LoadSave.

Reimplemented in EventBase, and Config.

Definition at line 82 of file XMLLoadSave.cc.

Referenced by plist::loadBuffer(), EventBase::loadBuffer(), and Config::loadBuffer().

unsigned int XMLLoadSave::saveBuffer ( char  buf[],
unsigned int  len 
) const [virtual]

Save to a given buffer in memory.

Parameters:
buf pointer to the memory where you should begin writing
len length of buf available. (this isn't necessarily 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::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, and Config.

Definition at line 148 of file XMLLoadSave.cc.

Referenced by plist::loadFile(), EventBase::loadFile(), Config::loadFile(), and ConfigurationEditor::LoadSettings::selectedFile().

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(), and ConfigurationEditor::SaveSettings::selectedFile().

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
Returns:
number of bytes read, 0 if error (or empty)

Reimplemented from LoadSave.

Reimplemented in EventBase, and Config.

Definition at line 214 of file XMLLoadSave.cc.

Referenced by EventBase::loadFileStream(), and Config::loadFileStream().

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
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().

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().

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().

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

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

Definition at line 80 of file XMLLoadSave.h.

void XMLLoadSave::readParseTree (  )  [virtual]

calls loadXML with the root of the current parse tree

Definition at line 276 of file XMLLoadSave.cc.

void XMLLoadSave::writeParseTree (  )  [virtual]

calls saveXML with the root of the current parse tree

Definition at line 288 of file XMLLoadSave.cc.

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.

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

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

Definition at line 90 of file XMLLoadSave.h.

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

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().

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().

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().

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.


Member Data Documentation

xmlDoc* XMLLoadSave::xmldocument [mutable, protected]

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

Definition at line 114 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 current compression level, or level to be used for the next save

Definition at line 117 of file XMLLoadSave.h.

Referenced by getBinSize(), getCompression(), operator=(), saveBuffer(), saveFile(), saveFileStream(), setCompression(), and writeParseTree().

bool XMLLoadSave::autoFormat [protected]

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

Definition at line 120 of file XMLLoadSave.h.

Referenced by plist::Collection::Collection(), getBinSize(), operator=(), saveBuffer(), saveFile(), and saveFileStream().

allows tracking of libxml usage so the library can be initialized and destructed automatically


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

Tekkotsu v4.0
Generated Thu Nov 22 00:58:50 2007 by Doxygen 1.5.4