gazebosim / gazebosim/sdformat
Add Element::GetElementCount()
- Dominant language
- C++
- Stars
- 216
- Forks
- 125
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 14
Description
**Original report ([archived issue](https://osrf-migration.github.io/sdformat-gh-pages/#!/osrf/sdformat/issues/156)) by Martin Pecka (Bitbucket: [peci1](https://bitbucket.org/%7B41691c43-4ae0-49ba-ba45-3c36439f5af2%7D/)).**
----------------------------------------
The `Element` class is missing method `GetElementCount`, and probably also `IsEmpty`.
The first one should just return `this->dataPtr->elements.size()`, the latter could probably return true if the element has no attributes and no child elements.
Adding at least the `GetElementCount` method would complete the API, where `GetAttributeCount` and `GetElementDescriptionCount` already exist.
Without this method, it is cumbersome to verify whether an element has any child elements. This is what I've come up with (it contains a completely useless object creation, which may get expensive):
auto isEmpty = element->GetFirstElement() != sdf::ElementPtr();
The cumbersomeness of this approach is elevated by the fact that `GetFirstElement` has no documentation at all, so there's no place that'd promise that `GetFirstElement` will always return a pointer to an empty element and not e.g. `nullptr`.
Contributor guide
Research direction
Start by locating the Element class and comparing its existing GetAttributeCount and GetElementDescriptionCount APIs. Confirm where the public declaration and implementation belong, then verify that the requested child-element count behavior is covered; treat IsEmpty as optional because the report requires at least GetElementCount.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100