XMLLoadSave Class Reference#include <XMLLoadSave.h>
Inheritance diagram for XMLLoadSave:
[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
|
XMLLoadSave & | operator= (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 xmlDoc * | getParseTree () 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 xmlNode * | FindRootXMLElement (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 xmlNode * | skipToElement (xmlNode *cur) |
| returns the next element following cur
|
static xmlNode * | skipToElement (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 |
xmlDoc * | xmldocument |
| 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 |
( |
|
) |
|
|
XMLLoadSave::~XMLLoadSave |
( |
|
) |
[virtual] |
|
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] |
|
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] |
|
unsigned int XMLLoadSave::getBinSize |
( |
|
) |
const [virtual] |
|
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] |
|
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(). |
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] |
|
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] |
|
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] |
|
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
|
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
|
|
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:
|