-
Notifications
You must be signed in to change notification settings - Fork 107
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
Add Element::FindElement as an alternative to Element::GetElement #620
Conversation
`Element::GetElement` may create a child element if it doesn't exist. This makes it a non-const function. Instead of changing this behavior, a new function `Element::FindElement` is added that returns a nullptr if the child element is not found instead of creating a new element. Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Omg, this is great!
src/Element_TEST.cc
Outdated
@@ -825,6 +825,25 @@ TEST(Element, GetNextElementMultiple) | |||
ASSERT_EQ(child2->GetNextElement(""), nullptr); | |||
} | |||
|
|||
///////////////////////////////////////////////// | |||
/// Helper function to add child elements without having to create descriptions | |||
sdf::ElementPtr AddChildElement(sdf::ElementPtr _parent, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: we usually use camelCase
for free functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in d519304. I'm never sure what to do about free functions and static functions because I think we diverge from the google style guide on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we don't have this documented anywhere, it's one of those things that we need to document
`Element::GetElement` may create a child element if it doesn't exist. This makes it a non-const function. Instead of changing this behavior, a new function `Element::FindElement` is added that returns a nullptr if the child element is not found instead of creating a new element. Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org> Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
🎉 New feature
Closes #188
Summary
Element::GetElement
may create a child element if it doesn't exist.This makes it a non-const function. Instead of changing this behavior, a
new function
Element::FindElement
is added that returns anullptr
ifthe child element is not found instead of creating a new element.
Test it
Run test
UNIT_Element_TEST
.Checklist
codecheck
passed (See contributing)Note to maintainers: Remember to use Squash-Merge