From 52fe8cb900761682c80a271fd42cf6bb70042247 Mon Sep 17 00:00:00 2001 From: Taiju Yamada Date: Mon, 21 Mar 2022 15:57:20 +0900 Subject: [PATCH 1/2] able to get inner content by utilizing GetJsonValueByPath --- include/mujincontrollerclient/mujincontrollerclient.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/mujincontrollerclient/mujincontrollerclient.h b/include/mujincontrollerclient/mujincontrollerclient.h index 55aead94..dc8581ab 100644 --- a/include/mujincontrollerclient/mujincontrollerclient.h +++ b/include/mujincontrollerclient/mujincontrollerclient.h @@ -696,8 +696,14 @@ class MUJINCLIENT_API WebResource template inline T Get(const std::string& field, double timeout = 5.0) { rapidjson::Document pt(rapidjson::kObjectType); - GetWrap(pt, field, timeout); - return mujinjson_external::GetJsonValueByKey(pt, field.c_str()); + std::string path = field; + if(path[0]!='/') { + path = std::string("/")+field; + } + std::string fieldToConstraint = path.substr(1); + fieldToConstraint = fieldToConstraint.substr(0, fieldToConstraint.find('/')); + GetWrap(pt, fieldToConstraint, timeout); + return mujinjson_external::GetJsonValueByPath(pt, path.c_str()); } /// \brief sets an attribute of this web resource From 813c258ee02d652feddb697b04aac636a62c758a Mon Sep 17 00:00:00 2001 From: Taiju Yamada Date: Wed, 2 Nov 2022 15:35:51 +0900 Subject: [PATCH 2/2] separate to GetPath method --- .../mujincontrollerclient.h | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/include/mujincontrollerclient/mujincontrollerclient.h b/include/mujincontrollerclient/mujincontrollerclient.h index dc8581ab..6f8ceb3e 100644 --- a/include/mujincontrollerclient/mujincontrollerclient.h +++ b/include/mujincontrollerclient/mujincontrollerclient.h @@ -694,18 +694,21 @@ class MUJINCLIENT_API WebResource /// \brief gets an attribute of this web resource template - inline T Get(const std::string& field, double timeout = 5.0) { + inline T GetPath(const std::string& path, double timeout = 5.0) { rapidjson::Document pt(rapidjson::kObjectType); - std::string path = field; - if(path[0]!='/') { - path = std::string("/")+field; - } - std::string fieldToConstraint = path.substr(1); - fieldToConstraint = fieldToConstraint.substr(0, fieldToConstraint.find('/')); - GetWrap(pt, fieldToConstraint, timeout); + std::string fieldToConstraintForCallGet = path.substr(1, path.find('/', 1)); + GetWrap(pt, fieldToConstraintForCallGet, timeout); return mujinjson_external::GetJsonValueByPath(pt, path.c_str()); } + /// \brief gets an attribute of this web resource + template + inline T Get(const std::string& field, double timeout = 5.0) { + rapidjson::Document pt(rapidjson::kObjectType); + GetWrap(pt, field, timeout); + return mujinjson_external::GetJsonValueByKey(pt, field.c_str()); + } + /// \brief sets an attribute of this web resource virtual void Set(const std::string& field, const std::string& newvalue, double timeout = 5.0);