MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / toJson

Method toJson

src/json_export.cpp:12–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10}
11
12bool JsonExporter::toJson(const Any& any, nlohmann::json& dst) const
13{
14 auto const& type = any.castedType();
15
16 if(any.isString())
17 {
18 dst = any.cast<std::string>();
19 }
20 else if(type == typeid(int64_t))
21 {
22 dst = any.cast<int64_t>();
23 }
24 else if(type == typeid(uint64_t))
25 {
26 dst = any.cast<uint64_t>();
27 }
28 else if(type == typeid(double))
29 {
30 dst = any.cast<double>();
31 }
32 else if(type == typeid(std::vector<double>))
33 {
34 dst = any.cast<std::vector<double>>();
35 }
36 else if(type == typeid(std::vector<int>))
37 {
38 dst = any.cast<std::vector<int>>();
39 }
40 else if(type == typeid(std::vector<std::string>))
41 {
42 dst = any.cast<std::vector<std::string>>();
43 }
44 else if(type == typeid(std::vector<bool>))
45 {
46 dst = any.cast<std::vector<bool>>();
47 }
48 else
49 {
50 auto it = to_json_converters_.find(type);
51 if(it != to_json_converters_.end())
52 {
53 it->second(any, dst);
54 }
55 else
56 {
57 return false;
58 }
59 }
60 return true;
61}
62
63JsonExporter::ExpectedEntry JsonExporter::fromJson(const nlohmann::json& source) const
64{

Callers 4

toJsonStringFunction · 0.80
ExportBlackboardToJSONFunction · 0.80
TESTFunction · 0.80
TEST_FFunction · 0.80

Calls 2

isStringMethod · 0.80
endMethod · 0.45

Tested by 2

TESTFunction · 0.64
TEST_FFunction · 0.64