29 #ifndef HPP_MANIPULATION_PARSER_HH
30 #define HPP_MANIPULATION_PARSER_HH
34 #include <hpp/manipulation/fwd.hh>
41 namespace manipulation {
155 void name(
const std::string& n);
161 template <
typename T>
163 if (!
dynamic_cast<T*
>(
this)) {
164 std::ostringstream oss;
165 oss <<
"Unexpected tag: " << this->
tagName();
166 throw std::invalid_argument(oss.str().c_str());
168 return static_cast<T*
>(
this);
186 virtual std::ostream&
print(std::ostream& os)
const;
191 typedef std::map<std::string, ObjectFactoryList> ChildrenMap;
192 ChildrenMap children_;
196 typedef std::map<std::string, std::string> AttributeMap;
197 AttributeMap attrMap_;
213 if (prefix_.empty())
return in;
218 if (prefix_.empty())
return in;
219 assert(in.compare(0, prefix_.size(), prefix_) == 0);
220 return in.substr(prefix_.size());
224 if (
prefix.empty())
return;
237 template <
typename T>
240 return new T(parent, element);
259 Parser(
bool fillWithDefaultFactories =
true,
260 FactoryType defaultFactory = create<ObjectFactory>);
266 void parseString(
const std::string& xmlString, DevicePtr_t robot);
268 void parseFile(
const std::string& filename, DevicePtr_t robot);
280 void loadFile(
const char* filename);
282 void loadString(
const char* xmlstring);
288 typedef std::map<std::string, FactoryType> ObjectFactoryMap;
289 typedef std::pair<std::string, FactoryType> ObjectFactoryPair;
290 typedef std::pair<ObjectFactoryMap::iterator, bool> ObjectFactoryInsertRet;
291 ObjectFactoryMap objFactoryMap_;
298 std::ostream& print(std::ostream&)
const;
Class that catch XML Parser events for a specific tag and build the corresponding Object.
Definition: parser.hh:85
std::string tagName() const
friend std::ostream & operator<<(std::ostream &, const ObjectFactory &)
virtual ~ObjectFactory()
Definition: parser.hh:91
std::vector< ObjectFactory * > ObjectFactoryList
Definition: parser.hh:87
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:162
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:248
Parser(bool fillWithDefaultFactories=true, FactoryType defaultFactory=create< ObjectFactory >)
const ObjectFactoryList & objectFactories() const
Definition: parser.hh:270
void prefix(const std::string &prefix)
Set the prefix of all joints.
Definition: parser.hh:273
friend std::ostream & operator<<(std::ostream &, const Parser &)
void addObjectFactory(const std::string &tagname, FactoryType factory)
ObjectFactory *(* FactoryType)(ObjectFactory *, const XMLElement *)
Definition: parser.hh:250
void parseString(const std::string &xmlString, DevicePtr_t robot)
ObjectFactory::ObjectFactoryList ObjectFactoryList
Definition: parser.hh:251
void parseFile(const std::string &filename, DevicePtr_t robot)
Represent a XML document.
Definition: parser.hh:205
virtual ~RootFactory()
Definition: parser.hh:207
std::string removePrefix(const std::string &in) const
Definition: parser.hh:217
RootFactory(const DevicePtr_t dev=DevicePtr_t())
void prefix(const std::string &prefix)
Definition: parser.hh:223
std::string prependPrefix(const std::string &in) const
Definition: parser.hh:212
DevicePtr_t device() const
std::ostream & operator<<(std::ostream &, const ObjectFactory &)
tinyxml2::XMLAttribute XMLAttribute
Definition: parser.hh:45
tinyxml2::XMLDocument XMLDocument
Definition: parser.hh:44
ObjectFactory * create(ObjectFactory *parent=NULL, const XMLElement *element=NULL)
Definition: parser.hh:238
tinyxml2::XMLElement XMLElement
Definition: parser.hh:43
tinyxml2::XMLText XMLText
Definition: parser.hh:47
tinyxml2::XMLNode XMLNode
Definition: parser.hh:46
Definition: ignoretag.hh:34