You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
jslee02
changed the title
Consistent interface of container classes and const_ptr_vector
Consistent interface of container class for element access
Feb 17, 2016
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.
DART has many container classes. For example,
Skeleton
is a container ofBodyNode
andMarker
, andJoint
is a container ofDegreeOfFreedom
. 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*>&
andconst 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.
The text was updated successfully, but these errors were encountered: