Remove confusing operator overload in user_api.cc
Explicitly add const_cast. This doesn't change the previous behaviour, just makes it explicit. PiperOrigin-RevId: 772486471 Change-Id: I942bd4effed93a366089411ca18461cad52bff88
This commit is contained in:
committed by
Copybara-Service
parent
998769a995
commit
d9aae1521a
+8
-20
@@ -41,24 +41,6 @@ using mujoco::user::StringToVector;
|
|||||||
static constexpr std::size_t kGlobalCacheSize = 500 * (1 << 20);
|
static constexpr std::size_t kGlobalCacheSize = 500 * (1 << 20);
|
||||||
|
|
||||||
|
|
||||||
// prepend prefix
|
|
||||||
template <typename T>
|
|
||||||
static T& operator+(std::string_view prefix, T& base) {
|
|
||||||
base.prefix = std::string(prefix);
|
|
||||||
return base;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// append suffix
|
|
||||||
template <typename T>
|
|
||||||
static T& operator+(T& base, std::string_view suffix) {
|
|
||||||
base.suffix = std::string(suffix);
|
|
||||||
return base;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// create model
|
// create model
|
||||||
mjSpec* mj_makeSpec() {
|
mjSpec* mj_makeSpec() {
|
||||||
mjCModel* modelC = new mjCModel;
|
mjCModel* modelC = new mjCModel;
|
||||||
@@ -135,8 +117,11 @@ static void SetFrame(mjsBody* body, mjtObj objtype, mjsFrame* frame) {
|
|||||||
// attach body to a frame of the parent
|
// attach body to a frame of the parent
|
||||||
static mjsElement* attachBody(mjCFrame* parent, const mjCBody* child,
|
static mjsElement* attachBody(mjCFrame* parent, const mjCBody* child,
|
||||||
const char* prefix, const char* suffix) {
|
const char* prefix, const char* suffix) {
|
||||||
|
mjCBody* mutable_child = const_cast<mjCBody*>(child);
|
||||||
|
mutable_child->prefix = prefix;
|
||||||
|
mutable_child->suffix = suffix;
|
||||||
try {
|
try {
|
||||||
*parent += std::string(prefix) + *(mjCBody*)child + std::string(suffix);
|
*parent += *mutable_child;
|
||||||
} catch (mjCError& e) {
|
} catch (mjCError& e) {
|
||||||
parent->model->SetError(e);
|
parent->model->SetError(e);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -151,8 +136,11 @@ static mjsElement* attachBody(mjCFrame* parent, const mjCBody* child,
|
|||||||
// attach frame to a parent body
|
// attach frame to a parent body
|
||||||
static mjsElement* attachFrame(mjCBody* parent, const mjCFrame* child,
|
static mjsElement* attachFrame(mjCBody* parent, const mjCFrame* child,
|
||||||
const char* prefix, const char* suffix) {
|
const char* prefix, const char* suffix) {
|
||||||
|
mjCFrame* mutable_child = const_cast<mjCFrame*>(child);
|
||||||
|
mutable_child->prefix = prefix;
|
||||||
|
mutable_child->suffix = suffix;
|
||||||
try {
|
try {
|
||||||
*parent += std::string(prefix) + *(mjCFrame*)child + std::string(suffix);
|
*parent += *mutable_child;
|
||||||
} catch (mjCError& e) {
|
} catch (mjCError& e) {
|
||||||
parent->model->SetError(e);
|
parent->model->SetError(e);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user