Skip to content

Commit

Permalink
Don't reparse parent elements when cloning. (#1484)
Browse files Browse the repository at this point in the history
Reparse was added in #589 to deal with the possibility that the meaning of an Element's value depends on the attributes in the element and those attributes might be different when reparenting. However, this does not apply when cloning since there will be no change in the attributes in the cloned element.

---------

Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Addisu Z. Taddese <[email protected]>
Co-authored-by: Steve Peters <[email protected]>
Co-authored-by: Addisu Z. Taddese <[email protected]>
  • Loading branch information
3 people authored Dec 20, 2024
1 parent 69c82c0 commit c8fdaa0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
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

0 comments on commit c8fdaa0

Please sign in to comment.