diff --git a/include/sdf/Param.hh b/include/sdf/Param.hh index d0a952f4c..924849ab9 100644 --- a/include/sdf/Param.hh +++ b/include/sdf/Param.hh @@ -326,6 +326,15 @@ namespace sdf public: bool SetParentElement(ElementPtr _parentElement, sdf::Errors &_errors); + /// \brief Set the parent Element of this Param without reparsing. + /// This is meant for internal consumption when cloning elements. + /// \param[in] _parentElement Pointer to new parent Element. A nullptr can + /// be provided to remove the current parent Element. + /// \param[out] _errors Vector of errors. + /// \return True if the parent Element was set. + public: bool SetParentElementNoReparse( + ElementPtr _parentElement); + /// \brief Reset the parameter to the default value. public: void Reset(); diff --git a/src/Element.cc b/src/Element.cc index fd8950d7f..7c95b6a9c 100644 --- a/src/Element.cc +++ b/src/Element.cc @@ -256,7 +256,7 @@ ElementPtr Element::Clone(sdf::Errors &_errors) const aiter != this->dataPtr->attributes.end(); ++aiter) { auto clonedAttribute = (*aiter)->Clone(); - SDF_ASSERT(clonedAttribute->SetParentElement(clone), + SDF_ASSERT(clonedAttribute->SetParentElementNoReparse(clone), "Cannot set parent Element of cloned attribute Param to cloned " "Element."); clone->dataPtr->attributes.push_back(clonedAttribute); @@ -279,7 +279,7 @@ ElementPtr Element::Clone(sdf::Errors &_errors) const if (this->dataPtr->value) { clone->dataPtr->value = this->dataPtr->value->Clone(); - SDF_ASSERT(clone->dataPtr->value->SetParentElement(clone), + SDF_ASSERT(clone->dataPtr->value->SetParentElementNoReparse(clone), "Cannot set parent Element of cloned value Param to cloned Element."); } diff --git a/src/Param.cc b/src/Param.cc index 2336f4296..317d47a77 100644 --- a/src/Param.cc +++ b/src/Param.cc @@ -1326,6 +1326,13 @@ bool Param::SetParentElement(ElementPtr _parentElement, sdf::Errors &_errors) return true; } +////////////////////////////////////////////////// +bool Param::SetParentElementNoReparse(ElementPtr _parentElement) +{ + this->dataPtr->parentElement = _parentElement; + return true; +} + ////////////////////////////////////////////////// void Param::Reset() {