|
2 | 2 |
|
3 | 3 | #include "behaviortree_cpp/utils/safe_any.hpp" |
4 | 4 | #include "behaviortree_cpp/basic_types.h" |
5 | | - |
6 | 5 | // Use the version nlohmann::json embedded in BT.CPP |
7 | 6 | #include "behaviortree_cpp/contrib/json.hpp" |
8 | 7 |
|
| 8 | +#ifdef BTCPP_PYTHON |
| 9 | +#include <pybind11/pybind11.h> |
| 10 | +#include <pybind11/pytypes.h> |
| 11 | +#include "behaviortree_cpp/contrib/pybind11_json.hpp" |
| 12 | +#endif |
| 13 | + |
9 | 14 | namespace BT |
10 | 15 | { |
11 | 16 |
|
@@ -82,14 +87,11 @@ class JsonExporter |
82 | 87 | template <typename T> |
83 | 88 | Expected<T> fromJson(const nlohmann::json& source) const; |
84 | 89 |
|
85 | | - template <typename T> |
86 | | - void fromJsonHelper(const nlohmann::json& src, T& dst) const |
87 | | - { |
88 | | - dst = *fromJson<T>(src); |
89 | | - } |
90 | | - |
91 | | - /// Register new JSON converters with addConverter<Foo>(). |
92 | | - /// You should have used first the macro BT_JSON_CONVERTER |
| 90 | + /** |
| 91 | + * @brief Register new JSON converters with addConverter<Foo>(). |
| 92 | + * You should used first the macro BT_JSON_CONVERTER. |
| 93 | + * The conversions from/to vector<T> are automatically registered. |
| 94 | + */ |
93 | 95 | template <typename T> |
94 | 96 | void addConverter(); |
95 | 97 |
|
@@ -121,7 +123,14 @@ class JsonExporter |
121 | 123 | std::unordered_map<std::type_index, FromJonConverter> from_json_converters_; |
122 | 124 | std::unordered_map<std::string, BT::TypeInfo> type_names_; |
123 | 125 | }; |
124 | | - |
| 126 | +#ifdef BTCPP_PYTHON |
| 127 | +template <> |
| 128 | +inline Expected<pybind11::object> |
| 129 | +JsonExporter::fromJson(const nlohmann::json& source) const |
| 130 | +{ |
| 131 | + return pyjson::from_json(source); |
| 132 | +} |
| 133 | +#endif |
125 | 134 | template <typename T> |
126 | 135 | inline Expected<T> JsonExporter::fromJson(const nlohmann::json& source) const |
127 | 136 | { |
|
0 commit comments