63 using Entry = std::pair<BT::Any, BT::TypeInfo>;
96 bool add_type =
true);
111 template <
typename T>
117 return nonstd::expected_lite::make_unexpected(res.error());
119 auto casted = res->first.tryCast<T>();
122 return nonstd::expected_lite::make_unexpected(casted.error());
129 template <
typename T>
133 dst = *
const_cast<BT::Any&
>(entry).castPtr<T>();
138 T value = src.get<T>();
139 return {
BT::Any(value), BT::TypeInfo::Create<T>() };
145 if(js.contains(
"__type"))
147 type_names_.insert({ std::string(js[
"__type"]), BT::TypeInfo::Create<T>() });
154 template <
typename T>
156 std::function<
void(
const T&,
nlohmann::json&)> func,
bool add_type)
159 func(entry.cast<T>(),
json);
168 template <
typename T>
175 return {
BT::Any(tmp), BT::TypeInfo::Create<T>() };
181 template <
typename T>
195 #define BT_JSON_CONVERTER(Type, value) \
196 template <class AddField> \
197 void _JsonTypeDefinition(Type&, AddField&); \
199 inline void to_json(nlohmann::json& js, const Type& p) \
201 auto op = [&js](const char* name, auto* val) { js[name] = *val; }; \
202 _JsonTypeDefinition(const_cast<Type&>(p), op); \
203 js["__type"] = #Type; \
206 inline void from_json(const nlohmann::json& js, Type& p) \
208 auto op = [&js](const char* name, auto* v) { js.at(name).get_to(*v); }; \
209 _JsonTypeDefinition(p, op); \
212 template <class AddField> \
213 inline void _JsonTypeDefinition(Type& value, AddField& add_field)