Make mjSpec related getter/find utilities take const parameters.

PiperOrigin-RevId: 910848529
Change-Id: I1c966a6299fe47317cbf0bfb8f8b835cbcd4ed65
This commit is contained in:
Sam Haves
2026-05-05 12:34:58 -07:00
committed by Copybara-Service
parent d249c882d5
commit 579a27e9d2
10 changed files with 175 additions and 181 deletions
+4 -4
View File
@@ -2251,7 +2251,7 @@ mjCBase* mjCBody::GetObject(mjtObj type, int i) {
// find object by name in given list
template <class T>
static T* findobject(std::string name, std::vector<T*>& list) {
static T* findobject(const std::string& name, const std::vector<T*>& list) {
for (unsigned int i=0; i < list.size(); i++) {
if (list[i]->name == name) {
return list[i];
@@ -2264,12 +2264,12 @@ static T* findobject(std::string name, std::vector<T*>& list) {
// recursive find by name
mjCBase* mjCBody::FindObject(mjtObj type, std::string _name, bool recursive) {
mjCBase* mjCBody::FindObject(mjtObj type, const std::string& _name, bool recursive) const {
mjCBase* res = 0;
// check self: just in case
if (name == _name) {
return this;
return const_cast<mjCBody*>(this);
}
// search elements of this body
@@ -2406,7 +2406,7 @@ static mjsElement* GetNextBody(const mjCBody* body, const mjsElement* child,
// get next child of given type
mjsElement* mjCBody::NextChild(const mjsElement* child, mjtObj type, bool recursive) {
mjsElement* mjCBody::NextChild(const mjsElement* child, mjtObj type, bool recursive) const {
if (type == mjOBJ_UNKNOWN) {
if (!child) {
throw mjCError(this, "child type must be specified if no child element is given");