Make mjSpec related getter/find utilities take const parameters.
PiperOrigin-RevId: 910848529 Change-Id: I1c966a6299fe47317cbf0bfb8f8b835cbcd4ed65
This commit is contained in:
committed by
Copybara-Service
parent
d249c882d5
commit
579a27e9d2
+53
-59
@@ -1302,61 +1302,56 @@ const char* mjs_setToDCMotor(mjsActuator* actuator, double motorconst[2], double
|
||||
|
||||
|
||||
// get spec from body
|
||||
mjSpec* mjs_getSpec(mjsElement* element) {
|
||||
return &(static_cast<mjCBase*>(element)->model->spec);
|
||||
mjSpec* mjs_getSpec(const mjsElement* element) {
|
||||
return &(static_cast<const mjCBase*>(element)->model->spec);
|
||||
}
|
||||
|
||||
|
||||
|
||||
mjsCompiler* mjs_getCompiler(mjsElement* element) {
|
||||
return static_cast<mjCBase*>(element)->compiler;
|
||||
mjsCompiler* mjs_getCompiler(const mjsElement* element) {
|
||||
return static_cast<const mjCBase*>(element)->compiler;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// find spec (model asset) by name
|
||||
mjSpec* mjs_findSpec(mjSpec* s, const char* name) {
|
||||
mjCModel* model = static_cast<mjCModel*>(s->element);
|
||||
mjSpec* mjs_findSpec(const mjSpec* s, const char* name) {
|
||||
const mjCModel* model = static_cast<mjCModel*>(s->element);
|
||||
return model->FindSpec(name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// get default
|
||||
mjsDefault* mjs_getDefault(mjsElement* element) {
|
||||
mjCModel* model = static_cast<mjCBase*>(element)->model;
|
||||
std::string classname = static_cast<mjCBase*>(element)->classname;
|
||||
return &(model->def_map[classname]->spec);
|
||||
mjsDefault* mjs_getDefault(const mjsElement* element) {
|
||||
const mjCModel* model = static_cast<const mjCBase*>(element)->model;
|
||||
std::string classname = static_cast<const mjCBase*>(element)->classname;
|
||||
auto it = model->def_map.find(classname);
|
||||
return (it != model->def_map.end()) ? &it->second->spec : nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Find default with given name in model.
|
||||
mjsDefault* mjs_findDefault(mjSpec* s, const char* classname) {
|
||||
mjCModel* modelC = static_cast<mjCModel*>(s->element);
|
||||
mjsDefault* mjs_findDefault(const mjSpec* s, const char* classname) {
|
||||
const mjCModel* modelC = static_cast<mjCModel*>(s->element);
|
||||
mjCDef* cdef = modelC->FindDefault(classname);
|
||||
if (!cdef) {
|
||||
return nullptr;
|
||||
}
|
||||
return &cdef->spec;
|
||||
return cdef ? &cdef->spec : nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// get default[0] from model
|
||||
mjsDefault* mjs_getSpecDefault(mjSpec* s) {
|
||||
mjCModel* modelC = static_cast<mjCModel*>(s->element);
|
||||
mjsDefault* mjs_getSpecDefault(const mjSpec* s) {
|
||||
const mjCModel* modelC = static_cast<mjCModel*>(s->element);
|
||||
mjCDef* def = modelC->Default();
|
||||
if (!def) {
|
||||
return nullptr;
|
||||
}
|
||||
return &def->spec;
|
||||
return def ? &def->spec : nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// find body in model by name
|
||||
mjsBody* mjs_findBody(mjSpec* s, const char* name) {
|
||||
mjsBody* mjs_findBody(const mjSpec* s, const char* name) {
|
||||
mjsElement* body = mjs_findElement(s, mjOBJ_BODY, name);
|
||||
return body ? &(static_cast<mjCBody*>(body)->spec) : nullptr;
|
||||
}
|
||||
@@ -1364,7 +1359,7 @@ mjsBody* mjs_findBody(mjSpec* s, const char* name) {
|
||||
|
||||
|
||||
// find element in spec by name
|
||||
mjsElement* mjs_findElement(mjSpec* s, mjtObj type, const char* name) {
|
||||
mjsElement* mjs_findElement(const mjSpec* s, mjtObj type, const char* name) {
|
||||
mjCModel* model = static_cast<mjCModel*>(s->element);
|
||||
if (model->IsCompiled() && type != mjOBJ_FRAME) {
|
||||
return model->FindObject(type, std::string(name)); // fast lookup
|
||||
@@ -1390,8 +1385,8 @@ mjsElement* mjs_findElement(mjSpec* s, mjtObj type, const char* name) {
|
||||
|
||||
|
||||
// find child of a body by name
|
||||
mjsBody* mjs_findChild(mjsBody* bodyspec, const char* name) {
|
||||
mjCBody* body = static_cast<mjCBody*>(bodyspec->element);
|
||||
mjsBody* mjs_findChild(const mjsBody* bodyspec, const char* name) {
|
||||
const mjCBody* body = static_cast<mjCBody*>(bodyspec->element);
|
||||
mjCBase* child = body->FindObject(mjOBJ_BODY, std::string(name));
|
||||
return child ? &(static_cast<mjCBody*>(child)->spec) : nullptr;
|
||||
}
|
||||
@@ -1399,22 +1394,22 @@ mjsBody* mjs_findChild(mjsBody* bodyspec, const char* name) {
|
||||
|
||||
|
||||
// get parent body
|
||||
mjsBody* mjs_getParent(mjsElement* element) {
|
||||
mjsBody* mjs_getParent(const mjsElement* element) {
|
||||
switch (element->elemtype) {
|
||||
case mjOBJ_BODY:
|
||||
return &(static_cast<mjCBody*>(element)->GetParent()->spec);
|
||||
return &(static_cast<const mjCBody*>(element)->GetParent()->spec);
|
||||
case mjOBJ_FRAME:
|
||||
return &(static_cast<mjCFrame*>(element)->GetParent()->spec);
|
||||
return &(static_cast<const mjCFrame*>(element)->GetParent()->spec);
|
||||
case mjOBJ_JOINT:
|
||||
return &(static_cast<mjCJoint*>(element)->GetParent()->spec);
|
||||
return &(static_cast<const mjCJoint*>(element)->GetParent()->spec);
|
||||
case mjOBJ_GEOM:
|
||||
return &(static_cast<mjCGeom*>(element)->GetParent()->spec);
|
||||
return &(static_cast<const mjCGeom*>(element)->GetParent()->spec);
|
||||
case mjOBJ_SITE:
|
||||
return &(static_cast<mjCSite*>(element)->GetParent()->spec);
|
||||
return &(static_cast<const mjCSite*>(element)->GetParent()->spec);
|
||||
case mjOBJ_CAMERA:
|
||||
return &(static_cast<mjCCamera*>(element)->GetParent()->spec);
|
||||
return &(static_cast<const mjCCamera*>(element)->GetParent()->spec);
|
||||
case mjOBJ_LIGHT:
|
||||
return &(static_cast<mjCLight*>(element)->GetParent()->spec);
|
||||
return &(static_cast<const mjCLight*>(element)->GetParent()->spec);
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
@@ -1423,8 +1418,8 @@ mjsBody* mjs_getParent(mjsElement* element) {
|
||||
|
||||
|
||||
// get parent frame
|
||||
mjsFrame* mjs_getFrame(mjsElement* element) {
|
||||
mjCBase* base = static_cast<mjCBase*>(element);
|
||||
mjsFrame* mjs_getFrame(const mjsElement* element) {
|
||||
const mjCBase* base = static_cast<const mjCBase*>(element);
|
||||
switch (element->elemtype) {
|
||||
case mjOBJ_BODY:
|
||||
case mjOBJ_FRAME:
|
||||
@@ -1442,7 +1437,7 @@ mjsFrame* mjs_getFrame(mjsElement* element) {
|
||||
|
||||
|
||||
// find frame by name
|
||||
mjsFrame* mjs_findFrame(mjSpec* s, const char* name) {
|
||||
mjsFrame* mjs_findFrame(const mjSpec* s, const char* name) {
|
||||
mjsElement* frame = mjs_findElement(s, mjOBJ_FRAME, name);
|
||||
return frame ? &(static_cast<mjCFrame*>(frame)->spec) : nullptr;
|
||||
}
|
||||
@@ -1601,11 +1596,11 @@ int mjs_sensorDim(const mjsSensor* sensor) {
|
||||
|
||||
|
||||
// get id
|
||||
int mjs_getId(mjsElement* element) {
|
||||
int mjs_getId(const mjsElement* element) {
|
||||
if (!element) {
|
||||
return -1;
|
||||
}
|
||||
return static_cast<mjCBase*>(element)->id;
|
||||
return static_cast<const mjCBase*>(element)->id;
|
||||
}
|
||||
|
||||
|
||||
@@ -1619,8 +1614,8 @@ void mjs_setDefault(mjsElement* element, const mjsDefault* defspec) {
|
||||
|
||||
|
||||
// return first child of selected type
|
||||
mjsElement* mjs_firstChild(mjsBody* body, mjtObj type, int recurse) {
|
||||
mjCBody* bodyC = static_cast<mjCBody*>(body->element);
|
||||
mjsElement* mjs_firstChild(const mjsBody* body, mjtObj type, int recurse) {
|
||||
const mjCBody* bodyC = static_cast<const mjCBody*>(body->element);
|
||||
try {
|
||||
return bodyC->NextChild(NULL, type, recurse);
|
||||
} catch (mjCError& e) {
|
||||
@@ -1632,8 +1627,8 @@ mjsElement* mjs_firstChild(mjsBody* body, mjtObj type, int recurse) {
|
||||
|
||||
|
||||
// return body's next child; return NULL if child is last
|
||||
mjsElement* mjs_nextChild(mjsBody* body, mjsElement* child, int recurse) {
|
||||
mjCBody* bodyC = static_cast<mjCBody*>(body->element);
|
||||
mjsElement* mjs_nextChild(const mjsBody* body, const mjsElement* child, int recurse) {
|
||||
const mjCBody* bodyC = static_cast<const mjCBody*>(body->element);
|
||||
try {
|
||||
return bodyC->NextChild(child, child->elemtype, recurse);
|
||||
} catch(mjCError& e) {
|
||||
@@ -1645,23 +1640,23 @@ mjsElement* mjs_nextChild(mjsBody* body, mjsElement* child, int recurse) {
|
||||
|
||||
|
||||
// return spec's first element of selected type
|
||||
mjsElement* mjs_firstElement(mjSpec* s, mjtObj type) {
|
||||
mjCModel* modelC = static_cast<mjCModel*>(s->element);
|
||||
mjsElement* mjs_firstElement(const mjSpec* s, mjtObj type) {
|
||||
const mjCModel* modelC = static_cast<mjCModel*>(s->element);
|
||||
return modelC->NextObject(NULL, type);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// return spec's next element; return NULL if element is last
|
||||
mjsElement* mjs_nextElement(mjSpec* s, mjsElement* element) {
|
||||
mjCModel* modelC = static_cast<mjCModel*>(s->element);
|
||||
mjsElement* mjs_nextElement(const mjSpec* s, const mjsElement* element) {
|
||||
const mjCModel* modelC = static_cast<mjCModel*>(s->element);
|
||||
return modelC->NextObject(element);
|
||||
}
|
||||
|
||||
|
||||
|
||||
mjsElement* mjs_getWrapTarget(mjsWrap* wrap) {
|
||||
mjCWrap* cwrap = static_cast<mjCWrap*>(wrap->element);
|
||||
mjsElement* mjs_getWrapTarget(const mjsWrap* wrap) {
|
||||
const mjCWrap* cwrap = static_cast<const mjCWrap*>(wrap->element);
|
||||
mjtObj type = mjOBJ_UNKNOWN;
|
||||
switch (cwrap->Type()) {
|
||||
case mjWRAP_SPHERE:
|
||||
@@ -1680,15 +1675,14 @@ mjsElement* mjs_getWrapTarget(mjsWrap* wrap) {
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
mjSpec* spec = mjs_getSpec(wrap->element);
|
||||
mjsElement* target = mjs_findElement(spec, type, cwrap->name.c_str());
|
||||
return target;
|
||||
const mjSpec* spec = mjs_getSpec(wrap->element);
|
||||
return mjs_findElement(spec, type, cwrap->name.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
mjsSite* mjs_getWrapSideSite(mjsWrap* wrap) {
|
||||
mjCWrap* cwrap = static_cast<mjCWrap*>(wrap->element);
|
||||
mjsSite* mjs_getWrapSideSite(const mjsWrap* wrap) {
|
||||
const mjCWrap* cwrap = static_cast<const mjCWrap*>(wrap->element);
|
||||
// only sphere and cylinder (geoms) have side sites
|
||||
if ((cwrap->Type() != mjWRAP_SPHERE &&
|
||||
cwrap->Type() != mjWRAP_CYLINDER) ||
|
||||
@@ -1696,7 +1690,7 @@ mjsSite* mjs_getWrapSideSite(mjsWrap* wrap) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
mjSpec* spec = mjs_getSpec(wrap->element);
|
||||
const mjSpec* spec = mjs_getSpec(wrap->element);
|
||||
mjsElement* site = mjs_findElement(spec, mjOBJ_SITE, cwrap->sidesite.c_str());
|
||||
if (site == nullptr) {
|
||||
mju_warning("Could not find side site %s for wrap %s in spec",
|
||||
@@ -1708,8 +1702,8 @@ mjsSite* mjs_getWrapSideSite(mjsWrap* wrap) {
|
||||
|
||||
|
||||
|
||||
double mjs_getWrapDivisor(mjsWrap* wrap) {
|
||||
mjCWrap* cwrap = static_cast<mjCWrap*>(wrap->element);
|
||||
double mjs_getWrapDivisor(const mjsWrap* wrap) {
|
||||
const mjCWrap* cwrap = static_cast<const mjCWrap*>(wrap->element);
|
||||
if (cwrap->Type() != mjWRAP_PULLEY) {
|
||||
mju_warning("Querying divisor attribute of non-pulley wrap: %s", cwrap->name.c_str());
|
||||
return 1.0;
|
||||
@@ -1719,8 +1713,8 @@ double mjs_getWrapDivisor(mjsWrap* wrap) {
|
||||
|
||||
|
||||
|
||||
double mjs_getWrapCoef(mjsWrap* wrap) {
|
||||
mjCWrap* cwrap = static_cast<mjCWrap*>(wrap->element);
|
||||
double mjs_getWrapCoef(const mjsWrap* wrap) {
|
||||
const mjCWrap* cwrap = static_cast<const mjCWrap*>(wrap->element);
|
||||
if (cwrap->Type() != mjWRAP_JOINT) {
|
||||
mju_warning("Querying coef attribute of non-joint wrap: %s", cwrap->name.c_str());
|
||||
return 1.0;
|
||||
|
||||
+20
-20
@@ -222,68 +222,68 @@ MJAPI int mjs_makeMesh(mjsMesh* mesh, mjtMeshBuiltin builtin, double* params, in
|
||||
//---------------------------------- Find/get utilities --------------------------------------------
|
||||
|
||||
// Get spec from body.
|
||||
MJAPI mjSpec* mjs_getSpec(mjsElement* element);
|
||||
MJAPI mjSpec* mjs_getSpec(const mjsElement* element);
|
||||
|
||||
// Find spec (model asset) by name.
|
||||
MJAPI mjSpec* mjs_findSpec(mjSpec* spec, const char* name);
|
||||
MJAPI mjSpec* mjs_findSpec(const mjSpec* spec, const char* name);
|
||||
|
||||
// Find body in spec by name.
|
||||
MJAPI mjsBody* mjs_findBody(mjSpec* s, const char* name);
|
||||
MJAPI mjsBody* mjs_findBody(const mjSpec* s, const char* name);
|
||||
|
||||
// Find element in spec by name.
|
||||
MJAPI mjsElement* mjs_findElement(mjSpec* s, mjtObj type, const char* name);
|
||||
MJAPI mjsElement* mjs_findElement(const mjSpec* s, mjtObj type, const char* name);
|
||||
|
||||
// Find child body by name.
|
||||
MJAPI mjsBody* mjs_findChild(mjsBody* body, const char* name);
|
||||
MJAPI mjsBody* mjs_findChild(const mjsBody* body, const char* name);
|
||||
|
||||
// Get parent body.
|
||||
MJAPI mjsBody* mjs_getParent(mjsElement* element);
|
||||
MJAPI mjsBody* mjs_getParent(const mjsElement* element);
|
||||
|
||||
// Get parent frame.
|
||||
MJAPI mjsFrame* mjs_getFrame(mjsElement* element);
|
||||
MJAPI mjsFrame* mjs_getFrame(const mjsElement* element);
|
||||
|
||||
// Find frame by name.
|
||||
MJAPI mjsFrame* mjs_findFrame(mjSpec* s, const char* name);
|
||||
MJAPI mjsFrame* mjs_findFrame(const mjSpec* s, const char* name);
|
||||
|
||||
// Get default corresponding to an element.
|
||||
MJAPI mjsDefault* mjs_getDefault(mjsElement* element);
|
||||
MJAPI mjsDefault* mjs_getDefault(const mjsElement* element);
|
||||
|
||||
// Find default in model by class name.
|
||||
MJAPI mjsDefault* mjs_findDefault(mjSpec* s, const char* classname);
|
||||
MJAPI mjsDefault* mjs_findDefault(const mjSpec* s, const char* classname);
|
||||
|
||||
// Get global default from model.
|
||||
MJAPI mjsDefault* mjs_getSpecDefault(mjSpec* s);
|
||||
MJAPI mjsDefault* mjs_getSpecDefault(const mjSpec* s);
|
||||
|
||||
// Get element id.
|
||||
MJAPI int mjs_getId(mjsElement* element);
|
||||
MJAPI int mjs_getId(const mjsElement* element);
|
||||
|
||||
|
||||
//---------------------------------- Tree traversal ------------------------------------------------
|
||||
|
||||
// Return body's first child of given type. If recurse is nonzero, also search the body's subtree.
|
||||
MJAPI mjsElement* mjs_firstChild(mjsBody* body, mjtObj type, int recurse);
|
||||
MJAPI mjsElement* mjs_firstChild(const mjsBody* body, mjtObj type, int recurse);
|
||||
|
||||
// Return body's next child of the same type; return NULL if child is last.
|
||||
// If recurse is nonzero, also search the body's subtree.
|
||||
MJAPI mjsElement* mjs_nextChild(mjsBody* body, mjsElement* child, int recurse);
|
||||
MJAPI mjsElement* mjs_nextChild(const mjsBody* body, const mjsElement* child, int recurse);
|
||||
|
||||
// Return spec's first element of selected type.
|
||||
MJAPI mjsElement* mjs_firstElement(mjSpec* s, mjtObj type);
|
||||
MJAPI mjsElement* mjs_firstElement(const mjSpec* s, mjtObj type);
|
||||
|
||||
// Return spec's next element; return NULL if element is last.
|
||||
MJAPI mjsElement* mjs_nextElement(mjSpec* s, mjsElement* element);
|
||||
MJAPI mjsElement* mjs_nextElement(const mjSpec* s, const mjsElement* element);
|
||||
|
||||
// Get wrapped element in tendon path.
|
||||
MJAPI mjsElement* mjs_getWrapTarget(mjsWrap* wrap);
|
||||
MJAPI mjsElement* mjs_getWrapTarget(const mjsWrap* wrap);
|
||||
|
||||
// Get wrapped element in tendon path.
|
||||
MJAPI mjsSite* mjs_getWrapSideSite(mjsWrap* wrap);
|
||||
MJAPI mjsSite* mjs_getWrapSideSite(const mjsWrap* wrap);
|
||||
|
||||
// Get divisor of mjsWrap wrapping a puller.
|
||||
MJAPI double mjs_getWrapDivisor(mjsWrap* wrap);
|
||||
MJAPI double mjs_getWrapDivisor(const mjsWrap* wrap);
|
||||
|
||||
// Get coefficient of mjsWrap wrapping a joint.
|
||||
MJAPI double mjs_getWrapCoef(mjsWrap* wrap);
|
||||
MJAPI double mjs_getWrapCoef(const mjsWrap* wrap);
|
||||
|
||||
// Safely cast an element as mjsBody, or return NULL if the element is not an mjsBody.
|
||||
MJAPI mjsBody* mjs_asBody(mjsElement* element);
|
||||
|
||||
@@ -1408,7 +1408,7 @@ mjCBase* mjCModel::GetObject(mjtObj type, int id) {
|
||||
|
||||
|
||||
template <class T>
|
||||
static mjsElement* GetNext(std::vector<T*>& list, mjsElement* child) {
|
||||
static mjsElement* GetNext(const std::vector<T*>& list, const mjsElement* child) {
|
||||
if (!child) {
|
||||
if (list.empty()) {
|
||||
return nullptr;
|
||||
@@ -1428,7 +1428,7 @@ static mjsElement* GetNext(std::vector<T*>& list, mjsElement* child) {
|
||||
|
||||
|
||||
// next object of specified type
|
||||
mjsElement* mjCModel::NextObject(mjsElement* object, mjtObj type) {
|
||||
mjsElement* mjCModel::NextObject(const mjsElement* object, mjtObj type) const {
|
||||
if (type == mjOBJ_UNKNOWN) {
|
||||
if (!object) {
|
||||
throw mjCError(nullptr, "type must be specified if no element is given");
|
||||
@@ -1519,7 +1519,7 @@ mjCBody* mjCModel::GetWorld() {
|
||||
|
||||
|
||||
// find default class name in array
|
||||
mjCDef* mjCModel::FindDefault(string name) {
|
||||
mjCDef* mjCModel::FindDefault(const string& name) const {
|
||||
for (int i=0; i < (int)defaults_.size(); i++) {
|
||||
if (defaults_[i]->name == name) {
|
||||
return defaults_[i];
|
||||
@@ -1697,13 +1697,13 @@ mjSpec* mjCModel::FindSpec(std::string name) const {
|
||||
|
||||
|
||||
// find spec by mjsCompiler pointer
|
||||
mjSpec* mjCModel::FindSpec(const mjsCompiler* compiler_) {
|
||||
mjSpec* mjCModel::FindSpec(const mjsCompiler* compiler_) const {
|
||||
if (compiler_ == &spec.compiler) {
|
||||
return &spec;
|
||||
return &const_cast<mjCModel*>(this)->spec;
|
||||
}
|
||||
|
||||
if (compiler2spec_.find(compiler_) != compiler2spec_.end()) {
|
||||
return compiler2spec_[compiler_];
|
||||
if (auto it = compiler2spec_.find(compiler_); it != compiler2spec_.end()) {
|
||||
return it->second;
|
||||
}
|
||||
|
||||
for (auto s : specs_) {
|
||||
|
||||
@@ -242,19 +242,19 @@ class mjCModel : public mjCModel_, private mjSpec {
|
||||
// API for access to model elements (outside tree)
|
||||
int NumObjects(mjtObj type); // number of objects in specified list
|
||||
mjCBase* GetObject(mjtObj type, int id); // pointer to specified object
|
||||
mjsElement* NextObject(mjsElement* object, mjtObj type = mjOBJ_UNKNOWN); // next object of specified type
|
||||
mjsElement* NextObject(const mjsElement* object, mjtObj type = mjOBJ_UNKNOWN) const; // next object of specified type
|
||||
|
||||
// API for access to other variables
|
||||
bool IsCompiled() const; // is model already compiled
|
||||
const mjCError& GetError() const; // get reference of error object
|
||||
void SetError(const mjCError& error) { errInfo = error; } // set value of error object
|
||||
mjCBody* GetWorld(); // pointer to world body
|
||||
mjCDef* FindDefault(std::string name); // find defaults class name
|
||||
mjCDef* FindDefault(const std::string& name) const; // find defaults class name
|
||||
mjCDef* AddDefault(std::string name, mjCDef* parent = nullptr); // add defaults class to array
|
||||
mjCBase* FindObject(mjtObj type, std::string name) const; // find object given type and name
|
||||
mjCBase* FindTree(mjCBody* body, mjtObj type, std::string name); // find tree object given name
|
||||
mjSpec* FindSpec(std::string name) const; // find spec given name
|
||||
mjSpec* FindSpec(const mjsCompiler* compiler_); // find spec given mjsCompiler
|
||||
mjSpec* FindSpec(const mjsCompiler* compiler_) const; // find spec given mjsCompiler
|
||||
void ActivatePlugin(const mjpPlugin* plugin, int slot); // activate plugin
|
||||
|
||||
// find asset given name checking both name and filename
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -531,7 +531,7 @@ class mjCBody : public mjCBody_, private mjsBody {
|
||||
// API for accessing objects
|
||||
int NumObjects(mjtObj type);
|
||||
mjCBase* GetObject(mjtObj type, int id);
|
||||
mjCBase* FindObject(mjtObj type, std::string name, bool recursive = true);
|
||||
mjCBase* FindObject(mjtObj type, const std::string& name, bool recursive = true) const;
|
||||
|
||||
// Propagate suffix and prefix to the whole tree
|
||||
void NameSpace(const mjCModel* m);
|
||||
@@ -556,7 +556,7 @@ class mjCBody : public mjCBody_, private mjsBody {
|
||||
// returns nullptr if the next child is not found or if `child` is the last element, returns
|
||||
// the next child after the input `child` otherwise
|
||||
mjsElement* NextChild(const mjsElement* child, mjtObj type = mjOBJ_UNKNOWN,
|
||||
bool recursive = false);
|
||||
bool recursive = false) const;
|
||||
|
||||
// reset keyframe references for allowing self-attach
|
||||
void ForgetKeyframes() const;
|
||||
|
||||
Reference in New Issue
Block a user