@@ -118,7 +118,6 @@ class JsonExporter
118118
119119 std::unordered_map<std::type_index, ToJonConverter> to_json_converters_;
120120 std::unordered_map<std::type_index, FromJonConverter> from_json_converters_;
121- std::unordered_map<std::type_index, FromJonConverter> from_json_array_converters_;
122121 std::unordered_map<std::string, BT::TypeInfo> type_names_;
123122};
124123
@@ -143,15 +142,6 @@ inline Expected<T> JsonExporter::fromJson(const nlohmann::json& source) const
143142template <typename T>
144143inline void JsonExporter::addConverter ()
145144{
146- // we need to get the name of the type
147- nlohmann::json const js = T{};
148- // we insert both the name obtained from JSON and demangle
149- if (js.contains (" __type" ))
150- {
151- type_names_.insert ({ std::string (js[" __type" ]), BT::TypeInfo::Create<T>() });
152- }
153- type_names_.insert ({ BT::demangle (typeid (T)), BT::TypeInfo::Create<T>() });
154-
155145 ToJonConverter to_converter = [](const BT::Any& entry, nlohmann::json& dst) {
156146 dst = *const_cast <BT::Any&>(entry).castPtr <T>();
157147 };
@@ -162,23 +152,16 @@ inline void JsonExporter::addConverter()
162152 return { BT::Any (value), BT::TypeInfo::Create<T>() };
163153 };
164154
165- from_json_converters_.insert ({ typeid (T), from_converter });
166-
167- // ---- include vectors of T
168- ToJonConverter to_array_converter = [](const BT::Any& entry, nlohmann::json& dst) {
169- dst = *const_cast <BT::Any&>(entry).castPtr <std::vector<T>>();
170- };
171- to_json_converters_.insert ({ typeid (std::vector<T>), to_array_converter });
155+ // we need to get the name of the type
156+ nlohmann::json const js = T{};
157+ // we insert both the name obtained from JSON and demangle
158+ if (js.contains (" __type" ))
159+ {
160+ type_names_.insert ({ std::string (js[" __type" ]), BT::TypeInfo::Create<T>() });
161+ }
162+ type_names_.insert ({ BT::demangle (typeid (T)), BT::TypeInfo::Create<T>() });
172163
173- FromJonConverter from_array_converter = [](const nlohmann::json& src) -> Entry {
174- std::vector<T> value;
175- for (const auto & item : src)
176- {
177- value.push_back (item.get <T>());
178- }
179- return { BT::Any (value), BT::TypeInfo::Create<std::vector<T>>() };
180- };
181- from_json_array_converters_.insert ({ typeid (T), from_array_converter });
164+ from_json_converters_.insert ({ typeid (T), from_converter });
182165}
183166
184167template <typename T>
@@ -193,18 +176,6 @@ inline void JsonExporter::addConverter(
193176 }
194177 };
195178 to_json_converters_.insert ({ typeid (T), std::move (converter) });
196- // ---------------------------------------------
197- // add the vector<T> converter
198- auto vector_converter = [converter](const BT::Any& entry, nlohmann::json& json) {
199- auto & vec = *const_cast <BT::Any&>(entry).castPtr <std::vector<T>>();
200- for (const auto & item : vec)
201- {
202- nlohmann::json item_json;
203- converter (BT::Any (item), item_json);
204- json.push_back (item_json);
205- }
206- };
207- to_json_converters_.insert ({ typeid (std::vector<T>), std::move (vector_converter) });
208179}
209180
210181template <typename T>
@@ -218,19 +189,6 @@ JsonExporter::addConverter(std::function<void(const nlohmann::json&, T&)> func)
218189 };
219190 type_names_.insert ({ BT::demangle (typeid (T)), BT::TypeInfo::Create<T>() });
220191 from_json_converters_.insert ({ typeid (T), std::move (converter) });
221- // ---------------------------------------------
222- // add the vector<T> converter
223- auto vector_converter = [func](const nlohmann::json& json) -> Entry {
224- std::vector<T> tmp;
225- for (const auto & item : json)
226- {
227- T item_tmp;
228- func (item, item_tmp);
229- tmp.push_back (item_tmp);
230- }
231- return { BT::Any (tmp), BT::TypeInfo::Create<std::vector<T>>() };
232- };
233- from_json_array_converters_.insert ({ typeid (T), std::move (vector_converter) });
234192}
235193
236194template <typename T>
0 commit comments