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

Consistent interface of container class for element access #613

Closed
jslee02 opened this issue Feb 17, 2016 · 2 comments · Fixed by #1644
Closed

Consistent interface of container class for element access #613

jslee02 opened this issue Feb 17, 2016 · 2 comments · Fixed by #1644
Milestone

Comments

@jslee02
Copy link
Member

jslee02 commented Feb 17, 2016

DART has many container classes. For example, Skeleton is a container of BodyNode and Marker, and Joint is a container of DegreeOfFreedom. To access the elements of the containers, there are two styles of interface: (1) getNum(Object)() / getObject(index) and (2) const vector getObjects(). Some container provide only (1), others provide (2), and some provide both, which is not consistent.

I would like to propose to have a consistent interface or, at least, have an interface that returns an iterable object like std::vector<Object*>. With the iterable object, we can utilize the advantage of ranged-based for loop of C++11, which provides a neater way of iterating the elements.

Also, in most cases, container classes return const reference of the iterable object that contains const/non-const pointers like const std::vector<BodyNode*>& and const std::vector<const BodyNode*>&. For this, two ways are used: (1) having two iterable objects in it, (2) return a const_cast-ed copy of the iterable object. Both of them have downsides: (1) requires unnecessary memory, and (2) requires unnecessary computation for creating the iterable object every time the accessor is called.

To resolve this, I'd like to propose a wrapper class of pointer container that provides a customized iterator for const_cast when the element is accessed instead of holding the copy of const_cast-ed elements inside it. I thought there must be others having a similar issue and reasonable solution, but couldn't find. Please let me know if it's not.

Here is a brief sketch of the wrapper class with tests.

@jslee02 jslee02 changed the title Consistent interface of container classes and const_ptr_vector Consistent interface of container class for element access Feb 17, 2016
@stale
Copy link

stale bot commented Feb 13, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@jslee02
Copy link
Member Author

jslee02 commented Jan 6, 2022

Resolved by #1644

@jslee02 jslee02 closed this as completed Jan 6, 2022
@jslee02 jslee02 linked a pull request Jan 6, 2022 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant