Class that catch XML Parser events for a specific tag and build the corresponding Object. More...
#include <hpp/util/parser.hh>
Public Types | |
typedef std::list< ObjectFactory * > | ObjectFactoryList |
Public Member Functions | |
ObjectFactory (ObjectFactory *parent=NULL, const XMLElement *element=NULL) | |
virtual | ~ObjectFactory () |
void | name (const std::string &n) |
Set the name. More... | |
void | name (const char *n) |
See name(const std::string&) More... | |
template<typename T > | |
T * | as () |
Cast this class to any child class. More... | |
Events | |
virtual bool | init () |
Called when the object is created. More... | |
void | setAttribute (const XMLAttribute *attr) |
Called for each attribute. More... | |
virtual void | addTextChild (const XMLText *text) |
Add Text child. More... | |
virtual bool | finishAttributes () |
Called when all the attributes have been processed. More... | |
virtual void | finishTags () |
Called when all the child tags have been processed. More... | |
virtual void | finishFile () |
Called when parsing is finished. More... | |
Write to file | |
ObjectFactory (const std::string &tagName, ObjectFactory *parent=NULL) | |
Constructor for writing objects from scratch. More... | |
void | addAttribute (const std::string &name, const std::string &value) |
Add an attribute. More... | |
XMLNode * | write (XMLNode *node) const |
Add this factory as child of the node argument. More... | |
Accessors | |
std::string | tagName () const |
Return tag name of the element is any. More... | |
std::string | name () const |
Return the content of the attribute name, or an empty string. More... | |
bool | hasAttribute (const std::string &attr) const |
Check if an attribute was set. More... | |
std::string | getAttribute (const std::string &attr) const |
Return a given attributes. More... | |
ObjectFactoryList | getChildrenOfType (std::string type) |
Get a list of ObjectFactory whose tag name is type. More... | |
bool | getChildOfType (std::string type, ObjectFactory *&o) |
Get the ObjectFactory whose tag name is type. More... | |
Protected Member Functions | |
ObjectFactory (ObjectFactory *root) | |
ObjectFactory * | parent () |
virtual ObjectFactory * | root () |
bool | hasParent () const |
const XMLElement * | XMLelement () |
virtual void | impl_setAttribute (const XMLAttribute *attr) |
virtual void | impl_write (XMLElement *element) const |
void | addChild (ObjectFactory *child) |
virtual std::ostream & | print (std::ostream &os) const |
Friends | |
std::ostream & | operator<< (std::ostream &, const ObjectFactory &) |
Class that catch XML Parser events for a specific tag and build the corresponding Object.
Derive this class if you wish to extend the Parser. The event callbacks are called in the following order:
typedef std::list<ObjectFactory*> hpp::util::parser::ObjectFactory::ObjectFactoryList |
hpp::util::parser::ObjectFactory::ObjectFactory | ( | ObjectFactory * | parent = NULL , |
const XMLElement * | element = NULL |
||
) |
References addChild(), and root().
Referenced by as(), and ~ObjectFactory().
|
inlinevirtual |
hpp::util::parser::ObjectFactory::ObjectFactory | ( | const std::string & | tagName, |
ObjectFactory * | parent = NULL |
||
) |
Constructor for writing objects from scratch.
References addChild(), and root().
|
protected |
void hpp::util::parser::ObjectFactory::addAttribute | ( | const std::string & | name, |
const std::string & | value | ||
) |
|
protected |
References tagName().
Referenced by as(), and ObjectFactory().
|
virtual |
Add Text child.
Reimplemented in hpp::util::parser::SequenceFactory< ValueType >.
Referenced by hpp::util::parser::Parser::addObjectFactory(), and ~ObjectFactory().
|
inline |
Cast this class to any child class.
References addChild(), hasParent(), impl_setAttribute(), impl_write(), ObjectFactory(), operator<<, parent(), print(), root(), and XMLelement().
|
virtual |
Called when all the attributes have been processed.
Referenced by hpp::util::parser::Parser::addObjectFactory(), and ~ObjectFactory().
|
virtual |
Called when parsing is finished.
Referenced by ~ObjectFactory().
|
virtual |
Called when all the child tags have been processed.
Referenced by hpp::util::parser::Parser::addObjectFactory(), and ~ObjectFactory().
std::string hpp::util::parser::ObjectFactory::getAttribute | ( | const std::string & | attr | ) | const |
bool hpp::util::parser::ObjectFactory::getChildOfType | ( | std::string | type, |
ObjectFactory *& | o | ||
) |
Get the ObjectFactory whose tag name is type.
[out] | o | Set to the first element of the requested type. |
std::invalid_argument | if no ObjectFactory of the requested type exists. |
References getChildrenOfType(), hppDout, and tagName().
Referenced by ~ObjectFactory().
std::list< ObjectFactory * > hpp::util::parser::ObjectFactory::getChildrenOfType | ( | std::string | type | ) |
Get a list of ObjectFactory whose tag name is type.
Referenced by getChildOfType(), and ~ObjectFactory().
bool hpp::util::parser::ObjectFactory::hasAttribute | ( | const std::string & | attr | ) | const |
Check if an attribute was set.
Referenced by ~ObjectFactory().
|
protected |
Referenced by as().
|
protectedvirtual |
Referenced by as(), and setAttribute().
|
protectedvirtual |
Reimplemented in hpp::util::parser::SequenceFactory< ValueType >, and hpp::util::parser::IgnoreTagFactory.
|
virtual |
Called when the object is created.
Reimplemented in hpp::util::parser::IgnoreTagFactory.
Referenced by hpp::util::parser::Parser::addObjectFactory(), and ~ObjectFactory().
std::string hpp::util::parser::ObjectFactory::name | ( | ) | const |
Return the content of the attribute name, or an empty string.
Referenced by addAttribute(), name(), print(), setAttribute(), and ~ObjectFactory().
void hpp::util::parser::ObjectFactory::name | ( | const std::string & | n | ) |
Set the name.
The default value is the value of the attribute "name" of the XML tag or an empty string if this does not exist.
void hpp::util::parser::ObjectFactory::name | ( | const char * | n | ) |
References name().
|
protected |
Referenced by as(), hpp::util::parser::create(), and ~ObjectFactory().
|
protectedvirtual |
References name(), and tagName().
Referenced by as(), and hpp::util::parser::operator<<().
|
protectedvirtual |
Referenced by as(), and ObjectFactory().
void hpp::util::parser::ObjectFactory::setAttribute | ( | const XMLAttribute * | attr | ) |
Called for each attribute.
A few reserved name are automatocally catched. The reserved names are "name" and "id". "name" expects a string. "id" expects an unsigned integer and can be use to define pointers to elements.
References hppDout, impl_setAttribute(), and name().
Referenced by hpp::util::parser::Parser::addObjectFactory(), and ~ObjectFactory().
std::string hpp::util::parser::ObjectFactory::tagName | ( | ) | const |
Return tag name of the element is any.
Returns "No element" otherwise.
Referenced by addChild(), hpp::util::parser::Parser::addObjectFactory(), getChildOfType(), print(), write(), and ~ObjectFactory().
Add this factory as child of the node argument.
Get a new XMLElement from the content of this factory.
Tags are handled throught children so you should add children before calling this function. If you factory must write something different from tags (XMLText or XMLComment), reimplement method impl_write.
References impl_write(), and tagName().
Referenced by ~ObjectFactory().
|
protected |
Referenced by as().
|
friend |
Referenced by as().