Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions include/mujincontrollerclient/mujincontrollerclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -696,8 +696,14 @@ class MUJINCLIENT_API WebResource
template<class T>
inline T Get(const std::string& field, double timeout = 5.0) {
rapidjson::Document pt(rapidjson::kObjectType);
GetWrap(pt, field, timeout);
return mujinjson_external::GetJsonValueByKey<T>(pt, field.c_str());
std::string path = field;
if(path[0]!='/') {
path = std::string("/")+field;
}
std::string fieldToConstraint = path.substr(1);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cielavenir looks pretty inefficient with creating all these strings on the heap, especially when rapidjson doesn't require std::string

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, alternative ideas are:

  1. use GetJsonValueByPath only when field contains "/"
  2. add a new API named GetPath

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added GetPath now

fieldToConstraint = fieldToConstraint.substr(0, fieldToConstraint.find('/'));
GetWrap(pt, fieldToConstraint, timeout);
return mujinjson_external::GetJsonValueByPath<T>(pt, path.c_str());
}

/// \brief sets an attribute of this web resource
Expand Down