3 #include <openrave/openrave.h>
5 #include "utils/logging.hpp"
7 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
9 class UserMap :
public std::map<std::string, OpenRAVE::UserDataPtr>,
public OpenRAVE::UserData {};
13 #if OPENRAVE_VERSION_MINOR > 8
14 inline OpenRAVE::UserDataPtr GetUserData(
const OpenRAVE::KinBody& body,
const std::string& key) {
15 return body.GetUserData(key);
17 inline void SetUserData(OpenRAVE::KinBody& body,
const std::string& key, OpenRAVE::UserDataPtr val) {
18 body.SetUserData(key, val);
20 inline void RemoveUserData(OpenRAVE::KinBody& body,
const std::string& key) {
21 body.RemoveUserData(key);
26 OpenRAVE::UserDataPtr GetUserData(
const T& env,
const std::string& key) {
27 OpenRAVE::UserDataPtr ud = env.GetUserData();
28 if (!ud)
return OpenRAVE::UserDataPtr();
29 else if (
UserMap* um = dynamic_cast<UserMap*>(ud.get())) {
30 UserMap::iterator it = (*um).find(key);
31 if (it != (*um).end())
return it->second;
32 else return OpenRAVE::UserDataPtr();
35 throw OpenRAVE::openrave_exception(
"Userdata has the wrong class!");
36 return OpenRAVE::UserDataPtr();
40 void SetUserData(T& env,
const std::string& key, OpenRAVE::UserDataPtr val) {
41 OpenRAVE::UserDataPtr ud = env.GetUserData();
43 ud = OpenRAVE::UserDataPtr(
new UserMap());
46 if (
UserMap* um = dynamic_cast<UserMap*>(ud.get())) {
50 throw OpenRAVE::openrave_exception(
"userdata has unexpected class");
54 void RemoveUserData(T& body,
const std::string& key) {
55 OpenRAVE::UserDataPtr ud = body.GetUserData();
56 if (
UserMap* um = dynamic_cast<UserMap*>(ud.get())) {
57 if (um->find(key) == um->end()) LOG_WARN(
"tried to erase key %s but it's not in the userdata map!", key.c_str());
61 LOG_ERROR(
"body %s has no userdata map", body.GetName().c_str());