17 #ifndef HPP_MANIPULATION_PARSER_HH 18 # define HPP_MANIPULATION_PARSER_HH 26 # include <hpp/manipulation/fwd.hh> 29 namespace manipulation {
121 std::string
name ()
const;
127 std::string
getAttribute (
const std::string& attr)
const;
143 void name (
const std::string&
n);
146 void name (
const char* 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_;
182 const XMLElement* element_;
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;
216 prefix_ = prefix +
"/";
228 template <
typename T>
231 return new T (
parent, element);
248 Parser (
bool fillWithDefaultFactories =
true, FactoryType defaultFactory = create <ObjectFactory>);
252 void addObjectFactory (
const std::string& tagname, FactoryType factory);
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);
280 void parseElement (
const XMLElement* element, ObjectFactory*
parent);
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_;
286 FactoryType defaultFactory_;
288 ObjectFactoryList objectFactories_;
292 std::ostream&
print (std::ostream&)
const;
302 #endif // HPP_MANIPULATION_PARSER_HH void prefix(const std::string &prefix)
Definition: parser.hh:213
TiXmlElement XMLElement
Definition: parser.hh:31
std::string prependPrefix(const std::string &in) const
Definition: parser.hh:200
pinocchio::DevicePtr_t DevicePtr_t
bool hasAttribute(const std::string &attr) const
Check if an attribute was set.
virtual ~RootFactory()
Definition: parser.hh:195
virtual void addTextChild(const XMLText *text)
Add Text child.
TiXmlAttribute XMLAttribute
Definition: parser.hh:33
const XMLElement * XMLelement()
friend std::ostream & operator<<(std::ostream &, const ObjectFactory &)
TiXmlText XMLText
Definition: parser.hh:35
virtual void finishTags()
Called when all the child tags have been processed.
std::string tagName() const
ObjectFactory::ObjectFactoryList ObjectFactoryList
Definition: parser.hh:242
void setAttribute(const XMLAttribute *attr)
void prefix(const std::string &prefix)
Set the prefix of all joints.
Definition: parser.hh:264
Represent a XML document.
Definition: parser.hh:193
assert(d.lhs()._blocks()==d.rhs()._blocks())
virtual void impl_setAttribute(const XMLAttribute *attr)
virtual ~ObjectFactory()
Definition: parser.hh:79
Parse an XML document.
Definition: parser.hh:239
TiXmlNode XMLNode
Definition: parser.hh:34
virtual std::ostream & print(std::ostream &os) const
virtual bool finishAttributes()
std::vector< ObjectFactory * > ObjectFactoryList
Definition: parser.hh:75
std::string getAttribute(const std::string &attr) const
Return a given attributes.
void addChild(ObjectFactory *child)
virtual void finishFile()
Called when parsing is finished.
TiXmlDocument XMLDocument
Definition: parser.hh:32
T * as()
Cast this class to any child class.
Definition: parser.hh:149
ObjectFactory(ObjectFactory *parent=NULL, const XMLElement *element=NULL)
ObjectFactory * create(ObjectFactory *parent=NULL, const XMLElement *element=NULL)
Definition: parser.hh:229
Class that catch XML Parser events for a specific tag and build the corresponding Object...
Definition: parser.hh:73
std::string removePrefix(const std::string &in) const
Definition: parser.hh:206
ObjectFactoryList getChildrenOfType(std::string type)
Get a list of ObjectFactory whose tag name is type.
const ObjectFactoryList & objectFactories() const
Definition: parser.hh:258
bool getChildOfType(std::string type, ObjectFactory *&o)