Das-Kollektiv / tdme2

TDME2 - ThreeDeeMiniEngine2 is a lightweight, multi-platform 3D engine including tools suited for 3D game/application development using C++, Mini(t)Script, GLSL, ...
Other
176 stars 29 forks source link

javacpp-port: Return STL container references instead of pointers if feasible #7

Closed andreasdr closed 5 years ago

andreasdr commented 6 years ago

There seem to be some getters that return pointers of STL containers like vector and map. As long as the container is always backed and the method never returns nullptr I like to have it changed to returning references as this seems to be the most common practice.

You can see those methods by using the following grep queries

Please be careful though as assignments then means copying if not using reference operator like:

In most cases you do not want: auto vertices = group->getVertices(); But: auto& vertices = group->getVertices();

Thanx @mahula

andreasdr commented 6 years ago

In some cases constness might be relevant, but only in a few. If unsure ask.

mahula commented 5 years ago

@andreasdr does that only concern the STL Vector and Map?

andreasdr commented 5 years ago

It is about every STL container.

mahula commented 5 years ago

Checked it - grep -Enr '>\* ([A-Za-Z]+::){0,1}get[[:upper:]]' src/tdme/ It concerns array, vector, and map.

You can search the containers separately: The lines where pointers to STL containers are return values of getter methods

STL vector grep -Enr 'vector<[A-Za-z0-9*&]+>\* ([A-Za-Z]+::){0,1}get[[:upper:]]' src/tdme/

STL map grep -Enr 'map<[A-Za-z0-9*&]+, *[A-Za-z0-9*&]+>\* ([A-Za-Z]+::){0,1}get[[:upper:]]' src/tdme/

STL array grep -Enr 'array<[A-Za-z0-9*&_]+, *[0-9]+>\* ([A-Za-Z]+::){0,1}get[[:upper:]]' src/tdme/

andreasdr commented 5 years ago

Looks good. Thank you. I am closing this issue.