diff --git a/VirtualRobot/MJCF/Document.h b/VirtualRobot/MJCF/Document.h index 021d22f3308d242753b1f0531f797a352e54e9d4..e2fc301f9f1777ec737d1cb3ac9afa8abf4abbbd 100644 --- a/VirtualRobot/MJCF/Document.h +++ b/VirtualRobot/MJCF/Document.h @@ -207,4 +207,19 @@ namespace mjcf { return _document->createElement<ElementD, ParentD>(parent, className); } + + template <class D> + void Element<D>::insertComment(const std::string& text, bool front) + { + tinyxml2::XMLComment* comment = _document->doc.NewComment(text.c_str()); + if (front) + { + _element->InsertFirstChild(comment); + } + else + { + _element->InsertEndChild(comment); + } + } + } diff --git a/VirtualRobot/MJCF/elements/core/Element.h b/VirtualRobot/MJCF/elements/core/Element.h index 03f34051381a15c6229483f5d7a34840aefb0415..cd93fba8e9391060a4b843ed05fc80173e17d343 100644 --- a/VirtualRobot/MJCF/elements/core/Element.h +++ b/VirtualRobot/MJCF/elements/core/Element.h @@ -4,6 +4,7 @@ #include "exceptions.h" #include "mjcf_utils.h" +#include "Visitor.h" namespace mjcf @@ -137,6 +138,17 @@ namespace mjcf void deleteChild(const Element<OtherDerived>& element); + /// Insert a comment as child of *this. + void insertComment(const std::string& text, bool front = false); + + + // VISITING + + /// Accept a hierarchical visit of the elements in *this. + /// @see tinyxml2::XMLNode::Accept() + bool accept(Visitor& visitor); + + // CLONING AND TRANSFORMATION /// Create a deep clone of this element. @@ -387,6 +399,12 @@ namespace mjcf _element->DeleteChild(element._element); } + template <class D> + bool Element<D>::accept(Visitor& visitor) + { + return _element->Accept(visitor.adapter()); + } + template <class D> auto Element<D>::deepClone() const -> Derived {