17 #ifndef HPP_MANIPULATION_PARSER_HH
18 # define HPP_MANIPULATION_PARSER_HH
26 # include <hpp/manipulation/fwd.hh>
29 namespace manipulation {
143 void name (
const std::string& n);
149 template <
typename T> T*
as ()
151 if (!
dynamic_cast <T*
> (
this)) {
152 std::ostringstream oss;
153 oss <<
"Unexpected tag: " << this->
tagName ();
154 throw std::invalid_argument (oss.str ().c_str ());
156 return static_cast <T*
> (
this);
174 virtual std::ostream&
print (std::ostream& os)
const;
179 typedef std::map <std::string, ObjectFactoryList > ChildrenMap;
180 ChildrenMap children_;
184 typedef std::map <std::string, std::string> AttributeMap;
185 AttributeMap attrMap_;
202 if (prefix_.empty ())
return in;
208 if (prefix_.empty ())
return in;
209 assert (in.compare (0, prefix_.size (), prefix_) == 0);
210 return in.substr (prefix_.size ());
215 if (
prefix.empty ())
return;
228 template <
typename T>
231 return new T (parent, element);
248 Parser (
bool fillWithDefaultFactories =
true,
FactoryType defaultFactory = create <ObjectFactory>);
254 void parseString (
const std::string& xmlString, DevicePtr_t robot);
256 void parseFile (
const std::string& filename, DevicePtr_t robot);
260 return objectFactories_;
274 void loadFile (
const char* filename);
276 void loadString (
const char* xmlstring);
282 typedef std::map <std::string, FactoryType> ObjectFactoryMap;
283 typedef std::pair <std::string, FactoryType> ObjectFactoryPair;
284 typedef std::pair <ObjectFactoryMap::iterator, bool> ObjectFactoryInsertRet;
285 ObjectFactoryMap objFactoryMap_;
292 std::ostream& print (std::ostream&)
const;
Class that catch XML Parser events for a specific tag and build the corresponding Object.
Definition: parser.hh:73
std::string tagName() const
friend std::ostream & operator<<(std::ostream &, const ObjectFactory &)
virtual ~ObjectFactory()
Definition: parser.hh:79
std::vector< ObjectFactory * > ObjectFactoryList
Definition: parser.hh:75
virtual bool finishAttributes()
virtual void finishFile()
Called when parsing is finished.
void name(const std::string &n)
void setAttribute(const XMLAttribute *attr)
void addChild(ObjectFactory *child)
ObjectFactoryList getChildrenOfType(std::string type)
Get a list of ObjectFactory whose tag name is type.
T * as()
Cast this class to any child class.
Definition: parser.hh:149
void name(const char *n)
See name(const std::string&)
virtual void finishTags()
Called when all the child tags have been processed.
virtual void impl_setAttribute(const XMLAttribute *attr)
ObjectFactory(ObjectFactory *parent=NULL, const XMLElement *element=NULL)
bool hasAttribute(const std::string &attr) const
Check if an attribute was set.
ObjectFactory(RootFactory *root)
virtual std::ostream & print(std::ostream &os) const
std::string getAttribute(const std::string &attr) const
Return a given attributes.
bool getChildOfType(std::string type, ObjectFactory *&o)
const XMLElement * XMLelement()
virtual void addTextChild(const XMLText *text)
Add Text child.
Parse an XML document.
Definition: parser.hh:239
Parser(bool fillWithDefaultFactories=true, FactoryType defaultFactory=create< ObjectFactory >)
const ObjectFactoryList & objectFactories() const
Definition: parser.hh:258
void prefix(const std::string &prefix)
Set the prefix of all joints.
Definition: parser.hh:264
friend std::ostream & operator<<(std::ostream &, const Parser &)
void addObjectFactory(const std::string &tagname, FactoryType factory)
ObjectFactory *(* FactoryType)(ObjectFactory *, const XMLElement *)
Definition: parser.hh:241
void parseString(const std::string &xmlString, DevicePtr_t robot)
ObjectFactory::ObjectFactoryList ObjectFactoryList
Definition: parser.hh:242
void parseFile(const std::string &filename, DevicePtr_t robot)
Represent a XML document.
Definition: parser.hh:193
virtual ~RootFactory()
Definition: parser.hh:195
std::string removePrefix(const std::string &in) const
Definition: parser.hh:206
RootFactory(const DevicePtr_t dev=DevicePtr_t())
void prefix(const std::string &prefix)
Definition: parser.hh:213
std::string prependPrefix(const std::string &in) const
Definition: parser.hh:200
DevicePtr_t device() const
std::ostream & operator<<(std::ostream &, const ObjectFactory &)
TiXmlDocument XMLDocument
Definition: parser.hh:32
TiXmlText XMLText
Definition: parser.hh:35
ObjectFactory * create(ObjectFactory *parent=NULL, const XMLElement *element=NULL)
Definition: parser.hh:229
TiXmlNode XMLNode
Definition: parser.hh:34
TiXmlAttribute XMLAttribute
Definition: parser.hh:33
TiXmlElement XMLElement
Definition: parser.hh:31
Definition: ignoretag.hh:22