NLohmannJSONConverter.cpp
Go to the documentation of this file.
2 
4 
6 
8 {
9  nlohmann::json
11  {
12  nlohmann::json j;
13  ConvertToNlohmannJSON(aron, j);
14  return j;
15  }
16 
17  void
19  nlohmann::json& j)
20  {
21  j = aron::data::readAndWrite<ToNLohmannJSONConverterVisitor>(aron);
22  }
23 
26  const armarx::aron::Path& p)
27  {
28  // TODO Switch case over json type and add other methods, e.g. for float, array, ...
29  // TODO add check if json is object_t
30  data::VariantPtr aron = std::make_shared<aron::data::Dict>(p);
31  ConvertFromNlohmannJSON(aron, j);
33  }
34 
35  void
38  const nlohmann::json& e,
39  const aron::type::VariantPtr& expectedStructure)
40  {
41  a = aron::data::readAndWrite<FromNLohmannJSONConverterVisitor>(e);
42  ARMARX_CHECK_EXPRESSION(a->fullfillsType(expectedStructure));
43  }
44 
45 } // namespace armarx::aron::data::converter
46 
48 {
49 
50  nlohmann::json
51  AronNlohmannJSONConverter::ConvertToNlohmannJSON(const type::VariantPtr& aron)
52  {
53  nlohmann::json j;
54  ConvertToNlohmannJSON(aron, j);
55  return j;
56  }
57 
58  void
59  AronNlohmannJSONConverter::ConvertToNlohmannJSON(const aron::type::VariantPtr& aron,
60  nlohmann::json& j)
61  {
62  j = aron::type::readAndWrite<ToNLohmannJSONConverterVisitor>(aron);
63  }
64 
66  AronNlohmannJSONConverter::ConvertFromNlohmannJSONTypeObject(const nlohmann::json& j,
67  const armarx::aron::Path& p)
68  {
69  type::VariantPtr aron = std::make_shared<aron::type::Object>(p);
70  ConvertFromNlohmannJSON(aron, j);
72  }
73 
74  void
75  AronNlohmannJSONConverter::ConvertFromNlohmannJSON(aron::type::VariantPtr& a,
76  const nlohmann::json& e)
77  {
78  a = aron::type::readAndWrite<FromNLohmannJSONConverterVisitor>(e);
79  }
80 } // namespace armarx::aron::type::converter
NLohmannJSONConverterVisitor.h
armarx::aron::type::VariantPtr
std::shared_ptr< Variant > VariantPtr
Definition: forward_declarations.h:11
armarx::aron::data::converter::AronNlohmannJSONConverter::ConvertToNlohmannJSON
static nlohmann::json ConvertToNlohmannJSON(const data::VariantPtr &)
Definition: NLohmannJSONConverter.cpp:10
armarx::aron::data::converter::AronNlohmannJSONConverter::ConvertFromNlohmannJSONObject
static data::DictPtr ConvertFromNlohmannJSONObject(const nlohmann::json &, const armarx::aron::Path &p={})
Definition: NLohmannJSONConverter.cpp:25
armarx::aron::data::detail::SpecializedVariantBase< data::dto::Dict, Dict >::DynamicCastAndCheck
static PointerType DynamicCastAndCheck(const VariantPtr &n)
Definition: SpecializedVariant.h:135
NLohmannJSONConverter.h
armarx::aron::Path
The Path class.
Definition: Path.h:36
armarx::aron::data::VariantPtr
std::shared_ptr< Variant > VariantPtr
Definition: forward_declarations.h:11
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
armarx::aron::type::converter
Definition: aron_conversions.cpp:9
armarx::aron::data::DictPtr
std::shared_ptr< Dict > DictPtr
Definition: Dict.h:41
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
armarx::aron::type::detail::SpecializedVariantBase< type::dto::AronObject, Object >::DynamicCastAndCheck
static std::shared_ptr< Object > DynamicCastAndCheck(const VariantPtr &n)
Definition: SpecializedVariant.h:124
armarx::aron::data::converter::AronNlohmannJSONConverter::ConvertFromNlohmannJSON
static void ConvertFromNlohmannJSON(data::VariantPtr &, const nlohmann::json &, const aron::type::VariantPtr &=nullptr)
Definition: NLohmannJSONConverter.cpp:36
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
Logging.h
armarx::aron::data::converter
Definition: aron_conversions.cpp:3