Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

able to get inner content by utilizing GetJsonValueByPath #115

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
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
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
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