Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't reparse parent elements when cloning. #1484

Merged
merged 10 commits into from
Dec 20, 2024
8 changes: 8 additions & 0 deletions include/sdf/Param.hh
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,14 @@ 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.
/// \return True if the parent Element was set.
public: bool SetParentElementNoReparse(
ElementPtr _parentElement);

/// \brief Reset the parameter to the default value.
public: void Reset();

Expand Down
4 changes: 2 additions & 2 deletions src/Element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.");
}

Expand Down
7 changes: 7 additions & 0 deletions src/Param.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Loading