17 #ifndef HPP_MANIPULATION_PARSER_HH 18 # define HPP_MANIPULATION_PARSER_HH 26 # include <boost/function.hpp> 128 XMLNode*
write (XMLNode* node)
const;
141 std::string
name ()
const;
147 std::string
getAttribute (
const std::string& attr)
const;
163 void name (
const std::string& n);
166 void name (
const char* n);
169 template <
typename T> T*
as ()
171 return static_cast <T*> (
this);
187 virtual void impl_write (XMLElement* element)
const;
191 virtual std::ostream&
print (std::ostream& os)
const;
196 typedef std::map <std::string, ObjectFactoryList > ChildrenMap;
197 ChildrenMap children_;
199 const XMLElement* element_;
201 typedef std::map <std::string, std::string> AttributeMap;
202 AttributeMap attrMap_;
203 std::string name_, tagName_;
212 template <
typename T>
215 return new T (
parent, element);
225 typedef boost::function <ObjectFactory* (ObjectFactory*, const XMLElement*)>
234 void addObjectFactory (
const std::string& tagname,
FactoryType factory);
236 virtual void parse (
const char* xmlString);
238 virtual void parseFile (
const std::string& filename);
246 bool checkError ()
const;
248 void loadString (
const char* xmlstring);
254 typedef std::map <std::string, FactoryType> ObjectFactoryMap;
255 typedef std::pair <std::string, FactoryType> ObjectFactoryPair;
256 typedef std::pair <ObjectFactoryMap::iterator, bool> ObjectFactoryInsertRet;
257 ObjectFactoryMap objFactoryMap_;
261 ObjectFactoryList objectFactories_;
263 std::ostream&
print (std::ostream&)
const;
273 #endif // HPP_MANIPULATION_PARSER_HH virtual void finishFile()
Called when parsing is finished.
Definition: parser.cc:170
std::string name() const
Definition: parser.cc:215
ObjectFactory(ObjectFactory *parent=NULL, const XMLElement *element=NULL)
Definition: parser.cc:138
T * as()
Cast this class to any child class.
Definition: parser.hh:169
virtual bool finishAttributes()
Definition: parser.cc:162
TiXmlText XMLText
Definition: parser.hh:36
Definition: assertion.hh:24
virtual ObjectFactory * root()
Definition: parser.cc:235
bool hasParent() const
Definition: parser.cc:240
Class that catch XML Parser events for a specific tag and build the corresponding Object...
Definition: parser.hh:77
void addChild(ObjectFactory *child)
Definition: parser.cc:256
ObjectFactory * create(ObjectFactory *parent=NULL, const XMLElement *element=NULL)
Definition: parser.hh:213
const XMLElement * XMLelement()
Definition: parser.cc:245
void addAttribute(const std::string &name, const std::string &value)
Add an attribute.
Definition: parser.cc:188
TiXmlNode XMLNode
Definition: parser.hh:35
std::string getAttribute(const std::string &attr) const
Return a given attributes.
Definition: parser.cc:314
TiXmlAttribute XMLAttribute
Definition: parser.hh:34
ObjectFactory * parent()
Definition: parser.cc:230
virtual ~ObjectFactory()
Definition: parser.hh:83
void setAttribute(const XMLAttribute *attr)
Definition: parser.cc:292
TiXmlComment XMLComment
Definition: parser.hh:37
ObjectFactoryList getChildrenOfType(std::string type)
Get a list of ObjectFactory whose tag name is type.
Definition: parser.cc:261
TiXmlElement XMLElement
Definition: parser.hh:31
std::string tagName() const
Definition: parser.cc:210
friend std::ostream & operator<<(std::ostream &, const ObjectFactory &)
Definition: parser.cc:133
TiXmlDocument XMLDocument
Definition: parser.hh:32
virtual std::ostream & print(std::ostream &os) const
Definition: parser.cc:281
XMLNode * write(XMLNode *node) const
Get a new XMLElement from the content of this factory.
Definition: parser.cc:195
TiXmlPrinter XMLPrinter
Definition: parser.hh:39
bool getChildOfType(std::string type, ObjectFactory *&o)
Definition: parser.cc:266
std::list< ObjectFactory * > ObjectFactoryList
Definition: parser.hh:79
Parse an XML document.
Definition: parser.hh:223
boost::function< ObjectFactory *(ObjectFactory *, const XMLElement *)> FactoryType
Definition: parser.hh:226
virtual void addTextChild(const XMLText *text)
Add Text child.
Definition: parser.cc:173
virtual bool init()
Definition: parser.cc:157
bool hasAttribute(const std::string &attr) const
Check if an attribute was set.
Definition: parser.cc:309
TiXmlDeclaration XMLDeclaration
Definition: parser.hh:33
virtual void impl_write(XMLElement *element) const
Definition: parser.cc:253
virtual void impl_setAttribute(const XMLAttribute *attr)
Definition: parser.cc:250
virtual void finishTags()
Called when all the child tags have been processed.
Definition: parser.cc:167