Rename variables to avoid shadowing in xml_native_reader.cc

PiperOrigin-RevId: 780135233
Change-Id: I509ac6a0807e102ad8749f81562ad45bf4c04335
This commit is contained in:
Yuval Tassa
2025-07-07 09:08:54 -07:00
committed by Copybara-Service
parent 783e6499d8
commit e01c4b454a
2 changed files with 53 additions and 53 deletions
+50 -50
View File
@@ -985,25 +985,25 @@ void mjXReader::Parse(XMLElement* root, const mjVFS* vfs) {
// compiler section parser
void mjXReader::Compiler(XMLElement* section, mjSpec* spec) {
void mjXReader::Compiler(XMLElement* section, mjSpec* s) {
string text;
int n;
// top-level attributes
if (MapValue(section, "autolimits", &n, bool_map, 2)) {
spec->compiler.autolimits = (n == 1);
s->compiler.autolimits = (n == 1);
}
ReadAttr(section, "boundmass", 1, &spec->compiler.boundmass, text);
ReadAttr(section, "boundinertia", 1, &spec->compiler.boundinertia, text);
ReadAttr(section, "settotalmass", 1, &spec->compiler.settotalmass, text);
ReadAttr(section, "boundmass", 1, &s->compiler.boundmass, text);
ReadAttr(section, "boundinertia", 1, &s->compiler.boundinertia, text);
ReadAttr(section, "settotalmass", 1, &s->compiler.settotalmass, text);
if (MapValue(section, "balanceinertia", &n, bool_map, 2)) {
spec->compiler.balanceinertia = (n == 1);
s->compiler.balanceinertia = (n == 1);
}
if (MapValue(section, "strippath", &n, bool_map, 2)) {
spec->strippath = (n == 1);
s->strippath = (n == 1);
}
if (MapValue(section, "fitaabb", &n, bool_map, 2)) {
spec->compiler.fitaabb = (n == 1);
s->compiler.fitaabb = (n == 1);
}
if (MapValue(section, "coordinate", &n, coordinate_map, 2)) {
if (n == 1) {
@@ -1012,48 +1012,48 @@ void mjXReader::Compiler(XMLElement* section, mjSpec* spec) {
}
}
if (MapValue(section, "angle", &n, angle_map, 2)) {
spec->compiler.degree = (n == 1);
s->compiler.degree = (n == 1);
}
if (ReadAttrTxt(section, "eulerseq", text)) {
if (text.size() != 3) {
throw mjXError(section, "euler format must have length 3");
}
memcpy(spec->compiler.eulerseq, text.c_str(), 3);
memcpy(s->compiler.eulerseq, text.c_str(), 3);
}
if (ReadAttrTxt(section, "assetdir", text)) {
mjs_setString(spec->meshdir, text.c_str());
mjs_setString(spec->texturedir, text.c_str());
mjs_setString(s->meshdir, text.c_str());
mjs_setString(s->texturedir, text.c_str());
}
// meshdir and texturedir take precedence over assetdir
string meshdir, texturedir;
if (ReadAttrTxt(section, "meshdir", meshdir)) {
mjs_setString(spec->meshdir, meshdir.c_str());
mjs_setString(s->meshdir, meshdir.c_str());
};
if (ReadAttrTxt(section, "texturedir", texturedir)) {
mjs_setString(spec->texturedir, texturedir.c_str());
mjs_setString(s->texturedir, texturedir.c_str());
}
if (MapValue(section, "discardvisual", &n, bool_map, 2)) {
spec->compiler.discardvisual = (n == 1);
s->compiler.discardvisual = (n == 1);
}
if (MapValue(section, "usethread", &n, bool_map, 2)) {
spec->compiler.usethread = (n == 1);
s->compiler.usethread = (n == 1);
}
if (MapValue(section, "fusestatic", &n, bool_map, 2)) {
spec->compiler.fusestatic = (n == 1);
s->compiler.fusestatic = (n == 1);
}
MapValue(section, "inertiafromgeom", &spec->compiler.inertiafromgeom, TFAuto_map, 3);
ReadAttr(section, "inertiagrouprange", 2, spec->compiler.inertiagrouprange, text);
MapValue(section, "inertiafromgeom", &s->compiler.inertiafromgeom, TFAuto_map, 3);
ReadAttr(section, "inertiagrouprange", 2, s->compiler.inertiagrouprange, text);
if (MapValue(section, "alignfree", &n, bool_map, 2)) {
spec->compiler.alignfree = (n == 1);
s->compiler.alignfree = (n == 1);
}
if (MapValue(section, "saveinertial", &n, bool_map, 2)) {
spec->compiler.saveinertial = (n == 1);
s->compiler.saveinertial = (n == 1);
}
// lengthrange subelement
XMLElement* elem = FindSubElem(section, "lengthrange");
if (elem) {
mjLROpt* opt = &(spec->compiler.LRopt);
mjLROpt* opt = &(s->compiler.LRopt);
// flags
MapValue(elem, "mode", &opt->mode, lrmode_map, lrmode_sz);
@@ -1173,7 +1173,7 @@ void mjXReader::Option(XMLElement* section, mjOption* opt) {
// size section parser
void mjXReader::Size(XMLElement* section, mjSpec* spec) {
void mjXReader::Size(XMLElement* section, mjSpec* s) {
// read memory bytes
{
constexpr char err_msg[] =
@@ -1262,69 +1262,69 @@ void mjXReader::Size(XMLElement* section, mjSpec* spec) {
if (*memory / sizeof(mjtNum) > std::numeric_limits<std::size_t>::max()) {
throw mjXError(section, "%s", err_msg);
}
spec->memory = *memory;
s->memory = *memory;
}
}
// read sizes
ReadAttrInt(section, "nuserdata", &spec->nuserdata);
ReadAttrInt(section, "nkey", &spec->nkey);
ReadAttrInt(section, "nuserdata", &s->nuserdata);
ReadAttrInt(section, "nkey", &s->nkey);
ReadAttrInt(section, "nconmax", &spec->nconmax);
if (spec->nconmax < -1) throw mjXError(section, "nconmax must be >= -1");
ReadAttrInt(section, "nconmax", &s->nconmax);
if (s->nconmax < -1) throw mjXError(section, "nconmax must be >= -1");
{
int nstack = -1;
const bool has_nstack = ReadAttrInt(section, "nstack", &nstack);
if (has_nstack) {
if (spec->nstack < -1) {
if (s->nstack < -1) {
throw mjXError(section, "nstack must be >= -1");
}
if (spec->memory != -1 && nstack != -1) {
if (s->memory != -1 && nstack != -1) {
throw mjXError(section,
"either 'memory' and 'nstack' attribute can be specified, not both");
}
spec->nstack = nstack;
s->nstack = nstack;
}
}
{
int njmax = -1;
const bool has_njmax = ReadAttrInt(section, "njmax", &njmax);
if (has_njmax) {
if (spec->njmax < -1) {
if (s->njmax < -1) {
throw mjXError(section, "njmax must be >= -1");
}
if (spec->memory != -1 && njmax != -1) {
if (s->memory != -1 && njmax != -1) {
throw mjXError(section,
"either 'memory' and 'njmax' attribute can be specified, not both");
}
spec->njmax = njmax;
s->njmax = njmax;
}
}
ReadAttrInt(section, "nuser_body", &spec->nuser_body);
if (spec->nuser_body < -1) throw mjXError(section, "nuser_body must be >= -1");
ReadAttrInt(section, "nuser_body", &s->nuser_body);
if (s->nuser_body < -1) throw mjXError(section, "nuser_body must be >= -1");
ReadAttrInt(section, "nuser_jnt", &spec->nuser_jnt);
if (spec->nuser_jnt < -1) throw mjXError(section, "nuser_jnt must be >= -1");
ReadAttrInt(section, "nuser_jnt", &s->nuser_jnt);
if (s->nuser_jnt < -1) throw mjXError(section, "nuser_jnt must be >= -1");
ReadAttrInt(section, "nuser_geom", &spec->nuser_geom);
if (spec->nuser_geom < -1) throw mjXError(section, "nuser_geom must be >= -1");
ReadAttrInt(section, "nuser_geom", &s->nuser_geom);
if (s->nuser_geom < -1) throw mjXError(section, "nuser_geom must be >= -1");
ReadAttrInt(section, "nuser_site", &spec->nuser_site);
if (spec->nuser_site < -1) throw mjXError(section, "nuser_site must be >= -1");
ReadAttrInt(section, "nuser_site", &s->nuser_site);
if (s->nuser_site < -1) throw mjXError(section, "nuser_site must be >= -1");
ReadAttrInt(section, "nuser_cam", &spec->nuser_cam);
if (spec->nuser_cam < -1) throw mjXError(section, "nuser_cam must be >= -1");
ReadAttrInt(section, "nuser_cam", &s->nuser_cam);
if (s->nuser_cam < -1) throw mjXError(section, "nuser_cam must be >= -1");
ReadAttrInt(section, "nuser_tendon", &spec->nuser_tendon);
if (spec->nuser_tendon < -1) throw mjXError(section, "nuser_tendon must be >= -1");
ReadAttrInt(section, "nuser_tendon", &s->nuser_tendon);
if (s->nuser_tendon < -1) throw mjXError(section, "nuser_tendon must be >= -1");
ReadAttrInt(section, "nuser_actuator", &spec->nuser_actuator);
if (spec->nuser_actuator < -1) throw mjXError(section, "nuser_actuator must be >= -1");
ReadAttrInt(section, "nuser_actuator", &s->nuser_actuator);
if (s->nuser_actuator < -1) throw mjXError(section, "nuser_actuator must be >= -1");
ReadAttrInt(section, "nuser_sensor", &spec->nuser_sensor);
if (spec->nuser_sensor < -1) throw mjXError(section, "nuser_sensor must be >= -1");
ReadAttrInt(section, "nuser_sensor", &s->nuser_sensor);
if (s->nuser_sensor < -1) throw mjXError(section, "nuser_sensor must be >= -1");
}
+3 -3
View File
@@ -42,9 +42,9 @@ class mjXReader : public mjXBase {
void SetTextureDir(const std::string& texturedir);
// XML sections embedded in all formats
static void Compiler(tinyxml2::XMLElement* section, mjSpec* spec); // compiler section
static void Option(tinyxml2::XMLElement* section, mjOption* opt); // option section
static void Size(tinyxml2::XMLElement* section, mjSpec* spec); // size section
static void Compiler(tinyxml2::XMLElement* section, mjSpec* s); // compiler section
static void Option(tinyxml2::XMLElement* section, mjOption* opt); // option section
static void Size(tinyxml2::XMLElement* section, mjSpec* s); // size section
private:
// XML section specific to MJCF