Add copy constructors and assignments to user_objects.

All of the constructors and assignments operators are declared by this CL, but only those that are currently used are implemented here.

PiperOrigin-RevId: 615369559
Change-Id: I9f8cc4a7cd2070362baba04f2af4c5567a696596
This commit is contained in:
Alessio Quaglino
2024-03-13 04:47:51 -07:00
committed by Copybara-Service
parent e42f9c6490
commit 693e3c66c8
3 changed files with 256 additions and 44 deletions
+106 -20
View File
@@ -506,6 +506,8 @@ mjCDef::mjCDef(const mjCDef& other) {
// compiler
void mjCDef::Compile(const mjCModel* model) {
CopyFromSpec();
// enforce length of all default userdata arrays
joint.userdata_.resize(model->nuser_jnt);
geom.userdata_.resize(model->nuser_geom);
@@ -1425,7 +1427,6 @@ mjCJoint::mjCJoint(mjCModel* _model, mjCDef* _def) {
// reset to default if given
if (_def) {
_def->joint.CopyFromSpec();
*this = _def->joint;
}
@@ -1433,7 +1434,7 @@ mjCJoint::mjCJoint(mjCModel* _model, mjCDef* _def) {
model = _model;
def = (_def ? _def : (_model ? _model->defaults[0] : 0));
// point to local (needs to be after defaults)
// point to local
PointToLocal();
// in case this joint is not compiled
@@ -1637,7 +1638,6 @@ mjCGeom::mjCGeom(mjCModel* _model, mjCDef* _def) {
// reset to default if given
if (_def) {
_def->geom.CopyFromSpec();
*this = _def->geom;
}
@@ -1645,7 +1645,7 @@ mjCGeom::mjCGeom(mjCModel* _model, mjCDef* _def) {
model = _model;
def = (_def ? _def : (_model ? _model->defaults[0] : 0));
// point to local (needs to be after defaults)
// point to local
PointToLocal();
// in case this geom is not compiled
@@ -2256,11 +2256,10 @@ mjCSite::mjCSite(mjCModel* _model, mjCDef* _def) {
// reset to default if given
if (_def) {
_def->site.CopyFromSpec();
*this = _def->site;
}
// point to local (needs to be after defaults)
// point to local
PointToLocal();
// in case this site is not compiled
@@ -2416,7 +2415,6 @@ mjCCamera::mjCCamera(mjCModel* _model, mjCDef* _def) {
// reset to default if given
if (_def) {
_def->camera.CopyFromSpec();
*this = _def->camera;
}
@@ -2424,7 +2422,7 @@ mjCCamera::mjCCamera(mjCModel* _model, mjCDef* _def) {
model = _model;
def = (_def ? _def : (_model ? _model->defaults[0] : 0));
// point to local (needs to be after defaults)
// point to local
PointToLocal();
// in case this camera is not compiled
@@ -2571,7 +2569,6 @@ mjCLight::mjCLight(mjCModel* _model, mjCDef* _def) {
// reset to default if given
if (_def) {
_def->light.CopyFromSpec();
*this = _def->light;
}
@@ -2913,7 +2910,7 @@ mjCTexture::mjCTexture(mjCModel* _model) {
// clear internal variables
rgb = 0;
// point to local (needs to be after defaults)
// point to local
PointToLocal();
// in case this camera is not compiled
@@ -3637,7 +3634,6 @@ mjCMaterial::mjCMaterial(mjCModel* _model, mjCDef* _def) {
// reset to default if given
if (_def) {
_def->material.CopyFromSpec();
*this = _def->material;
}
@@ -3645,7 +3641,7 @@ mjCMaterial::mjCMaterial(mjCModel* _model, mjCDef* _def) {
model = _model;
def = (_def ? _def : (_model ? _model->defaults[0] : 0));
// point to local (needs to be after defaults)
// point to local
PointToLocal();
// in case this camera is not compiled
@@ -3654,6 +3650,24 @@ mjCMaterial::mjCMaterial(mjCModel* _model, mjCDef* _def) {
mjCMaterial::mjCMaterial(const mjCMaterial& other) {
*this = other;
}
mjCMaterial& mjCMaterial::operator=(const mjCMaterial& other) {
if (this != &other) {
this->spec = other.spec;
*static_cast<mjCMaterial_*>(this) = static_cast<const mjCMaterial_&>(other);
*static_cast<mjmMaterial*>(this) = static_cast<const mjmMaterial&>(other);
}
PointToLocal();
return *this;
}
void mjCMaterial::PointToLocal() {
spec.element = (mjElement)this;
spec.name = (mjString)&name;
@@ -3696,7 +3710,6 @@ mjCPair::mjCPair(mjCModel* _model, mjCDef* _def) {
// reset to default if given
if (_def) {
_def->pair.CopyFromSpec();
*this = _def->pair;
}
@@ -3704,7 +3717,7 @@ mjCPair::mjCPair(mjCModel* _model, mjCDef* _def) {
model = _model;
def = (_def ? _def : (_model ? _model->defaults[0] : 0));
// point to local (needs to be after defaults)
// point to local
PointToLocal();
// in case this camera is not compiled
@@ -3713,6 +3726,26 @@ mjCPair::mjCPair(mjCModel* _model, mjCDef* _def) {
mjCPair::mjCPair(const mjCPair& other) {
*this = other;
}
mjCPair& mjCPair::operator=(const mjCPair& other) {
if (this != &other) {
this->spec = other.spec;
*static_cast<mjCPair_*>(this) = static_cast<const mjCPair_&>(other);
*static_cast<mjmPair*>(this) = static_cast<const mjmPair&>(other);
this->geom1 = other.geom1;
this->geom2 = other.geom2;
}
PointToLocal();
return *this;
}
void mjCPair::PointToLocal() {
spec.element = (mjElement)this;
spec.name = (mjString)&name;
@@ -3956,7 +3989,6 @@ mjCEquality::mjCEquality(mjCModel* _model, mjCDef* _def) {
// reset to default if given
if (_def) {
_def->equality.CopyFromSpec();
*this = _def->equality;
}
@@ -3964,7 +3996,7 @@ mjCEquality::mjCEquality(mjCModel* _model, mjCDef* _def) {
model = _model;
def = (_def ? _def : (_model ? _model->defaults[0] : 0));
// point to local (needs to be after defaults)
// point to local
PointToLocal();
// in case this camera is not compiled
@@ -3972,6 +4004,25 @@ mjCEquality::mjCEquality(mjCModel* _model, mjCDef* _def) {
}
mjCEquality::mjCEquality(const mjCEquality& other) {
*this = other;
}
mjCEquality& mjCEquality::operator=(const mjCEquality& other) {
if (this != &other) {
this->spec = other.spec;
*static_cast<mjCEquality_*>(this) = static_cast<const mjCEquality_&>(other);
*static_cast<mjmEquality*>(this) = static_cast<const mjmEquality&>(other);
}
PointToLocal();
return *this;
}
void mjCEquality::PointToLocal() {
spec.element = (mjElement)this;
spec.name = (mjString)&name;
@@ -4082,7 +4133,6 @@ mjCTendon::mjCTendon(mjCModel* _model, mjCDef* _def) {
// reset to default if given
if (_def) {
_def->tendon.CopyFromSpec();
*this = _def->tendon;
}
@@ -4090,7 +4140,7 @@ mjCTendon::mjCTendon(mjCModel* _model, mjCDef* _def) {
model = _model;
def = (_def ? _def : (_model ? _model->defaults[0] : 0));
// point to local (needs to be after defaults)
// point to local
PointToLocal();
// in case this camera is not compiled
@@ -4098,6 +4148,25 @@ mjCTendon::mjCTendon(mjCModel* _model, mjCDef* _def) {
}
mjCTendon::mjCTendon(const mjCTendon& other) {
*this = other;
}
mjCTendon& mjCTendon::operator=(const mjCTendon& other) {
if (this != &other) {
this->spec = other.spec;
*static_cast<mjmTendon*>(this) = static_cast<const mjmTendon&>(other);
*static_cast<mjmTendon*>(this) = static_cast<const mjmTendon&>(other);
}
PointToLocal();
return *this;
}
bool mjCTendon::is_limited() const { return islimited(limited, range); }
@@ -4467,7 +4536,6 @@ mjCActuator::mjCActuator(mjCModel* _model, mjCDef* _def) {
// reset to default if given
if (_def) {
_def->actuator.CopyFromSpec();
*this = _def->actuator;
}
@@ -4478,12 +4546,30 @@ mjCActuator::mjCActuator(mjCModel* _model, mjCDef* _def) {
// in case this actuator is not compiled
CopyFromSpec();
// point to local (needs to be after defaults)
// point to local
PointToLocal();
}
mjCActuator::mjCActuator(const mjCActuator& other) {
*this = other;
}
mjCActuator& mjCActuator::operator=(const mjCActuator& other) {
if (this != &other) {
this->spec = other.spec;
*static_cast<mjCActuator_*>(this) = static_cast<const mjCActuator_&>(other);
*static_cast<mjmActuator*>(this) = static_cast<const mjmActuator&>(other);
}
PointToLocal();
return *this;
}
bool mjCActuator::is_ctrllimited() const { return islimited(ctrllimited, ctrlrange); }
bool mjCActuator::is_forcelimited() const { return islimited(forcelimited, forcerange); }
bool mjCActuator::is_actlimited() const { return islimited(actlimited, actrange); }