diff --git a/src/user/user_api.cc b/src/user/user_api.cc index 1c6384fc..e99ea886 100644 --- a/src/user/user_api.cc +++ b/src/user/user_api.cc @@ -581,66 +581,61 @@ mjElement* mjs_nextChild(mjsBody* body, mjElement* child) { // set string -void mjs_setString(mjString dest, const char* text) { - std::string* str = reinterpret_cast(dest); +void mjs_setString(mjString* dest, const char* text) { + std::string* str = static_cast(dest); *str = std::string(text); } // Set specific entry in destination string vector. -mjtByte mjs_setInStringVec(mjStringVec dest, int i, const char* text) { - std::vector* v = reinterpret_cast*>(dest); - if (v->size() <= i) { +mjtByte mjs_setInStringVec(mjStringVec* dest, int i, const char* text) { + if (dest->size() <= i) { mju_error("Requested index in mjs_setInStringVec is out of bounds"); return 0; } - v->at(i) = std::string(text); + dest->at(i) = std::string(text); return 1; } // split text and copy into string array -void mjs_setStringVec(mjStringVec dest, const char* text) { - std::vector* v = reinterpret_cast*>(dest); +void mjs_setStringVec(mjStringVec* dest, const char* text) { + std::vector* v = static_cast*>(dest); *v = mjXUtil::String2Vector(text); } // add text entry to destination string vector -void mjs_appendString(mjStringVec dest, const char* text) { - std::vector* v = reinterpret_cast*>(dest); - v->push_back(std::string(text)); +void mjs_appendString(mjStringVec* dest, const char* text) { + dest->push_back(std::string(text)); } // copy int array to vector -void mjs_setInt(mjIntVec dest, const int* array, int size) { - std::vector* v = reinterpret_cast*>(dest); - v->assign(size, 0.0); +void mjs_setInt(mjIntVec* dest, const int* array, int size) { + dest->assign(size, 0.0); for (int i = 0; i < size; ++i) { - (*v)[i] = array[i]; + (*dest)[i] = array[i]; } } // append int array to vector of arrays -void mjs_appendIntVec(mjIntVecVec dest, const int* array, int size) { - std::vector>* v = reinterpret_cast>*>(dest); - v->push_back(std::vector(array, array + size)); +void mjs_appendIntVec(mjIntVecVec* dest, const int* array, int size) { + dest->push_back(std::vector(array, array + size)); } // copy float array to vector -void mjs_setFloat(mjFloatVec dest, const float* array, int size) { - std::vector* v = reinterpret_cast*>(dest); - v->assign(size, 0.0); +void mjs_setFloat(mjFloatVec* dest, const float* array, int size) { + dest->assign(size, 0.0); for (int i = 0; i < size; ++i) { - (*v)[i] = array[i]; + (*dest)[i] = array[i]; } } @@ -648,42 +643,35 @@ void mjs_setFloat(mjFloatVec dest, const float* array, int size) { // append float array to vector of arrays -void mjs_appendFloatVec(mjFloatVecVec dest, const float* array, int size) { - std::vector>* v = reinterpret_cast>*>(dest); - v->push_back(std::vector(array, array + size)); +void mjs_appendFloatVec(mjFloatVecVec* dest, const float* array, int size) { + dest->push_back(std::vector(array, array + size)); } // copy double array to vector -void mjs_setDouble(mjDoubleVec dest, const double* array, int size) { - std::vector* v = reinterpret_cast*>(dest); - v->assign(size, 0.0); +void mjs_setDouble(mjDoubleVec* dest, const double* array, int size) { + dest->assign(size, 0.0); for (int i = 0; i < size; ++i) { - (*v)[i] = array[i]; + (*dest)[i] = array[i]; } } // get string -const char* mjs_getString(const mjString source) { - std::string* str = reinterpret_cast(source); - if (!str) { - return nullptr; - } - return str->c_str(); +const char* mjs_getString(const mjString* source) { + return source->c_str(); } // get double array -const double* mjs_getDouble(const mjDoubleVec source, int* size) { - std::vector* v = reinterpret_cast*>(source); +const double* mjs_getDouble(const mjDoubleVec* source, int* size) { if (size) { - *size = v->size(); + *size = source->size(); } - return v->data(); + return source->data(); } diff --git a/src/user/user_api.h b/src/user/user_api.h index cc192cb3..96650d7e 100644 --- a/src/user/user_api.h +++ b/src/user/user_api.h @@ -25,21 +25,36 @@ // this is a C-API #ifdef __cplusplus +#include +#include + extern "C" { #endif #define mjNAN NAN // used to mark undefined fields -//---------------------------------- handles to internal objects ----------------------------------- +//---------------------------------- C/C++ handles to strings and arrays --------------------------- -typedef struct mjString_* mjString; -typedef struct mjStringVec_* mjStringVec; -typedef struct mjIntVec_* mjIntVec; -typedef struct mjIntVecVec_* mjIntVecVec; -typedef struct mjFloatVec_* mjFloatVec; -typedef struct mjFloatVecVec_* mjFloatVecVec; -typedef struct mjDoubleVec_* mjDoubleVec; +#ifdef __cplusplus + // C++, defined to be compatible with corresponding std types + using mjString = std::string; + using mjStringVec = std::vector; + using mjIntVec = std::vector; + using mjIntVecVec = std::vector>; + using mjFloatVec = std::vector; + using mjFloatVecVec = std::vector>; + using mjDoubleVec = std::vector; +#else + // C, opaque pointers + typedef struct mjString_ mjString; + typedef struct mjStringVec_ mjStringVec; + typedef struct mjIntVec_ mjIntVec; + typedef struct mjIntVecVec_ mjIntVecVec; + typedef struct mjFloatVec_ mjFloatVec; + typedef struct mjFloatVecVec_ mjFloatVecVec; + typedef struct mjDoubleVec_ mjDoubleVec; +#endif //---------------------------------- enum types (mjt) ---------------------------------------------- @@ -98,7 +113,7 @@ typedef struct mjElement_ { // element type, do not modify typedef struct mjSpec_ { // model specification mjElement* element; // element type - mjString modelname; // model name + mjString* modelname; // model name // compiler settings mjtByte autolimits; // infer "limited" attribute based on range @@ -110,8 +125,8 @@ typedef struct mjSpec_ { // model specification mjtByte fitaabb; // meshfit to aabb instead of inertia box mjtByte degree; // angles in radians or degrees char euler[3]; // sequence for euler rotations - mjString meshdir; // mesh and hfield directory - mjString texturedir; // texture directory + mjString* meshdir; // mesh and hfield directory + mjString* texturedir; // texture directory mjtByte discardvisual; // discard visual geoms in parser mjtByte convexhull; // compute mesh convex hulls mjtByte usethread; // use multiple threads to speed up compiler @@ -144,8 +159,8 @@ typedef struct mjSpec_ { // model specification size_t nstack; // (deprecated) number of mjtNums in mjData stack // global data - mjString comment; // comment at top of XML - mjString modelfiledir; // path to model file + mjString* comment; // comment at top of XML + mjString* modelfiledir; // path to model file // other mjtByte hasImplicitPluginElem; // already encountered an implicit plugin sensor/actuator @@ -163,18 +178,18 @@ typedef struct mjsOrientation_ { // alternative orientation specifiers typedef struct mjsPlugin_ { // plugin specification mjElement* instance; // element type - mjString name; // name - mjString instance_name; // instance name + mjString* name; // name + mjString* instance_name; // instance name int plugin_slot; // global registered slot number of the plugin mjtByte active; // is the plugin active - mjString info; // message appended to compiler errors + mjString* info; // message appended to compiler errors } mjsPlugin; typedef struct mjsBody_ { // body specification mjElement* element; // element type - mjString name; // name - mjString childclass; // childclass name + mjString* name; // name + mjString* childclass; // childclass name // body frame double pos[3]; // frame position @@ -192,28 +207,28 @@ typedef struct mjsBody_ { // body specification // other mjtByte mocap; // is this a mocap body double gravcomp; // gravity compensation - mjDoubleVec userdata; // user data + mjDoubleVec* userdata; // user data mjtByte explicitinertial; // whether to save the body with explicit inertial clause mjsPlugin plugin; // passive force plugin - mjString info; // message appended to compiler errors + mjString* info; // message appended to compiler errors } mjsBody; typedef struct mjsFrame_ { // frame specification mjElement* element; // element type - mjString name; // name - mjString childclass; // childclass name + mjString* name; // name + mjString* childclass; // childclass name double pos[3]; // position double quat[4]; // orientation mjsOrientation alt; // alternative orientation - mjString info; // message appended to compiler errors + mjString* info; // message appended to compiler errors } mjsFrame; typedef struct mjsJoint_ { // joint specification mjElement* element; // element type - mjString name; // name - mjString classname; // class name + mjString* name; // name + mjString* classname; // class name mjtJoint type; // joint type // kinematics @@ -245,15 +260,15 @@ typedef struct mjsJoint_ { // joint specification // other int group; // group mjtByte actgravcomp; // is gravcomp force applied via actuators - mjDoubleVec userdata; // user data - mjString info; // message appended to compiler errors + mjDoubleVec* userdata; // user data + mjString* info; // message appended to compiler errors } mjsJoint; typedef struct mjsGeom_ { // geom specification mjElement* element; // element type - mjString name; // name - mjString classname; // classname + mjString* name; // name + mjString* classname; // classname mjtGeom type; // geom type // frame, size @@ -285,24 +300,24 @@ typedef struct mjsGeom_ { // geom specification mjtNum fluid_coefs[5]; // ellipsoid-fluid interaction coefs // visual - mjString material; // name of material + mjString* material; // name of material float rgba[4]; // rgba when material is omitted int group; // group // other - mjString hfieldname; // heightfield attached to geom - mjString meshname; // mesh attached to geom + mjString* hfieldname; // heightfield attached to geom + mjString* meshname; // mesh attached to geom double fitscale; // scale mesh uniformly - mjDoubleVec userdata; // user data + mjDoubleVec* userdata; // user data mjsPlugin plugin; // sdf plugin - mjString info; // message appended to compiler errors + mjString* info; // message appended to compiler errors } mjsGeom; typedef struct mjsSite_ { // site specification mjElement* element; // element type - mjString name; // name - mjString classname; // class name + mjString* name; // name + mjString* classname; // class name // frame, size double pos[3]; // position @@ -313,27 +328,27 @@ typedef struct mjsSite_ { // site specification // visual mjtGeom type; // geom type - mjString material; // name of material + mjString* material; // name of material int group; // group float rgba[4]; // rgba when material is omitted // other - mjDoubleVec userdata; // user data - mjString info; // message appended to compiler errors + mjDoubleVec* userdata; // user data + mjString* info; // message appended to compiler errors } mjsSite; typedef struct mjsCamera_ { // camera specification mjElement* element; // element type - mjString name; // name - mjString classname; // class name + mjString* name; // name + mjString* classname; // class name // extrinsics double pos[3]; // position double quat[4]; // orientation mjsOrientation alt; // alternative orientation mjtCamLight mode; // tracking mode - mjString targetbody; // target body for tracking/targeting + mjString* targetbody; // target body for tracking/targeting // intrinsics double fovy; // y-field of view @@ -347,21 +362,21 @@ typedef struct mjsCamera_ { // camera specification float principal_pixel[2]; // principal point (pixel) // other - mjDoubleVec userdata; // user data - mjString info; // message appended to compiler errors + mjDoubleVec* userdata; // user data + mjString* info; // message appended to compiler errors } mjsCamera; typedef struct mjsLight_ { // light specification mjElement* element; // element type - mjString name; // name - mjString classname; // class name + mjString* name; // name + mjString* classname; // class name // frame double pos[3]; // position double dir[3]; // direction mjtCamLight mode; // tracking mode - mjString targetbody; // target body for targeting + mjString* targetbody; // target body for targeting // intrinsics mjtByte active; // is light active @@ -376,14 +391,14 @@ typedef struct mjsLight_ { // light specification float specular[3]; // specular color // other - mjString info; // message appended to compiler errors + mjString* info; // message appended to compiler errorsx } mjsLight; typedef struct mjsFlex_ { mjElement* element; // element type - mjString name; // name - mjString classname; // class name + mjString* name; // name + mjString* classname; // class name // contact properties int contype; // contact type @@ -408,85 +423,85 @@ typedef struct mjsFlex_ { double edgestiffness; // edge stiffness double edgedamping; // edge damping float rgba[4]; // rgba when material is omitted - mjString material; // name of material used for rendering + mjString* material; // name of material used for rendering // mesh properties - mjStringVec vertbody; // vertex body names - mjDoubleVec vert; // vertex positions - mjIntVec elem; // element vertex ids - mjFloatVec texcoord; // vertex texture coordinates + mjStringVec* vertbody; // vertex body names + mjDoubleVec* vert; // vertex positions + mjIntVec* elem; // element vertex ids + mjFloatVec* texcoord; // vertex texture coordinates // other - mjString info; // message appended to compiler errors + mjString* info; // message appended to compiler errors } mjsFlex; typedef struct mjsMesh_ { // mesh specification mjElement* element; // element type - mjString name; // name - mjString classname; // class name - mjString content_type; // content type of file - mjString file; // mesh file + mjString* name; // name + mjString* classname; // class name + mjString* content_type; // content type of file + mjString* file; // mesh file double refpos[3]; // reference position double refquat[4]; // reference orientation double scale[3]; // rescale mesh mjtByte smoothnormal; // do not exclude large-angle faces from normals - mjFloatVec uservert; // user vertex data - mjFloatVec usernormal; // user normal data - mjFloatVec usertexcoord; // user texcoord data - mjIntVec userface; // user vertex indices - mjIntVec userfacenormal; // user normal indices - mjIntVec userfacetexcoord; // user texcoord indices + mjFloatVec* uservert; // user vertex data + mjFloatVec* usernormal; // user normal data + mjFloatVec* usertexcoord; // user texcoord data + mjIntVec* userface; // user vertex indices + mjIntVec* userfacenormal; // user normal indices + mjIntVec* userfacetexcoord; // user texcoord indices mjsPlugin plugin; // sdf plugin - mjString info; // message appended to compiler errors + mjString* info; // message appended to compiler errors } mjsMesh; typedef struct mjsHField_ { // height field specification mjElement* element; // element type - mjString name; // name - mjString content_type; // content type of file - mjString file; // file: (nrow, ncol, [elevation data]) + mjString* name; // name + mjString* content_type; // content type of file + mjString* file; // file: (nrow, ncol, [elevation data]) double size[4]; // hfield size (ignore referencing geom size) int nrow; // number of rows int ncol; // number of columns - mjFloatVec userdata; // user-provided elevation data - mjString info; // message appended to compiler errors + mjFloatVec* userdata; // user-provided elevation data + mjString* info; // message appended to compiler errors } mjsHField; typedef struct mjsSkin_ { // skin specification mjElement* element; // element type - mjString name; // name - mjString classname; // class name - mjString file; // skin file - mjString material; // name of material used for rendering + mjString* name; // name + mjString* classname; // class name + mjString* file; // skin file + mjString* material; // name of material used for rendering float rgba[4]; // rgba when material is omitted float inflate; // inflate in normal direction int group; // group for visualization // mesh - mjFloatVec vert; // vertex positions - mjFloatVec texcoord; // texture coordinates - mjIntVec face; // faces + mjFloatVec* vert; // vertex positions + mjFloatVec* texcoord; // texture coordinates + mjIntVec* face; // faces // skin - mjStringVec bodyname; // body names - mjFloatVec bindpos; // bind pos - mjFloatVec bindquat; // bind quat - mjIntVecVec vertid; // vertex ids - mjFloatVecVec vertweight; // vertex weights + mjStringVec* bodyname; // body names + mjFloatVec* bindpos; // bind pos + mjFloatVec* bindquat; // bind quat + mjIntVecVec* vertid; // vertex ids + mjFloatVecVec* vertweight; // vertex weights // other - mjString info; // message appended to compiler errors + mjString* info; // message appended to compiler errors } mjsSkin; typedef struct mjsTexture_ { // texture specification mjElement* element; // element type - mjString name; // name - mjString classname; // class name + mjString* name; // name + mjString* classname; // class name mjtTexture type; // texture type // method 1: builtin @@ -500,28 +515,28 @@ typedef struct mjsTexture_ { // texture specification int width; // width in pixels // method 2: single file - mjString content_type; // content type of file - mjString file; // png file to load; use for all sides of cube + mjString* content_type; // content type of file + mjString* file; // png file to load; use for all sides of cube int gridsize[2]; // size of grid for composite file; (1,1)-repeat char gridlayout[13]; // row-major: L,R,F,B,U,D for faces; . for unused // method 3: separate files - mjStringVec cubefiles; // different file for each side of the cube + mjStringVec* cubefiles; // different file for each side of the cube // flip options mjtByte hflip; // horizontal flip mjtByte vflip; // vertical flip // other - mjString info; // message appended to compiler errors + mjString* info; // message appended to compiler errors } mjsTexture; typedef struct mjsMaterial_ { // material specification mjElement* element; // element type - mjString name; // name - mjString classname; // class name - mjString texture; // name of texture (empty: none) + mjString* name; // name + mjString* classname; // class name + mjString* texture; // name of texture (empty: none) mjtByte texuniform; // make texture cube uniform float texrepeat[2]; // texture repetition for 2D mapping float emission; // emission @@ -531,16 +546,16 @@ typedef struct mjsMaterial_ { // material specification float metallic; // metallic float roughness; // roughness float rgba[4]; // rgba - mjString info; // message appended to compiler errors + mjString* info; // message appended to compiler errors } mjsMaterial; typedef struct mjsPair_ { mjElement* element; // element type - mjString name; // name - mjString classname; // class name - mjString geomname1; // name of geom 1 - mjString geomname2; // name of geom 2 + mjString* name; // name + mjString* classname; // class name + mjString* geomname1; // name of geom 1 + mjString* geomname2; // name of geom 2 // optional parameters: computed from geoms if not set by user int condim; // contact dimensionality @@ -550,38 +565,38 @@ typedef struct mjsPair_ { double margin; // margin for contact detection double gap; // include in solver if dist(this); - spec.name = (mjString)&name; - spec.classname = (mjString)&classname; - spec.file = (mjString)&spec_file_; - spec.content_type = (mjString)&spec_content_type_; - spec.uservert = (mjFloatVec)&spec_vert_; - spec.usernormal = (mjFloatVec)&spec_normal_; - spec.userface = (mjIntVec)&spec_face_; - spec.usertexcoord = (mjFloatVec)&spec_texcoord_; - spec.userfacetexcoord = (mjIntVec)&spec_facetexcoord_; - spec.plugin.name = (mjString)&plugin_name; - spec.plugin.instance_name = (mjString)&plugin_instance_name; - spec.info = (mjString)&info; + spec.name = &name; + spec.classname = &classname; + spec.file = &spec_file_; + spec.content_type = &spec_content_type_; + spec.uservert = &spec_vert_; + spec.usernormal = &spec_normal_; + spec.userface = &spec_face_; + spec.usertexcoord = &spec_texcoord_; + spec.userfacetexcoord = &spec_facetexcoord_; + spec.plugin.name = &plugin_name; + spec.plugin.instance_name = &plugin_instance_name; + spec.info = &info; } @@ -221,13 +221,13 @@ void mjCMesh::CopyFromSpec() { face_ = spec_face_; texcoord_ = spec_texcoord_; facetexcoord_ = spec_facetexcoord_; - file = (mjString)&file_; - content_type = (mjString)&content_type_; - uservert = (mjFloatVec)&vert_; - usernormal = (mjFloatVec)&normal_; - userface = (mjIntVec)&face_; - usertexcoord = (mjFloatVec)&texcoord_; - userfacetexcoord = (mjIntVec)&facetexcoord_; + file = &file_; + content_type = &content_type_; + uservert = &vert_; + usernormal = &normal_; + userface = &face_; + usertexcoord = &texcoord_; + userfacetexcoord = &facetexcoord_; plugin.active = spec.plugin.active; plugin.instance = spec.plugin.instance; plugin.name = spec.plugin.name; @@ -1979,19 +1979,19 @@ mjCSkin& mjCSkin::operator=(const mjCSkin& other) { void mjCSkin::PointToLocal() { spec.element = static_cast(this); - spec.name = (mjString)&name; - spec.classname = (mjString)&classname; - spec.file = (mjString)&spec_file_; - spec.material = (mjString)&spec_material_; - spec.vert = (mjFloatVec)&spec_vert_; - spec.texcoord = (mjFloatVec)&spec_texcoord_; - spec.face = (mjIntVec)&spec_face_; - spec.bodyname = (mjStringVec)&spec_bodyname_; - spec.bindpos = (mjFloatVec)&spec_bindpos_; - spec.bindquat = (mjFloatVec)&spec_bindquat_; - spec.vertid = (mjIntVecVec)&spec_vertid_; - spec.vertweight = (mjFloatVecVec)&spec_vertweight_; - spec.info = (mjString)&info; + spec.name = &name; + spec.classname = &classname; + spec.file = &spec_file_; + spec.material = &spec_material_; + spec.vert = &spec_vert_; + spec.texcoord = &spec_texcoord_; + spec.face = &spec_face_; + spec.bodyname = &spec_bodyname_; + spec.bindpos = &spec_bindpos_; + spec.bindquat = &spec_bindquat_; + spec.vertid = &spec_vertid_; + spec.vertweight = &spec_vertweight_; + spec.info = &info; } @@ -2016,16 +2016,16 @@ void mjCSkin::CopyFromSpec() { bindquat_ = spec_bindquat_; vertid_ = spec_vertid_; vertweight_ = spec_vertweight_; - file = (mjString)&spec_file_; - material = (mjString)&spec_material_; - vert = (mjFloatVec)&spec_vert_; - texcoord = (mjFloatVec)&spec_texcoord_; - face = (mjIntVec)&spec_face_; - bodyname = (mjStringVec)&spec_bodyname_; - bindpos = (mjFloatVec)&spec_bindpos_; - bindquat = (mjFloatVec)&spec_bindquat_; - vertid = (mjIntVecVec)&spec_vertid_; - vertweight = (mjFloatVecVec)&spec_vertweight_; + file = &spec_file_; + material = &spec_material_; + vert = &spec_vert_; + texcoord = &spec_texcoord_; + face = &spec_face_; + bodyname = &spec_bodyname_; + bindpos = &spec_bindpos_; + bindquat = &spec_bindquat_; + vertid = &spec_vertid_; + vertweight = &spec_vertweight_; } @@ -2391,14 +2391,14 @@ mjCFlex& mjCFlex::operator=(const mjCFlex& other) { void mjCFlex::PointToLocal() { spec.element = static_cast(this); - spec.name = (mjString)&name; - spec.classname = (mjString)&classname; - spec.material = (mjString)&spec_material_; - spec.vertbody = (mjStringVec)&spec_vertbody_; - spec.vert = (mjDoubleVec)&spec_vert_; - spec.texcoord = (mjFloatVec)&spec_texcoord_; - spec.elem = (mjIntVec)&spec_elem_; - spec.info = (mjString)&info; + spec.name = &name; + spec.classname = &classname; + spec.material = &spec_material_; + spec.vertbody = &spec_vertbody_; + spec.vert = &spec_vert_; + spec.texcoord = &spec_texcoord_; + spec.elem = &spec_elem_; + spec.info = &info; } @@ -2413,17 +2413,17 @@ void mjCFlex::NameSpace(const mjCModel* m) { void mjCFlex::CopyFromSpec() { *static_cast(this) = spec; - spec.info = (mjString)&info; + spec.info = &info; material_ = spec_material_; vertbody_ = spec_vertbody_; vert_ = spec_vert_; texcoord_ = spec_texcoord_; elem_ = spec_elem_; - material = (mjString)&material_; - vertbody = (mjStringVec)&vertbody_; - vert = (mjDoubleVec)&vert_; - texcoord = (mjFloatVec)&texcoord_; - elem = (mjIntVec)&elem_; + material = &material_; + vertbody = &vertbody_; + vert = &vert_; + texcoord = &texcoord_; + elem = &elem_; // clear precompiled asset. TODO: use asset cache nedge = 0; diff --git a/src/user/user_model.cc b/src/user/user_model.cc index f2bcbe5a..0a4f6f44 100644 --- a/src/user/user_model.cc +++ b/src/user/user_model.cc @@ -417,11 +417,11 @@ void mjCModel::CreateObjectLists() { void mjCModel::PointToLocal() { spec.element = static_cast(this); - spec.comment = (mjString)&spec_comment_; - spec.modelfiledir = (mjString)&spec_modelfiledir_; - spec.modelname = (mjString)&spec_modelname_; - spec.meshdir = (mjString)&spec_meshdir_; - spec.texturedir = (mjString)&spec_texturedir_; + spec.comment = &spec_comment_; + spec.modelfiledir = &spec_modelfiledir_; + spec.modelname = &spec_modelname_; + spec.meshdir = &spec_meshdir_; + spec.texturedir = &spec_texturedir_; } @@ -433,11 +433,11 @@ void mjCModel::CopyFromSpec() { modelname_ = spec_modelname_; meshdir_ = spec_meshdir_; texturedir_ = spec_texturedir_; - comment = (mjString)&comment_; - modelfiledir = (mjString)&modelfiledir_; - modelname = (mjString)&modelname_; - meshdir = (mjString)&meshdir_; - texturedir = (mjString)&texturedir_; + comment = &comment_; + modelfiledir = &modelfiledir_; + modelname = &modelname_; + meshdir = &meshdir_; + texturedir = &texturedir_; } diff --git a/src/user/user_objects.cc b/src/user/user_objects.cc index d59e4950..6ff8c13c 100644 --- a/src/user/user_objects.cc +++ b/src/user/user_objects.cc @@ -641,7 +641,7 @@ void mjCDef::PointToLocal() { tendon_.PointToLocal(); actuator_.PointToLocal(); spec.element = static_cast(this); - spec.name = (mjString)&name; + spec.name = &name; spec.joint = &joint_.spec; spec.geom = &geom_.spec; spec.site = &site_.spec; @@ -950,19 +950,19 @@ mjCBody& mjCBody::operator-=(const mjCBody& subtree) { void mjCBody::PointToLocal() { spec.element = static_cast(this); - spec.name = (mjString)&name; - spec.childclass = (mjString)&classname; - spec.userdata = (mjDoubleVec)&spec_userdata_; - spec.plugin.name = (mjString)&plugin_name; - spec.plugin.instance_name = (mjString)&plugin_instance_name; - spec.info = (mjString)&info; + spec.name = &name; + spec.childclass = &classname; + spec.userdata = &spec_userdata_; + spec.plugin.name = &plugin_name; + spec.plugin.instance_name = (&plugin_instance_name); + spec.info = &info; } void mjCBody::CopyFromSpec() { *static_cast(this) = spec; userdata_ = spec_userdata_; - userdata = (mjDoubleVec)&userdata_; + userdata = &userdata_; plugin.active = spec.plugin.active; plugin.instance = spec.plugin.instance; plugin.name = spec.plugin.name; @@ -1670,9 +1670,9 @@ void mjCFrame::SetParent(mjCBody* _body) { void mjCFrame::PointToLocal() { spec.element = static_cast(this); - spec.name = (mjString)&name; - spec.childclass = (mjString)&classname; - spec.info = (mjString)&info; + spec.name = &name; + spec.childclass = &classname; + spec.info = &info; } @@ -1766,10 +1766,10 @@ bool mjCJoint::is_actfrclimited() const { return islimited(actfrclimited, actfrc void mjCJoint::PointToLocal() { spec.element = static_cast(this); - spec.name = (mjString)&name; - spec.classname = (mjString)&classname; - spec.userdata = (mjDoubleVec)&spec_userdata_; - spec.info = (mjString)&info; + spec.name = &name; + spec.classname = &classname; + spec.userdata = &spec_userdata_; + spec.info = &info; } @@ -1777,7 +1777,7 @@ void mjCJoint::PointToLocal() { void mjCJoint::CopyFromSpec() { *static_cast(this) = spec; userdata_ = spec_userdata_; - userdata = (mjDoubleVec)&spec_userdata_; + userdata = &spec_userdata_; } @@ -1966,15 +1966,15 @@ mjCGeom& mjCGeom::operator=(const mjCGeom& other) { // to be called after any default copy constructor void mjCGeom::PointToLocal(void) { spec.element = static_cast(this); - spec.name = (mjString)&name; - spec.info = (mjString)&info; - spec.classname = (mjString)&classname; - spec.userdata = (mjDoubleVec)&spec_userdata_; - spec.material = (mjString)&spec_material_; - spec.meshname = (mjString)&spec_meshname_; - spec.hfieldname = (mjString)&spec_hfieldname_; - spec.plugin.name = (mjString)&plugin_name; - spec.plugin.instance_name = (mjString)&plugin_instance_name; + spec.name = &name; + spec.info = &info; + spec.classname = &classname; + spec.userdata = &spec_userdata_; + spec.material = &spec_material_; + spec.meshname = &spec_meshname_; + spec.hfieldname = &spec_hfieldname_; + spec.plugin.name = &plugin_name; + spec.plugin.instance_name = &plugin_instance_name; } @@ -1985,10 +1985,10 @@ void mjCGeom::CopyFromSpec() { hfieldname_ = spec_hfieldname_; meshname_ = spec_meshname_; material_ = spec_material_; - userdata = (mjDoubleVec)&userdata_; - hfieldname = (mjString)&hfieldname_; - meshname = (mjString)&meshname_; - material = (mjString)&material_; + userdata = &userdata_; + hfieldname = &hfieldname_; + meshname = &meshname_; + material = &material_; plugin.active = spec.plugin.active; plugin.instance = spec.plugin.instance; plugin.name = spec.plugin.name; @@ -2599,11 +2599,11 @@ mjCSite& mjCSite::operator=(const mjCSite& other) { void mjCSite::PointToLocal() { spec.element = static_cast(this); - spec.name = (mjString)&name; - spec.info = (mjString)&info; - spec.classname = (mjString)&classname; - spec.material = (mjString)&spec_material_; - spec.userdata = (mjDoubleVec)&spec_userdata_; + spec.name = &name; + spec.info = &info; + spec.classname = &classname; + spec.material = &spec_material_; + spec.userdata = &spec_userdata_; } @@ -2612,8 +2612,8 @@ void mjCSite::CopyFromSpec() { *static_cast(this) = spec; userdata_ = spec_userdata_; material_ = spec_material_; - userdata = (mjDoubleVec)&userdata_; - material = (mjString)&material_; + userdata = &userdata_; + material = &material_; } @@ -2751,11 +2751,11 @@ mjCCamera& mjCCamera::operator=(const mjCCamera& other) { void mjCCamera::PointToLocal() { spec.element = static_cast(this); - spec.name = (mjString)&name; - spec.classname = (mjString)&classname; - spec.userdata = (mjDoubleVec)&spec_userdata_; - spec.targetbody = (mjString)&spec_targetbody_; - spec.info = (mjString)&info; + spec.name = &name; + spec.classname = &classname; + spec.userdata = &spec_userdata_; + spec.targetbody = &spec_targetbody_; + spec.info = &info; } @@ -2775,8 +2775,8 @@ void mjCCamera::CopyFromSpec() { *static_cast(this) = spec; userdata_ = spec_userdata_; targetbody_ = spec_targetbody_; - userdata = (mjDoubleVec)&userdata_; - targetbody = (mjString)&targetbody_; + userdata = &userdata_; + targetbody = &targetbody_; } @@ -2902,10 +2902,10 @@ mjCLight& mjCLight::operator=(const mjCLight& other) { void mjCLight::PointToLocal() { spec.element = static_cast(this); - spec.name = (mjString)&name; - spec.classname = (mjString)&classname; - spec.targetbody = (mjString)&spec_targetbody_; - spec.info = (mjString)&info; + spec.name = &name; + spec.classname = &classname; + spec.targetbody = &spec_targetbody_; + spec.info = &info; } @@ -2924,7 +2924,7 @@ void mjCLight::NameSpace(const mjCModel* m) { void mjCLight::CopyFromSpec() { *static_cast(this) = spec; targetbody_ = spec_targetbody_; - targetbody = (mjString)&targetbody_; + targetbody = &targetbody_; } @@ -3002,11 +3002,11 @@ mjCHField& mjCHField::operator=(const mjCHField& other) { void mjCHField::PointToLocal() { spec.element = static_cast(this); - spec.name = (mjString)&name; - spec.file = (mjString)&spec_file_; - spec.content_type = (mjString)&spec_content_type_; - spec.userdata = (mjFloatVec)&spec_userdata_; - spec.info = (mjString)&info; + spec.name = &name; + spec.file = &spec_file_; + spec.content_type = &spec_content_type_; + spec.userdata = &spec_userdata_; + spec.info = &info; } @@ -3016,9 +3016,9 @@ void mjCHField::CopyFromSpec() { file_ = spec_file_; content_type_ = spec_content_type_; userdata_ = spec_userdata_; - file = (mjString)&file_; - content_type = (mjString)&content_type_; - userdata = (mjFloatVec)&userdata_; + file = &file_; + content_type = &content_type_; + userdata = &userdata_; // clear precompiled asset. TODO: use asset cache data.clear(); @@ -3231,12 +3231,12 @@ mjCTexture& mjCTexture::operator=(const mjCTexture& other) { void mjCTexture::PointToLocal() { spec.element = static_cast(this); - spec.name = (mjString)&name; - spec.classname = (mjString)&classname; - spec.file = (mjString)&spec_file_; - spec.content_type = (mjString)&spec_content_type_; - spec.cubefiles = (mjStringVec)&spec_cubefiles_; - spec.info = (mjString)&info; + spec.name = &name; + spec.classname = &classname; + spec.file = &spec_file_; + spec.content_type = &spec_content_type_; + spec.cubefiles = &spec_cubefiles_; + spec.info = &info; } @@ -3246,9 +3246,9 @@ void mjCTexture::CopyFromSpec() { file_ = spec_file_; content_type_ = spec_content_type_; cubefiles_ = spec_cubefiles_; - file = (mjString)&file_; - content_type = (mjString)&content_type_; - cubefiles = (mjStringVec)&cubefiles_; + file = &file_; + content_type = &content_type_; + cubefiles = &cubefiles_; // clear precompiled asset. TODO: use asset cache rgb.clear(); @@ -3942,10 +3942,10 @@ mjCMaterial& mjCMaterial::operator=(const mjCMaterial& other) { void mjCMaterial::PointToLocal() { spec.element = static_cast(this); - spec.name = (mjString)&name; - spec.classname = (mjString)&classname; - spec.texture = (mjString)&spec_texture_; - spec.info = (mjString)&info; + spec.name = &name; + spec.classname = &classname; + spec.texture = &spec_texture_; + spec.info = &info; } @@ -3953,7 +3953,7 @@ void mjCMaterial::PointToLocal() { void mjCMaterial::CopyFromSpec() { *static_cast(this) = spec; texture_ = spec_texture_; - texture = (mjString)&texture_; + texture = &texture_; } @@ -4032,11 +4032,11 @@ mjCPair& mjCPair::operator=(const mjCPair& other) { void mjCPair::PointToLocal() { spec.element = static_cast(this); - spec.name = (mjString)&name; - spec.classname = (mjString)&classname; - spec.geomname1 = (mjString)&spec_geomname1_; - spec.geomname2 = (mjString)&spec_geomname2_; - spec.info = (mjString)&info; + spec.name = &name; + spec.classname = &classname; + spec.geomname1 = &spec_geomname1_; + spec.geomname2 = &spec_geomname2_; + spec.info = &info; } @@ -4055,8 +4055,8 @@ void mjCPair::CopyFromSpec() { *static_cast(this) = spec; geomname1_ = spec_geomname1_; geomname2_ = spec_geomname2_; - geomname1 = (mjString)&geomname1_; - geomname2 = (mjString)&geomname2_; + geomname1 = &geomname1_; + geomname2 = &geomname2_; } @@ -4257,10 +4257,10 @@ mjCBodyPair& mjCBodyPair::operator=(const mjCBodyPair& other) { void mjCBodyPair::PointToLocal() { spec.element = static_cast(this); - spec.name = (mjString)&name; - spec.bodyname1 = (mjString)&spec_bodyname1_; - spec.bodyname2 = (mjString)&spec_bodyname2_; - spec.info = (mjString)&info; + spec.name = &name; + spec.bodyname1 = &spec_bodyname1_; + spec.bodyname2 = &spec_bodyname2_; + spec.info = &info; } @@ -4279,8 +4279,8 @@ void mjCBodyPair::CopyFromSpec() { *static_cast(this) = spec; bodyname1_ = spec_bodyname1_; bodyname2_ = spec_bodyname2_; - bodyname1 = (mjString)&bodyname1_; - bodyname2 = (mjString)&bodyname2_; + bodyname1 = &bodyname1_; + bodyname2 = &bodyname2_; } @@ -4391,11 +4391,11 @@ mjCEquality& mjCEquality::operator=(const mjCEquality& other) { void mjCEquality::PointToLocal() { spec.element = static_cast(this); - spec.name = (mjString)&name; - spec.classname = (mjString)&classname; - spec.name1 = (mjString)&spec_name1_; - spec.name2 = (mjString)&spec_name2_; - spec.info = (mjString)&info; + spec.name = &name; + spec.classname = &classname; + spec.name1 = &spec_name1_; + spec.name2 = &spec_name2_; + spec.info = &info; } @@ -4414,8 +4414,8 @@ void mjCEquality::CopyFromSpec() { *static_cast(this) = spec; name1_ = spec_name1_; name2_ = spec_name2_; - name1 = (mjString)&name1_; - name2 = (mjString)&name2_; + name1 = &name1_; + name2 = &name2_; } @@ -4560,11 +4560,11 @@ bool mjCTendon::is_limited() const { return islimited(limited, range); } void mjCTendon::PointToLocal() { spec.element = static_cast(this); - spec.name = (mjString)&name; - spec.classname = (mjString)&classname; - spec.material = (mjString)&spec_material_; - spec.userdata = (mjDoubleVec)&spec_userdata_; - spec.info = (mjString)&info; + spec.name = &name; + spec.classname = &classname; + spec.material = &spec_material_; + spec.userdata = &spec_userdata_; + spec.info = &info; } @@ -4583,8 +4583,8 @@ void mjCTendon::CopyFromSpec() { *static_cast(this) = spec; material_ = spec_material_; userdata_ = spec_userdata_; - material = (mjString)&material_; - userdata = (mjDoubleVec)&userdata_; + material = &material_; + userdata = &userdata_; // clear precompiled for (int i=0; i(this); - spec.info = (mjString)&info; + spec.info = &info; } @@ -5041,15 +5041,15 @@ bool mjCActuator::is_actlimited() const { return islimited(actlimited, actrange) void mjCActuator::PointToLocal() { spec.element = static_cast(this); - spec.name = (mjString)&name; - spec.classname = (mjString)&classname; - spec.userdata = (mjDoubleVec)&spec_userdata_; - spec.target = (mjString)&spec_target_; - spec.refsite = (mjString)&spec_refsite_; - spec.slidersite = (mjString)&spec_slidersite_; - spec.plugin.name = (mjString)&plugin_name; - spec.plugin.instance_name = (mjString)&plugin_instance_name; - spec.info = (mjString)&info; + spec.name = &name; + spec.classname = &classname; + spec.userdata = &spec_userdata_; + spec.target = &spec_target_; + spec.refsite = &spec_refsite_; + spec.slidersite = &spec_slidersite_; + spec.plugin.name = &plugin_name; + spec.plugin.instance_name = &plugin_instance_name; + spec.info = &info; } @@ -5071,10 +5071,10 @@ void mjCActuator::CopyFromSpec() { target_ = spec_target_; refsite_ = spec_refsite_; slidersite_ = spec_slidersite_; - userdata = (mjDoubleVec)&userdata_; - target = (mjString)&target_; - refsite = (mjString)&refsite_; - slidersite = (mjString)&slidersite_; + userdata = &userdata_; + target = &target_; + refsite = &refsite_; + slidersite = &slidersite_; plugin.active = spec.plugin.active; plugin.instance = spec.plugin.instance; plugin.name = spec.plugin.name; @@ -5364,14 +5364,14 @@ mjCSensor& mjCSensor::operator=(const mjCSensor& other) { void mjCSensor::PointToLocal() { spec.element = static_cast(this); - spec.name = (mjString)&name; - spec.classname = (mjString)&classname; - spec.userdata = (mjDoubleVec)&spec_userdata_; - spec.objname = (mjString)&spec_objname_; - spec.refname = (mjString)&spec_refname_; - spec.plugin.name = (mjString)&plugin_name; - spec.plugin.instance_name = (mjString)&plugin_instance_name; - spec.info = (mjString)&info; + spec.name = &name; + spec.classname = &classname; + spec.userdata = &spec_userdata_; + spec.objname = &spec_objname_; + spec.refname = &spec_refname_; + spec.plugin.name = &plugin_name; + spec.plugin.instance_name = &plugin_instance_name; + spec.info = &info; } @@ -5391,9 +5391,9 @@ void mjCSensor::CopyFromSpec() { userdata_ = spec_userdata_; objname_ = spec_objname_; refname_ = spec_refname_; - userdata = (mjDoubleVec)&userdata_; - objname = (mjString)&objname_; - refname = (mjString)&refname_; + userdata = &userdata_; + objname = &objname_; + refname = &refname_; plugin.active = spec.plugin.active; plugin.instance = spec.plugin.instance; plugin.name = spec.plugin.name; @@ -5867,9 +5867,9 @@ mjCNumeric& mjCNumeric::operator=(const mjCNumeric& other) { void mjCNumeric::PointToLocal() { spec.element = static_cast(this); - spec.name = (mjString)&name; - spec.data = (mjDoubleVec)&spec_data_; - spec.info = (mjString)&info; + spec.name = &name; + spec.data = &spec_data_; + spec.info = &info; } @@ -5877,7 +5877,7 @@ void mjCNumeric::PointToLocal() { void mjCNumeric::CopyFromSpec() { *static_cast(this) = spec; data_ = spec_data_; - data = (mjDoubleVec)&data_; + data = &data_; } @@ -5956,9 +5956,9 @@ mjCText& mjCText::operator=(const mjCText& other) { void mjCText::PointToLocal() { spec.element = static_cast(this); - spec.name = (mjString)&name; - spec.data = (mjString)&spec_data_; - spec.info = (mjString)&info; + spec.name = &name; + spec.data = &spec_data_; + spec.info = &info; } @@ -5966,7 +5966,7 @@ void mjCText::PointToLocal() { void mjCText::CopyFromSpec() { *static_cast(this) = spec; data_ = spec_data_; - data = (mjString)&data_; + data = &data_; } @@ -6036,11 +6036,11 @@ mjCTuple& mjCTuple::operator=(const mjCTuple& other) { void mjCTuple::PointToLocal() { spec.element = static_cast(this); - spec.name = (mjString)&name; - spec.objtype = (mjIntVec)&spec_objtype_; - spec.objname = (mjStringVec)&spec_objname_; - spec.objprm = (mjDoubleVec)&spec_objprm_; - spec.info = (mjString)&info; + spec.name = &name; + spec.objtype = (mjIntVec*)&spec_objtype_; + spec.objname = &spec_objname_; + spec.objprm = &spec_objprm_; + spec.info = &info; } @@ -6061,9 +6061,9 @@ void mjCTuple::CopyFromSpec() { objtype_ = spec_objtype_; objname_ = spec_objname_; objprm_ = spec_objprm_; - objtype = (mjIntVec)&objtype_; - objname = (mjStringVec)&objname_; - objprm = (mjDoubleVec)&objprm_; + objtype = (mjIntVec*)&objtype_; + objname = &objname_; + objprm = &objprm_; } @@ -6171,14 +6171,14 @@ mjCKey& mjCKey::operator=(const mjCKey& other) { void mjCKey::PointToLocal() { spec.element = static_cast(this); - spec.name = (mjString)&name; - spec.qpos = (mjDoubleVec)&spec_qpos_; - spec.qvel = (mjDoubleVec)&spec_qvel_; - spec.act = (mjDoubleVec)&spec_act_; - spec.mpos = (mjDoubleVec)&spec_mpos_; - spec.mquat = (mjDoubleVec)&spec_mquat_; - spec.ctrl = (mjDoubleVec)&spec_ctrl_; - spec.info = (mjString)&info; + spec.name = &name; + spec.qpos = &spec_qpos_; + spec.qvel = &spec_qvel_; + spec.act = &spec_act_; + spec.mpos = &spec_mpos_; + spec.mquat = &spec_mquat_; + spec.ctrl = &spec_ctrl_; + spec.info = &info; } @@ -6191,12 +6191,12 @@ void mjCKey::CopyFromSpec() { mpos_ = spec_mpos_; mquat_ = spec_mquat_; ctrl_ = spec_ctrl_; - qpos = (mjDoubleVec)&qpos_; - qvel = (mjDoubleVec)&qvel_; - act = (mjDoubleVec)&act_; - mpos = (mjDoubleVec)&mpos_; - mquat = (mjDoubleVec)&mquat_; - ctrl = (mjDoubleVec)&ctrl_; + qpos = &qpos_; + qvel = &qvel_; + act = &act_; + mpos = &mpos_; + mquat = &mquat_; + ctrl = &ctrl_; } @@ -6314,9 +6314,9 @@ mjCPlugin::mjCPlugin(mjCModel* _model) { // public interface mjs_defaultPlugin(&spec); elemtype = mjOBJ_PLUGIN; - spec.name = (mjString)&name; - spec.instance_name = (mjString)&instance_name; - spec.info = (mjString)&info; + spec.name = &name; + spec.instance_name = &instance_name; + spec.info = &info; }