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
+21 -21
View File
@@ -3686,27 +3686,27 @@ mjsSkin* mjs_addSkin(mjSpec* s);
mjsTexture* mjs_addTexture(mjSpec* s); mjsTexture* mjs_addTexture(mjSpec* s);
mjsMaterial* mjs_addMaterial(mjSpec* s, const mjsDefault* def); mjsMaterial* mjs_addMaterial(mjSpec* s, const mjsDefault* def);
int mjs_makeMesh(mjsMesh* mesh, mjtMeshBuiltin builtin, double* params, int nparams); int mjs_makeMesh(mjsMesh* mesh, mjtMeshBuiltin builtin, double* params, int nparams);
mjSpec* mjs_getSpec(mjsElement* element); mjSpec* mjs_getSpec(const mjsElement* element);
mjsCompiler* mjs_getCompiler(mjsElement* element); mjsCompiler* mjs_getCompiler(const mjsElement* element);
mjSpec* mjs_findSpec(mjSpec* spec, const char* name); mjSpec* mjs_findSpec(const mjSpec* spec, const char* name);
mjsBody* mjs_findBody(mjSpec* s, const char* name); mjsBody* mjs_findBody(const mjSpec* s, const char* name);
mjsElement* mjs_findElement(mjSpec* s, mjtObj type, const char* name); mjsElement* mjs_findElement(const mjSpec* s, mjtObj type, const char* name);
mjsBody* mjs_findChild(mjsBody* body, const char* name); mjsBody* mjs_findChild(const mjsBody* body, const char* name);
mjsBody* mjs_getParent(mjsElement* element); mjsBody* mjs_getParent(const mjsElement* element);
mjsFrame* mjs_getFrame(mjsElement* element); mjsFrame* mjs_getFrame(const mjsElement* element);
mjsFrame* mjs_findFrame(mjSpec* s, const char* name); mjsFrame* mjs_findFrame(const mjSpec* s, const char* name);
mjsDefault* mjs_getDefault(mjsElement* element); mjsDefault* mjs_getDefault(const mjsElement* element);
mjsDefault* mjs_findDefault(mjSpec* s, const char* classname); mjsDefault* mjs_findDefault(const mjSpec* s, const char* classname);
mjsDefault* mjs_getSpecDefault(mjSpec* s); mjsDefault* mjs_getSpecDefault(const mjSpec* s);
int mjs_getId(mjsElement* element); int mjs_getId(const mjsElement* element);
mjsElement* mjs_firstChild(mjsBody* body, mjtObj type, int recurse); mjsElement* mjs_firstChild(const mjsBody* body, mjtObj type, int recurse);
mjsElement* mjs_nextChild(mjsBody* body, mjsElement* child, int recurse); mjsElement* mjs_nextChild(const mjsBody* body, const mjsElement* child, int recurse);
mjsElement* mjs_firstElement(mjSpec* s, mjtObj type); mjsElement* mjs_firstElement(const mjSpec* s, mjtObj type);
mjsElement* mjs_nextElement(mjSpec* s, mjsElement* element); mjsElement* mjs_nextElement(const mjSpec* s, const mjsElement* element);
mjsElement* mjs_getWrapTarget(mjsWrap* wrap); mjsElement* mjs_getWrapTarget(const mjsWrap* wrap);
mjsSite* mjs_getWrapSideSite(mjsWrap* wrap); mjsSite* mjs_getWrapSideSite(const mjsWrap* wrap);
double mjs_getWrapDivisor(mjsWrap* wrap); double mjs_getWrapDivisor(const mjsWrap* wrap);
double mjs_getWrapCoef(mjsWrap* wrap); double mjs_getWrapCoef(const mjsWrap* wrap);
int mjs_setName(mjsElement* element, const char* name); int mjs_setName(mjsElement* element, const char* name);
void mjs_setBuffer(mjByteVec* dest, const void* array, int size); void mjs_setBuffer(mjByteVec* dest, const void* array, int size);
void mjs_setString(mjString* dest, const char* text); void mjs_setString(mjString* dest, const char* text);
+21 -21
View File
@@ -1774,68 +1774,68 @@ MJAPI int mjs_makeMesh(mjsMesh* mesh, mjtMeshBuiltin builtin, double* params, in
//---------------------------------- Find and get utilities ---------------------------------------- //---------------------------------- Find and get utilities ----------------------------------------
// Get spec from body. // Get spec from body.
MJAPI mjSpec* mjs_getSpec(mjsElement* element); MJAPI mjSpec* mjs_getSpec(const mjsElement* element);
// Get compiler associated with element's origin spec. // Get compiler associated with element's origin spec.
MJAPI mjsCompiler* mjs_getCompiler(mjsElement* element); MJAPI mjsCompiler* mjs_getCompiler(const mjsElement* element);
// Find spec (model asset) by name. // 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. // 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. // 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. // 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. // Get parent body.
MJAPI mjsBody* mjs_getParent(mjsElement* element); MJAPI mjsBody* mjs_getParent(const mjsElement* element);
// Get parent frame. // Get parent frame.
MJAPI mjsFrame* mjs_getFrame(mjsElement* element); MJAPI mjsFrame* mjs_getFrame(const mjsElement* element);
// Find frame by name. // 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. // 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. // 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. // Get global default from model.
MJAPI mjsDefault* mjs_getSpecDefault(mjSpec* s); MJAPI mjsDefault* mjs_getSpecDefault(const mjSpec* s);
// Get element id. // Get element id.
MJAPI int mjs_getId(mjsElement* element); MJAPI int mjs_getId(const mjsElement* element);
// Return body's first child of given type. If recurse is nonzero, also search the body's subtree. // 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. // 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. // 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. // 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. // 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. // Get wrapped element in tendon path.
MJAPI mjsElement* mjs_getWrapTarget(mjsWrap* wrap); MJAPI mjsElement* mjs_getWrapTarget(const mjsWrap* wrap);
// Get wrapped element side site in tendon path if it has one, nullptr otherwise. // Get wrapped element side site in tendon path if it has one, nullptr otherwise.
MJAPI mjsSite* mjs_getWrapSideSite(mjsWrap* wrap); MJAPI mjsSite* mjs_getWrapSideSite(const mjsWrap* wrap);
// Get divisor of mjsWrap wrapping a puller. // 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. // Get coefficient of mjsWrap wrapping a joint.
MJAPI double mjs_getWrapCoef(mjsWrap* wrap); MJAPI double mjs_getWrapCoef(const mjsWrap* wrap);
//---------------------------------- Attribute setters --------------------------------------------- //---------------------------------- Attribute setters ---------------------------------------------
+23 -23
View File
@@ -11120,7 +11120,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
FunctionParameterDecl( FunctionParameterDecl(
name='element', name='element',
type=PointerType( type=PointerType(
inner_type=ValueType(name='mjsElement'), inner_type=ValueType(name='mjsElement', is_const=True),
), ),
), ),
), ),
@@ -11136,7 +11136,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
FunctionParameterDecl( FunctionParameterDecl(
name='element', name='element',
type=PointerType( type=PointerType(
inner_type=ValueType(name='mjsElement'), inner_type=ValueType(name='mjsElement', is_const=True),
), ),
), ),
), ),
@@ -11152,7 +11152,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
FunctionParameterDecl( FunctionParameterDecl(
name='spec', name='spec',
type=PointerType( type=PointerType(
inner_type=ValueType(name='mjSpec'), inner_type=ValueType(name='mjSpec', is_const=True),
), ),
), ),
FunctionParameterDecl( FunctionParameterDecl(
@@ -11174,7 +11174,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
FunctionParameterDecl( FunctionParameterDecl(
name='s', name='s',
type=PointerType( type=PointerType(
inner_type=ValueType(name='mjSpec'), inner_type=ValueType(name='mjSpec', is_const=True),
), ),
), ),
FunctionParameterDecl( FunctionParameterDecl(
@@ -11196,7 +11196,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
FunctionParameterDecl( FunctionParameterDecl(
name='s', name='s',
type=PointerType( type=PointerType(
inner_type=ValueType(name='mjSpec'), inner_type=ValueType(name='mjSpec', is_const=True),
), ),
), ),
FunctionParameterDecl( FunctionParameterDecl(
@@ -11222,7 +11222,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
FunctionParameterDecl( FunctionParameterDecl(
name='body', name='body',
type=PointerType( type=PointerType(
inner_type=ValueType(name='mjsBody'), inner_type=ValueType(name='mjsBody', is_const=True),
), ),
), ),
FunctionParameterDecl( FunctionParameterDecl(
@@ -11244,7 +11244,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
FunctionParameterDecl( FunctionParameterDecl(
name='element', name='element',
type=PointerType( type=PointerType(
inner_type=ValueType(name='mjsElement'), inner_type=ValueType(name='mjsElement', is_const=True),
), ),
), ),
), ),
@@ -11260,7 +11260,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
FunctionParameterDecl( FunctionParameterDecl(
name='element', name='element',
type=PointerType( type=PointerType(
inner_type=ValueType(name='mjsElement'), inner_type=ValueType(name='mjsElement', is_const=True),
), ),
), ),
), ),
@@ -11276,7 +11276,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
FunctionParameterDecl( FunctionParameterDecl(
name='s', name='s',
type=PointerType( type=PointerType(
inner_type=ValueType(name='mjSpec'), inner_type=ValueType(name='mjSpec', is_const=True),
), ),
), ),
FunctionParameterDecl( FunctionParameterDecl(
@@ -11298,7 +11298,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
FunctionParameterDecl( FunctionParameterDecl(
name='element', name='element',
type=PointerType( type=PointerType(
inner_type=ValueType(name='mjsElement'), inner_type=ValueType(name='mjsElement', is_const=True),
), ),
), ),
), ),
@@ -11314,7 +11314,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
FunctionParameterDecl( FunctionParameterDecl(
name='s', name='s',
type=PointerType( type=PointerType(
inner_type=ValueType(name='mjSpec'), inner_type=ValueType(name='mjSpec', is_const=True),
), ),
), ),
FunctionParameterDecl( FunctionParameterDecl(
@@ -11336,7 +11336,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
FunctionParameterDecl( FunctionParameterDecl(
name='s', name='s',
type=PointerType( type=PointerType(
inner_type=ValueType(name='mjSpec'), inner_type=ValueType(name='mjSpec', is_const=True),
), ),
), ),
), ),
@@ -11350,7 +11350,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
FunctionParameterDecl( FunctionParameterDecl(
name='element', name='element',
type=PointerType( type=PointerType(
inner_type=ValueType(name='mjsElement'), inner_type=ValueType(name='mjsElement', is_const=True),
), ),
), ),
), ),
@@ -11366,7 +11366,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
FunctionParameterDecl( FunctionParameterDecl(
name='body', name='body',
type=PointerType( type=PointerType(
inner_type=ValueType(name='mjsBody'), inner_type=ValueType(name='mjsBody', is_const=True),
), ),
), ),
FunctionParameterDecl( FunctionParameterDecl(
@@ -11390,13 +11390,13 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
FunctionParameterDecl( FunctionParameterDecl(
name='body', name='body',
type=PointerType( type=PointerType(
inner_type=ValueType(name='mjsBody'), inner_type=ValueType(name='mjsBody', is_const=True),
), ),
), ),
FunctionParameterDecl( FunctionParameterDecl(
name='child', name='child',
type=PointerType( type=PointerType(
inner_type=ValueType(name='mjsElement'), inner_type=ValueType(name='mjsElement', is_const=True),
), ),
), ),
FunctionParameterDecl( FunctionParameterDecl(
@@ -11416,7 +11416,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
FunctionParameterDecl( FunctionParameterDecl(
name='s', name='s',
type=PointerType( type=PointerType(
inner_type=ValueType(name='mjSpec'), inner_type=ValueType(name='mjSpec', is_const=True),
), ),
), ),
FunctionParameterDecl( FunctionParameterDecl(
@@ -11436,13 +11436,13 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
FunctionParameterDecl( FunctionParameterDecl(
name='s', name='s',
type=PointerType( type=PointerType(
inner_type=ValueType(name='mjSpec'), inner_type=ValueType(name='mjSpec', is_const=True),
), ),
), ),
FunctionParameterDecl( FunctionParameterDecl(
name='element', name='element',
type=PointerType( type=PointerType(
inner_type=ValueType(name='mjsElement'), inner_type=ValueType(name='mjsElement', is_const=True),
), ),
), ),
), ),
@@ -11458,7 +11458,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
FunctionParameterDecl( FunctionParameterDecl(
name='wrap', name='wrap',
type=PointerType( type=PointerType(
inner_type=ValueType(name='mjsWrap'), inner_type=ValueType(name='mjsWrap', is_const=True),
), ),
), ),
), ),
@@ -11474,7 +11474,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
FunctionParameterDecl( FunctionParameterDecl(
name='wrap', name='wrap',
type=PointerType( type=PointerType(
inner_type=ValueType(name='mjsWrap'), inner_type=ValueType(name='mjsWrap', is_const=True),
), ),
), ),
), ),
@@ -11488,7 +11488,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
FunctionParameterDecl( FunctionParameterDecl(
name='wrap', name='wrap',
type=PointerType( type=PointerType(
inner_type=ValueType(name='mjsWrap'), inner_type=ValueType(name='mjsWrap', is_const=True),
), ),
), ),
), ),
@@ -11502,7 +11502,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
FunctionParameterDecl( FunctionParameterDecl(
name='wrap', name='wrap',
type=PointerType( type=PointerType(
inner_type=ValueType(name='mjsWrap'), inner_type=ValueType(name='mjsWrap', is_const=True),
), ),
), ),
), ),
+53 -59
View File
@@ -1302,61 +1302,56 @@ const char* mjs_setToDCMotor(mjsActuator* actuator, double motorconst[2], double
// get spec from body // get spec from body
mjSpec* mjs_getSpec(mjsElement* element) { mjSpec* mjs_getSpec(const mjsElement* element) {
return &(static_cast<mjCBase*>(element)->model->spec); return &(static_cast<const mjCBase*>(element)->model->spec);
} }
mjsCompiler* mjs_getCompiler(mjsElement* element) { mjsCompiler* mjs_getCompiler(const mjsElement* element) {
return static_cast<mjCBase*>(element)->compiler; return static_cast<const mjCBase*>(element)->compiler;
} }
// find spec (model asset) by name // find spec (model asset) by name
mjSpec* mjs_findSpec(mjSpec* s, const char* name) { mjSpec* mjs_findSpec(const mjSpec* s, const char* name) {
mjCModel* model = static_cast<mjCModel*>(s->element); const mjCModel* model = static_cast<mjCModel*>(s->element);
return model->FindSpec(name); return model->FindSpec(name);
} }
// get default // get default
mjsDefault* mjs_getDefault(mjsElement* element) { mjsDefault* mjs_getDefault(const mjsElement* element) {
mjCModel* model = static_cast<mjCBase*>(element)->model; const mjCModel* model = static_cast<const mjCBase*>(element)->model;
std::string classname = static_cast<mjCBase*>(element)->classname; std::string classname = static_cast<const mjCBase*>(element)->classname;
return &(model->def_map[classname]->spec); auto it = model->def_map.find(classname);
return (it != model->def_map.end()) ? &it->second->spec : nullptr;
} }
// Find default with given name in model. // Find default with given name in model.
mjsDefault* mjs_findDefault(mjSpec* s, const char* classname) { mjsDefault* mjs_findDefault(const mjSpec* s, const char* classname) {
mjCModel* modelC = static_cast<mjCModel*>(s->element); const mjCModel* modelC = static_cast<mjCModel*>(s->element);
mjCDef* cdef = modelC->FindDefault(classname); mjCDef* cdef = modelC->FindDefault(classname);
if (!cdef) { return cdef ? &cdef->spec : nullptr;
return nullptr;
}
return &cdef->spec;
} }
// get default[0] from model // get default[0] from model
mjsDefault* mjs_getSpecDefault(mjSpec* s) { mjsDefault* mjs_getSpecDefault(const mjSpec* s) {
mjCModel* modelC = static_cast<mjCModel*>(s->element); const mjCModel* modelC = static_cast<mjCModel*>(s->element);
mjCDef* def = modelC->Default(); mjCDef* def = modelC->Default();
if (!def) { return def ? &def->spec : nullptr;
return nullptr;
}
return &def->spec;
} }
// find body in model by name // 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); mjsElement* body = mjs_findElement(s, mjOBJ_BODY, name);
return body ? &(static_cast<mjCBody*>(body)->spec) : nullptr; 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 // 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); mjCModel* model = static_cast<mjCModel*>(s->element);
if (model->IsCompiled() && type != mjOBJ_FRAME) { if (model->IsCompiled() && type != mjOBJ_FRAME) {
return model->FindObject(type, std::string(name)); // fast lookup 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 // find child of a body by name
mjsBody* mjs_findChild(mjsBody* bodyspec, const char* name) { mjsBody* mjs_findChild(const mjsBody* bodyspec, const char* name) {
mjCBody* body = static_cast<mjCBody*>(bodyspec->element); const mjCBody* body = static_cast<mjCBody*>(bodyspec->element);
mjCBase* child = body->FindObject(mjOBJ_BODY, std::string(name)); mjCBase* child = body->FindObject(mjOBJ_BODY, std::string(name));
return child ? &(static_cast<mjCBody*>(child)->spec) : nullptr; return child ? &(static_cast<mjCBody*>(child)->spec) : nullptr;
} }
@@ -1399,22 +1394,22 @@ mjsBody* mjs_findChild(mjsBody* bodyspec, const char* name) {
// get parent body // get parent body
mjsBody* mjs_getParent(mjsElement* element) { mjsBody* mjs_getParent(const mjsElement* element) {
switch (element->elemtype) { switch (element->elemtype) {
case mjOBJ_BODY: case mjOBJ_BODY:
return &(static_cast<mjCBody*>(element)->GetParent()->spec); return &(static_cast<const mjCBody*>(element)->GetParent()->spec);
case mjOBJ_FRAME: case mjOBJ_FRAME:
return &(static_cast<mjCFrame*>(element)->GetParent()->spec); return &(static_cast<const mjCFrame*>(element)->GetParent()->spec);
case mjOBJ_JOINT: case mjOBJ_JOINT:
return &(static_cast<mjCJoint*>(element)->GetParent()->spec); return &(static_cast<const mjCJoint*>(element)->GetParent()->spec);
case mjOBJ_GEOM: case mjOBJ_GEOM:
return &(static_cast<mjCGeom*>(element)->GetParent()->spec); return &(static_cast<const mjCGeom*>(element)->GetParent()->spec);
case mjOBJ_SITE: case mjOBJ_SITE:
return &(static_cast<mjCSite*>(element)->GetParent()->spec); return &(static_cast<const mjCSite*>(element)->GetParent()->spec);
case mjOBJ_CAMERA: case mjOBJ_CAMERA:
return &(static_cast<mjCCamera*>(element)->GetParent()->spec); return &(static_cast<const mjCCamera*>(element)->GetParent()->spec);
case mjOBJ_LIGHT: case mjOBJ_LIGHT:
return &(static_cast<mjCLight*>(element)->GetParent()->spec); return &(static_cast<const mjCLight*>(element)->GetParent()->spec);
default: default:
return nullptr; return nullptr;
} }
@@ -1423,8 +1418,8 @@ mjsBody* mjs_getParent(mjsElement* element) {
// get parent frame // get parent frame
mjsFrame* mjs_getFrame(mjsElement* element) { mjsFrame* mjs_getFrame(const mjsElement* element) {
mjCBase* base = static_cast<mjCBase*>(element); const mjCBase* base = static_cast<const mjCBase*>(element);
switch (element->elemtype) { switch (element->elemtype) {
case mjOBJ_BODY: case mjOBJ_BODY:
case mjOBJ_FRAME: case mjOBJ_FRAME:
@@ -1442,7 +1437,7 @@ mjsFrame* mjs_getFrame(mjsElement* element) {
// find frame by name // 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); mjsElement* frame = mjs_findElement(s, mjOBJ_FRAME, name);
return frame ? &(static_cast<mjCFrame*>(frame)->spec) : nullptr; return frame ? &(static_cast<mjCFrame*>(frame)->spec) : nullptr;
} }
@@ -1601,11 +1596,11 @@ int mjs_sensorDim(const mjsSensor* sensor) {
// get id // get id
int mjs_getId(mjsElement* element) { int mjs_getId(const mjsElement* element) {
if (!element) { if (!element) {
return -1; 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 // return first child of selected type
mjsElement* mjs_firstChild(mjsBody* body, mjtObj type, int recurse) { mjsElement* mjs_firstChild(const mjsBody* body, mjtObj type, int recurse) {
mjCBody* bodyC = static_cast<mjCBody*>(body->element); const mjCBody* bodyC = static_cast<const mjCBody*>(body->element);
try { try {
return bodyC->NextChild(NULL, type, recurse); return bodyC->NextChild(NULL, type, recurse);
} catch (mjCError& e) { } 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 // return body's next child; return NULL if child is last
mjsElement* mjs_nextChild(mjsBody* body, mjsElement* child, int recurse) { mjsElement* mjs_nextChild(const mjsBody* body, const mjsElement* child, int recurse) {
mjCBody* bodyC = static_cast<mjCBody*>(body->element); const mjCBody* bodyC = static_cast<const mjCBody*>(body->element);
try { try {
return bodyC->NextChild(child, child->elemtype, recurse); return bodyC->NextChild(child, child->elemtype, recurse);
} catch(mjCError& e) { } catch(mjCError& e) {
@@ -1645,23 +1640,23 @@ mjsElement* mjs_nextChild(mjsBody* body, mjsElement* child, int recurse) {
// return spec's first element of selected type // return spec's first element of selected type
mjsElement* mjs_firstElement(mjSpec* s, mjtObj type) { mjsElement* mjs_firstElement(const mjSpec* s, mjtObj type) {
mjCModel* modelC = static_cast<mjCModel*>(s->element); const mjCModel* modelC = static_cast<mjCModel*>(s->element);
return modelC->NextObject(NULL, type); return modelC->NextObject(NULL, type);
} }
// return spec's next element; return NULL if element is last // return spec's next element; return NULL if element is last
mjsElement* mjs_nextElement(mjSpec* s, mjsElement* element) { mjsElement* mjs_nextElement(const mjSpec* s, const mjsElement* element) {
mjCModel* modelC = static_cast<mjCModel*>(s->element); const mjCModel* modelC = static_cast<mjCModel*>(s->element);
return modelC->NextObject(element); return modelC->NextObject(element);
} }
mjsElement* mjs_getWrapTarget(mjsWrap* wrap) { mjsElement* mjs_getWrapTarget(const mjsWrap* wrap) {
mjCWrap* cwrap = static_cast<mjCWrap*>(wrap->element); const mjCWrap* cwrap = static_cast<const mjCWrap*>(wrap->element);
mjtObj type = mjOBJ_UNKNOWN; mjtObj type = mjOBJ_UNKNOWN;
switch (cwrap->Type()) { switch (cwrap->Type()) {
case mjWRAP_SPHERE: case mjWRAP_SPHERE:
@@ -1680,15 +1675,14 @@ mjsElement* mjs_getWrapTarget(mjsWrap* wrap) {
default: default:
return nullptr; return nullptr;
} }
mjSpec* spec = mjs_getSpec(wrap->element); const mjSpec* spec = mjs_getSpec(wrap->element);
mjsElement* target = mjs_findElement(spec, type, cwrap->name.c_str()); return mjs_findElement(spec, type, cwrap->name.c_str());
return target;
} }
mjsSite* mjs_getWrapSideSite(mjsWrap* wrap) { mjsSite* mjs_getWrapSideSite(const mjsWrap* wrap) {
mjCWrap* cwrap = static_cast<mjCWrap*>(wrap->element); const mjCWrap* cwrap = static_cast<const mjCWrap*>(wrap->element);
// only sphere and cylinder (geoms) have side sites // only sphere and cylinder (geoms) have side sites
if ((cwrap->Type() != mjWRAP_SPHERE && if ((cwrap->Type() != mjWRAP_SPHERE &&
cwrap->Type() != mjWRAP_CYLINDER) || cwrap->Type() != mjWRAP_CYLINDER) ||
@@ -1696,7 +1690,7 @@ mjsSite* mjs_getWrapSideSite(mjsWrap* wrap) {
return nullptr; 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()); mjsElement* site = mjs_findElement(spec, mjOBJ_SITE, cwrap->sidesite.c_str());
if (site == nullptr) { if (site == nullptr) {
mju_warning("Could not find side site %s for wrap %s in spec", 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) { double mjs_getWrapDivisor(const mjsWrap* wrap) {
mjCWrap* cwrap = static_cast<mjCWrap*>(wrap->element); const mjCWrap* cwrap = static_cast<const mjCWrap*>(wrap->element);
if (cwrap->Type() != mjWRAP_PULLEY) { if (cwrap->Type() != mjWRAP_PULLEY) {
mju_warning("Querying divisor attribute of non-pulley wrap: %s", cwrap->name.c_str()); mju_warning("Querying divisor attribute of non-pulley wrap: %s", cwrap->name.c_str());
return 1.0; return 1.0;
@@ -1719,8 +1713,8 @@ double mjs_getWrapDivisor(mjsWrap* wrap) {
double mjs_getWrapCoef(mjsWrap* wrap) { double mjs_getWrapCoef(const mjsWrap* wrap) {
mjCWrap* cwrap = static_cast<mjCWrap*>(wrap->element); const mjCWrap* cwrap = static_cast<const mjCWrap*>(wrap->element);
if (cwrap->Type() != mjWRAP_JOINT) { if (cwrap->Type() != mjWRAP_JOINT) {
mju_warning("Querying coef attribute of non-joint wrap: %s", cwrap->name.c_str()); mju_warning("Querying coef attribute of non-joint wrap: %s", cwrap->name.c_str());
return 1.0; return 1.0;
+20 -20
View File
@@ -222,68 +222,68 @@ MJAPI int mjs_makeMesh(mjsMesh* mesh, mjtMeshBuiltin builtin, double* params, in
//---------------------------------- Find/get utilities -------------------------------------------- //---------------------------------- Find/get utilities --------------------------------------------
// Get spec from body. // Get spec from body.
MJAPI mjSpec* mjs_getSpec(mjsElement* element); MJAPI mjSpec* mjs_getSpec(const mjsElement* element);
// Find spec (model asset) by name. // 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. // 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. // 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. // 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. // Get parent body.
MJAPI mjsBody* mjs_getParent(mjsElement* element); MJAPI mjsBody* mjs_getParent(const mjsElement* element);
// Get parent frame. // Get parent frame.
MJAPI mjsFrame* mjs_getFrame(mjsElement* element); MJAPI mjsFrame* mjs_getFrame(const mjsElement* element);
// Find frame by name. // 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. // 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. // 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. // Get global default from model.
MJAPI mjsDefault* mjs_getSpecDefault(mjSpec* s); MJAPI mjsDefault* mjs_getSpecDefault(const mjSpec* s);
// Get element id. // Get element id.
MJAPI int mjs_getId(mjsElement* element); MJAPI int mjs_getId(const mjsElement* element);
//---------------------------------- Tree traversal ------------------------------------------------ //---------------------------------- Tree traversal ------------------------------------------------
// Return body's first child of given type. If recurse is nonzero, also search the body's subtree. // 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. // 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. // 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. // 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. // 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. // 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. // 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. // 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. // 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. // Safely cast an element as mjsBody, or return NULL if the element is not an mjsBody.
MJAPI mjsBody* mjs_asBody(mjsElement* element); MJAPI mjsBody* mjs_asBody(mjsElement* element);
+7 -7
View File
@@ -1408,7 +1408,7 @@ mjCBase* mjCModel::GetObject(mjtObj type, int id) {
template <class T> 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 (!child) {
if (list.empty()) { if (list.empty()) {
return nullptr; return nullptr;
@@ -1428,7 +1428,7 @@ static mjsElement* GetNext(std::vector<T*>& list, mjsElement* child) {
// next object of specified type // 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 (type == mjOBJ_UNKNOWN) {
if (!object) { if (!object) {
throw mjCError(nullptr, "type must be specified if no element is given"); 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 // 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++) { for (int i=0; i < (int)defaults_.size(); i++) {
if (defaults_[i]->name == name) { if (defaults_[i]->name == name) {
return defaults_[i]; return defaults_[i];
@@ -1697,13 +1697,13 @@ mjSpec* mjCModel::FindSpec(std::string name) const {
// find spec by mjsCompiler pointer // find spec by mjsCompiler pointer
mjSpec* mjCModel::FindSpec(const mjsCompiler* compiler_) { mjSpec* mjCModel::FindSpec(const mjsCompiler* compiler_) const {
if (compiler_ == &spec.compiler) { if (compiler_ == &spec.compiler) {
return &spec; return &const_cast<mjCModel*>(this)->spec;
} }
if (compiler2spec_.find(compiler_) != compiler2spec_.end()) { if (auto it = compiler2spec_.find(compiler_); it != compiler2spec_.end()) {
return compiler2spec_[compiler_]; return it->second;
} }
for (auto s : specs_) { for (auto s : specs_) {
+3 -3
View File
@@ -242,19 +242,19 @@ class mjCModel : public mjCModel_, private mjSpec {
// API for access to model elements (outside tree) // API for access to model elements (outside tree)
int NumObjects(mjtObj type); // number of objects in specified list int NumObjects(mjtObj type); // number of objects in specified list
mjCBase* GetObject(mjtObj type, int id); // pointer to specified object 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 // API for access to other variables
bool IsCompiled() const; // is model already compiled bool IsCompiled() const; // is model already compiled
const mjCError& GetError() const; // get reference of error object const mjCError& GetError() const; // get reference of error object
void SetError(const mjCError& error) { errInfo = error; } // set value of error object void SetError(const mjCError& error) { errInfo = error; } // set value of error object
mjCBody* GetWorld(); // pointer to world body 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 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* 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 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(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 void ActivatePlugin(const mjpPlugin* plugin, int slot); // activate plugin
// find asset given name checking both name and filename // find asset given name checking both name and filename
+4 -4
View File
@@ -2251,7 +2251,7 @@ mjCBase* mjCBody::GetObject(mjtObj type, int i) {
// find object by name in given list // find object by name in given list
template <class T> 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++) { for (unsigned int i=0; i < list.size(); i++) {
if (list[i]->name == name) { if (list[i]->name == name) {
return list[i]; return list[i];
@@ -2264,12 +2264,12 @@ static T* findobject(std::string name, std::vector<T*>& list) {
// recursive find by name // 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; mjCBase* res = 0;
// check self: just in case // check self: just in case
if (name == _name) { if (name == _name) {
return this; return const_cast<mjCBody*>(this);
} }
// search elements of this body // search elements of this body
@@ -2406,7 +2406,7 @@ static mjsElement* GetNextBody(const mjCBody* body, const mjsElement* child,
// get next child of given type // 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 (type == mjOBJ_UNKNOWN) {
if (!child) { if (!child) {
throw mjCError(this, "child type must be specified if no child element is given"); throw mjCError(this, "child type must be specified if no child element is given");
+2 -2
View File
@@ -531,7 +531,7 @@ class mjCBody : public mjCBody_, private mjsBody {
// API for accessing objects // API for accessing objects
int NumObjects(mjtObj type); int NumObjects(mjtObj type);
mjCBase* GetObject(mjtObj type, int id); 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 // Propagate suffix and prefix to the whole tree
void NameSpace(const mjCModel* m); 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 // 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 // the next child after the input `child` otherwise
mjsElement* NextChild(const mjsElement* child, mjtObj type = mjOBJ_UNKNOWN, mjsElement* NextChild(const mjsElement* child, mjtObj type = mjOBJ_UNKNOWN,
bool recursive = false); bool recursive = false) const;
// reset keyframe references for allowing self-attach // reset keyframe references for allowing self-attach
void ForgetKeyframes() const; void ForgetKeyframes() const;
+21 -21
View File
@@ -9687,7 +9687,7 @@ void mjs_deleteUserValue_wrapper(MjsElement& element, const String& key) {
mjs_deleteUserValue(element.get(), key.as<const std::string>().data()); mjs_deleteUserValue(element.get(), key.as<const std::string>().data());
} }
std::optional<MjsBody> mjs_findBody_wrapper(MjSpec& s, const String& name) { std::optional<MjsBody> mjs_findBody_wrapper(const MjSpec& s, const String& name) {
CHECK_VAL(name); CHECK_VAL(name);
mjsBody* result = mjs_findBody(s.get(), name.as<const std::string>().data()); mjsBody* result = mjs_findBody(s.get(), name.as<const std::string>().data());
if (result == nullptr) { if (result == nullptr) {
@@ -9696,7 +9696,7 @@ std::optional<MjsBody> mjs_findBody_wrapper(MjSpec& s, const String& name) {
return MjsBody(result); return MjsBody(result);
} }
std::optional<MjsBody> mjs_findChild_wrapper(MjsBody& body, const String& name) { std::optional<MjsBody> mjs_findChild_wrapper(const MjsBody& body, const String& name) {
CHECK_VAL(name); CHECK_VAL(name);
mjsBody* result = mjs_findChild(body.get(), name.as<const std::string>().data()); mjsBody* result = mjs_findChild(body.get(), name.as<const std::string>().data());
if (result == nullptr) { if (result == nullptr) {
@@ -9705,7 +9705,7 @@ std::optional<MjsBody> mjs_findChild_wrapper(MjsBody& body, const String& name)
return MjsBody(result); return MjsBody(result);
} }
std::optional<MjsDefault> mjs_findDefault_wrapper(MjSpec& s, const String& classname) { std::optional<MjsDefault> mjs_findDefault_wrapper(const MjSpec& s, const String& classname) {
CHECK_VAL(classname); CHECK_VAL(classname);
mjsDefault* result = mjs_findDefault(s.get(), classname.as<const std::string>().data()); mjsDefault* result = mjs_findDefault(s.get(), classname.as<const std::string>().data());
if (result == nullptr) { if (result == nullptr) {
@@ -9714,7 +9714,7 @@ std::optional<MjsDefault> mjs_findDefault_wrapper(MjSpec& s, const String& class
return MjsDefault(result); return MjsDefault(result);
} }
std::optional<MjsElement> mjs_findElement_wrapper(MjSpec& s, mjtObj type, const String& name) { std::optional<MjsElement> mjs_findElement_wrapper(const MjSpec& s, mjtObj type, const String& name) {
CHECK_VAL(name); CHECK_VAL(name);
mjsElement* result = mjs_findElement(s.get(), type, name.as<const std::string>().data()); mjsElement* result = mjs_findElement(s.get(), type, name.as<const std::string>().data());
if (result == nullptr) { if (result == nullptr) {
@@ -9723,7 +9723,7 @@ std::optional<MjsElement> mjs_findElement_wrapper(MjSpec& s, mjtObj type, const
return MjsElement(result); return MjsElement(result);
} }
std::optional<MjsFrame> mjs_findFrame_wrapper(MjSpec& s, const String& name) { std::optional<MjsFrame> mjs_findFrame_wrapper(const MjSpec& s, const String& name) {
CHECK_VAL(name); CHECK_VAL(name);
mjsFrame* result = mjs_findFrame(s.get(), name.as<const std::string>().data()); mjsFrame* result = mjs_findFrame(s.get(), name.as<const std::string>().data());
if (result == nullptr) { if (result == nullptr) {
@@ -9732,7 +9732,7 @@ std::optional<MjsFrame> mjs_findFrame_wrapper(MjSpec& s, const String& name) {
return MjsFrame(result); return MjsFrame(result);
} }
std::optional<MjSpec> mjs_findSpec_wrapper(MjSpec& spec, const String& name) { std::optional<MjSpec> mjs_findSpec_wrapper(const MjSpec& spec, const String& name) {
CHECK_VAL(name); CHECK_VAL(name);
mjSpec* result = mjs_findSpec(spec.get(), name.as<const std::string>().data()); mjSpec* result = mjs_findSpec(spec.get(), name.as<const std::string>().data());
if (result == nullptr) { if (result == nullptr) {
@@ -9741,7 +9741,7 @@ std::optional<MjSpec> mjs_findSpec_wrapper(MjSpec& spec, const String& name) {
return MjSpec(result); return MjSpec(result);
} }
std::optional<MjsElement> mjs_firstChild_wrapper(MjsBody& body, mjtObj type, int recurse) { std::optional<MjsElement> mjs_firstChild_wrapper(const MjsBody& body, mjtObj type, int recurse) {
mjsElement* result = mjs_firstChild(body.get(), type, recurse); mjsElement* result = mjs_firstChild(body.get(), type, recurse);
if (result == nullptr) { if (result == nullptr) {
return std::nullopt; return std::nullopt;
@@ -9749,7 +9749,7 @@ std::optional<MjsElement> mjs_firstChild_wrapper(MjsBody& body, mjtObj type, int
return MjsElement(result); return MjsElement(result);
} }
std::optional<MjsElement> mjs_firstElement_wrapper(MjSpec& s, mjtObj type) { std::optional<MjsElement> mjs_firstElement_wrapper(const MjSpec& s, mjtObj type) {
mjsElement* result = mjs_firstElement(s.get(), type); mjsElement* result = mjs_firstElement(s.get(), type);
if (result == nullptr) { if (result == nullptr) {
return std::nullopt; return std::nullopt;
@@ -9757,7 +9757,7 @@ std::optional<MjsElement> mjs_firstElement_wrapper(MjSpec& s, mjtObj type) {
return MjsElement(result); return MjsElement(result);
} }
std::optional<MjsCompiler> mjs_getCompiler_wrapper(MjsElement& element) { std::optional<MjsCompiler> mjs_getCompiler_wrapper(const MjsElement& element) {
mjsCompiler* result = mjs_getCompiler(element.get()); mjsCompiler* result = mjs_getCompiler(element.get());
if (result == nullptr) { if (result == nullptr) {
return std::nullopt; return std::nullopt;
@@ -9765,7 +9765,7 @@ std::optional<MjsCompiler> mjs_getCompiler_wrapper(MjsElement& element) {
return MjsCompiler(result); return MjsCompiler(result);
} }
std::optional<MjsDefault> mjs_getDefault_wrapper(MjsElement& element) { std::optional<MjsDefault> mjs_getDefault_wrapper(const MjsElement& element) {
mjsDefault* result = mjs_getDefault(element.get()); mjsDefault* result = mjs_getDefault(element.get());
if (result == nullptr) { if (result == nullptr) {
return std::nullopt; return std::nullopt;
@@ -9777,7 +9777,7 @@ std::string mjs_getError_wrapper(MjSpec& s) {
return std::string(mjs_getError(s.get())); return std::string(mjs_getError(s.get()));
} }
std::optional<MjsFrame> mjs_getFrame_wrapper(MjsElement& element) { std::optional<MjsFrame> mjs_getFrame_wrapper(const MjsElement& element) {
mjsFrame* result = mjs_getFrame(element.get()); mjsFrame* result = mjs_getFrame(element.get());
if (result == nullptr) { if (result == nullptr) {
return std::nullopt; return std::nullopt;
@@ -9785,7 +9785,7 @@ std::optional<MjsFrame> mjs_getFrame_wrapper(MjsElement& element) {
return MjsFrame(result); return MjsFrame(result);
} }
int mjs_getId_wrapper(MjsElement& element) { int mjs_getId_wrapper(const MjsElement& element) {
return mjs_getId(element.get()); return mjs_getId(element.get());
} }
@@ -9793,7 +9793,7 @@ std::string mjs_getName_wrapper(MjsElement& element) {
return *mjs_getName(element.get()); return *mjs_getName(element.get());
} }
std::optional<MjsBody> mjs_getParent_wrapper(MjsElement& element) { std::optional<MjsBody> mjs_getParent_wrapper(const MjsElement& element) {
mjsBody* result = mjs_getParent(element.get()); mjsBody* result = mjs_getParent(element.get());
if (result == nullptr) { if (result == nullptr) {
return std::nullopt; return std::nullopt;
@@ -9801,7 +9801,7 @@ std::optional<MjsBody> mjs_getParent_wrapper(MjsElement& element) {
return MjsBody(result); return MjsBody(result);
} }
std::optional<MjSpec> mjs_getSpec_wrapper(MjsElement& element) { std::optional<MjSpec> mjs_getSpec_wrapper(const MjsElement& element) {
mjSpec* result = mjs_getSpec(element.get()); mjSpec* result = mjs_getSpec(element.get());
if (result == nullptr) { if (result == nullptr) {
return std::nullopt; return std::nullopt;
@@ -9809,7 +9809,7 @@ std::optional<MjSpec> mjs_getSpec_wrapper(MjsElement& element) {
return MjSpec(result); return MjSpec(result);
} }
std::optional<MjsDefault> mjs_getSpecDefault_wrapper(MjSpec& s) { std::optional<MjsDefault> mjs_getSpecDefault_wrapper(const MjSpec& s) {
mjsDefault* result = mjs_getSpecDefault(s.get()); mjsDefault* result = mjs_getSpecDefault(s.get());
if (result == nullptr) { if (result == nullptr) {
return std::nullopt; return std::nullopt;
@@ -9825,11 +9825,11 @@ std::optional<MjsWrap> mjs_getWrap_wrapper(const MjsTendon& tendonspec, int i) {
return MjsWrap(result); return MjsWrap(result);
} }
double mjs_getWrapCoef_wrapper(MjsWrap& wrap) { double mjs_getWrapCoef_wrapper(const MjsWrap& wrap) {
return mjs_getWrapCoef(wrap.get()); return mjs_getWrapCoef(wrap.get());
} }
double mjs_getWrapDivisor_wrapper(MjsWrap& wrap) { double mjs_getWrapDivisor_wrapper(const MjsWrap& wrap) {
return mjs_getWrapDivisor(wrap.get()); return mjs_getWrapDivisor(wrap.get());
} }
@@ -9837,7 +9837,7 @@ int mjs_getWrapNum_wrapper(const MjsTendon& tendonspec) {
return mjs_getWrapNum(tendonspec.get()); return mjs_getWrapNum(tendonspec.get());
} }
std::optional<MjsSite> mjs_getWrapSideSite_wrapper(MjsWrap& wrap) { std::optional<MjsSite> mjs_getWrapSideSite_wrapper(const MjsWrap& wrap) {
mjsSite* result = mjs_getWrapSideSite(wrap.get()); mjsSite* result = mjs_getWrapSideSite(wrap.get());
if (result == nullptr) { if (result == nullptr) {
return std::nullopt; return std::nullopt;
@@ -9845,7 +9845,7 @@ std::optional<MjsSite> mjs_getWrapSideSite_wrapper(MjsWrap& wrap) {
return MjsSite(result); return MjsSite(result);
} }
std::optional<MjsElement> mjs_getWrapTarget_wrapper(MjsWrap& wrap) { std::optional<MjsElement> mjs_getWrapTarget_wrapper(const MjsWrap& wrap) {
mjsElement* result = mjs_getWrapTarget(wrap.get()); mjsElement* result = mjs_getWrapTarget(wrap.get());
if (result == nullptr) { if (result == nullptr) {
return std::nullopt; return std::nullopt;
@@ -9862,7 +9862,7 @@ int mjs_makeMesh_wrapper(MjsMesh& mesh, mjtMeshBuiltin builtin, const val& param
return mjs_makeMesh(mesh.get(), builtin, params_.data(), nparams); return mjs_makeMesh(mesh.get(), builtin, params_.data(), nparams);
} }
std::optional<MjsElement> mjs_nextChild_wrapper(MjsBody& body, MjsElement& child, int recurse) { std::optional<MjsElement> mjs_nextChild_wrapper(const MjsBody& body, const MjsElement& child, int recurse) {
mjsElement* result = mjs_nextChild(body.get(), child.get(), recurse); mjsElement* result = mjs_nextChild(body.get(), child.get(), recurse);
if (result == nullptr) { if (result == nullptr) {
return std::nullopt; return std::nullopt;
@@ -9870,7 +9870,7 @@ std::optional<MjsElement> mjs_nextChild_wrapper(MjsBody& body, MjsElement& child
return MjsElement(result); return MjsElement(result);
} }
std::optional<MjsElement> mjs_nextElement_wrapper(MjSpec& s, MjsElement& element) { std::optional<MjsElement> mjs_nextElement_wrapper(const MjSpec& s, const MjsElement& element) {
mjsElement* result = mjs_nextElement(s.get(), element.get()); mjsElement* result = mjs_nextElement(s.get(), element.get());
if (result == nullptr) { if (result == nullptr) {
return std::nullopt; return std::nullopt;