From a67e9370c89d105dc67eaf77aca86d5e90161628 Mon Sep 17 00:00:00 2001 From: Rainer Kartmann <rainer.kartmann@kit.edu> Date: Wed, 27 Oct 2021 09:26:29 +0200 Subject: [PATCH] Handle removed toJSON() --- source/armarx/navigation/core/CMakeLists.txt | 2 + source/armarx/navigation/core/Graph.cpp | 3 +- .../navigation/core/json_conversions.cpp | 45 +++++++++++++++++++ .../armarx/navigation/core/json_conversions.h | 36 +++++++++++++++ 4 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 source/armarx/navigation/core/json_conversions.cpp create mode 100644 source/armarx/navigation/core/json_conversions.h diff --git a/source/armarx/navigation/core/CMakeLists.txt b/source/armarx/navigation/core/CMakeLists.txt index c9b92d2c..d4eb4883 100644 --- a/source/armarx/navigation/core/CMakeLists.txt +++ b/source/armarx/navigation/core/CMakeLists.txt @@ -15,6 +15,7 @@ armarx_add_library(core types.cpp Graph.cpp aron_conversions.cpp + json_conversions.cpp time/ChronoMonotonicTimeServer.cpp HEADERS types.h @@ -27,6 +28,7 @@ armarx_add_library(core Graph.h TopologicScene.h aron_conversions.h + json_conversions.h time/ChronoMonotonicTimeServer.h time/TimeServerInterface.h DEPENDENCIES diff --git a/source/armarx/navigation/core/Graph.cpp b/source/armarx/navigation/core/Graph.cpp index c7cf378a..7bdd89ba 100644 --- a/source/armarx/navigation/core/Graph.cpp +++ b/source/armarx/navigation/core/Graph.cpp @@ -31,6 +31,7 @@ #include <RobotAPI/libraries/armem/core/wm/memory_definitions.h> #include <armarx/navigation/location/aron/Location.aron.generated.h> +#include <armarx/navigation/core/json_conversions.h> namespace armarx::navigation::core @@ -80,7 +81,7 @@ namespace armarx::navigation::core ss << " cost " << edge.attrib().cost() << ", type: " << static_cast<int>(edge.attrib().strategy) << " , has traj " - << edge.attrib().trajectory.has_value() << ", aron: " << edge.attrib().aron.toJSON(); + << edge.attrib().trajectory.has_value() << ", aron: " << nlohmann::json(edge.attrib().aron); return ss.str(); } diff --git a/source/armarx/navigation/core/json_conversions.cpp b/source/armarx/navigation/core/json_conversions.cpp new file mode 100644 index 00000000..30b8a70f --- /dev/null +++ b/source/armarx/navigation/core/json_conversions.cpp @@ -0,0 +1,45 @@ +/** + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "json_conversions.h" + +#include <RobotAPI/libraries/aron/core/data/rw/writer/nlohmannJSON/NlohmannJSONWriter.h> +#include <RobotAPI/libraries/aron/core/data/rw/reader/nlohmannJSON/NlohmannJSONReader.h> + + +namespace armarx::navigation::core +{ + + void arondto::to_json(nlohmann::json& j, const Edge& bo) + { + armarx::aron::data::writer::NlohmannJSONWriter writer; + j = bo.write(writer); + } + + + void arondto::from_json(const nlohmann::json& j, Edge& bo) + { + armarx::aron::data::reader::NlohmannJSONReader reader; + bo.read<armarx::aron::data::reader::NlohmannJSONReader::InputType>(reader, j); + } + + +} // namespace armarx::navigation::core diff --git a/source/armarx/navigation/core/json_conversions.h b/source/armarx/navigation/core/json_conversions.h new file mode 100644 index 00000000..57cee75d --- /dev/null +++ b/source/armarx/navigation/core/json_conversions.h @@ -0,0 +1,36 @@ +/** + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +#include <SimoxUtility/json/json.hpp> + +#include <armarx/navigation/core/aron/Graph.aron.generated.h> + + +namespace armarx::navigation::core::arondto +{ + + void to_json(nlohmann::json& j, const arondto::Edge& bo); + void from_json(const nlohmann::json& j, arondto::Edge& bo); + + +} // namespace armarx::navigation::graph -- GitLab