diff --git a/source/RobotAPI/libraries/aron/core/CMakeLists.txt b/source/RobotAPI/libraries/aron/core/CMakeLists.txt index 1c4ae2923cb0d24f57fd5fda32524d6b5100eefe..1f6fb1582f3af4a98ba739a9621bd6db7988e160 100644 --- a/source/RobotAPI/libraries/aron/core/CMakeLists.txt +++ b/source/RobotAPI/libraries/aron/core/CMakeLists.txt @@ -73,6 +73,7 @@ set(LIB_FILES data/rw/Reader.cpp data/rw/reader/variant/VariantReader.cpp data/rw/reader/nlohmannJSON/NlohmannJSONReader.cpp + data/rw/reader/nlohmannJSON/NlohmannJSONReaderWithoutTypeCheck.cpp type/rw/Writer.cpp type/rw/writer/variant/VariantWriter.cpp @@ -211,6 +212,7 @@ set(LIB_HEADERS data/rw/Reader.h data/rw/reader/variant/VariantReader.h data/rw/reader/nlohmannJSON/NlohmannJSONReader.h + data/rw/reader/nlohmannJSON/NlohmannJSONReaderWithoutTypeCheck.h type/rw/json/Data.h diff --git a/source/RobotAPI/libraries/aron/core/data/rw/reader/nlohmannJSON/NlohmannJSONReaderWithoutTypeCheck.cpp b/source/RobotAPI/libraries/aron/core/data/rw/reader/nlohmannJSON/NlohmannJSONReaderWithoutTypeCheck.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e773c517d9ceee0c8c166f327b639a2c8f799f6b --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/data/rw/reader/nlohmannJSON/NlohmannJSONReaderWithoutTypeCheck.cpp @@ -0,0 +1,107 @@ +/* +* 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 Fabian Peller (fabian dot peller at kit dot edu) +* @copyright http://www.gnu.org/licenses/gpl-2.0.txt +* GNU General Public License +*/ + +// STD/STL +#include <memory> +#include <numeric> + +// Header +#include "NlohmannJSONReaderWithoutTypeCheck.h" + +// ArmarX +#include <RobotAPI/libraries/aron/core/Exception.h> +#include <RobotAPI/libraries/aron/core/data/visitor/nlohmannJSON/NlohmannJSONVisitor.h> + +#include "../../json/Data.h" + + +namespace armarx::aron::data::reader +{ + data::Descriptor + NlohmannJSONReaderWithoutTypeCheck::getDescriptor(InputType& input) + { + return ConstNlohmannJSONVisitor::GetDescriptor(input); + } + + void + NlohmannJSONReaderWithoutTypeCheck::readList(const nlohmann::json& input, + std::vector<nlohmann::json>& elements, + Path& p) + { + elements = input.get<std::vector<nlohmann::json>>(); + } + + void + NlohmannJSONReaderWithoutTypeCheck::readDict(const nlohmann::json& input, + std::map<std::string, nlohmann::json>& elements, + Path& p) + { + elements = input.get<std::map<std::string, nlohmann::json>>(); + } + + void + NlohmannJSONReaderWithoutTypeCheck::readNDArray(const nlohmann::json& input, + std::vector<int>& shape, + std::string& typeAsString, + std::vector<unsigned char>& data, + Path& p) + { + shape = input.at("dims").get<std::vector<int>>(); + data = input.at("data").get<std::vector<unsigned char>>(); + } + + void + NlohmannJSONReaderWithoutTypeCheck::readInt(const nlohmann::json& input, int& i, Path& p) + { + i = input; + } + + void + NlohmannJSONReaderWithoutTypeCheck::readLong(const nlohmann::json& input, long& i, Path& p) + { + i = input; + } + + void + NlohmannJSONReaderWithoutTypeCheck::readFloat(const nlohmann::json& input, float& i, Path& p) + { + i = input; + } + + void + NlohmannJSONReaderWithoutTypeCheck::readDouble(const nlohmann::json& input, double& i, Path& p) + { + i = input; + } + + void + NlohmannJSONReaderWithoutTypeCheck::readString(const nlohmann::json& input, + std::string& i, + Path& p) + { + i = input; + } + + void + NlohmannJSONReaderWithoutTypeCheck::readBool(const nlohmann::json& input, bool& i, Path& p) + { + i = input; + } +} // namespace armarx::aron::data::reader diff --git a/source/RobotAPI/libraries/aron/core/data/rw/reader/nlohmannJSON/NlohmannJSONReaderWithoutTypeCheck.h b/source/RobotAPI/libraries/aron/core/data/rw/reader/nlohmannJSON/NlohmannJSONReaderWithoutTypeCheck.h new file mode 100644 index 0000000000000000000000000000000000000000..e0bed7b71869e2abc074484fe3fb9774e0ef6730 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/data/rw/reader/nlohmannJSON/NlohmannJSONReaderWithoutTypeCheck.h @@ -0,0 +1,73 @@ +/* +* 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 Fabian Peller (fabian dot peller at kit dot edu) +* @copyright http://www.gnu.org/licenses/gpl-2.0.txt +* GNU General Public License +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <stack> + +// Simox +#include <SimoxUtility/json.h> + +// BaseClass +#include <RobotAPI/libraries/aron/core/data/rw/Reader.h> + +namespace armarx::aron::data::reader +{ + class NlohmannJSONReaderWithoutTypeCheck : public ReaderInterface<const nlohmann::json> + { + using Base = ReaderInterface<const nlohmann::json>; + + public: + // constructors + NlohmannJSONReaderWithoutTypeCheck() = default; + + data::Descriptor getDescriptor(InputType& input) final; + + using Base::readBool; + using Base::readDict; + using Base::readDouble; + using Base::readFloat; + using Base::readInt; + using Base::readList; + using Base::readLong; + using Base::readNDArray; + using Base::readString; + + void readList(InputType& input, std::vector<InputTypeNonConst>& elements, Path& p) override; + void readDict(InputType& input, + std::map<std::string, InputTypeNonConst>& elements, + Path& p) override; + + void readNDArray(InputType& input, + std::vector<int>& shape, + std::string& typeAsString, + std::vector<unsigned char>& data, + Path& p) override; + + void readInt(InputType& input, int& i, Path& p) override; + void readLong(InputType& input, long& i, Path& p) override; + void readFloat(InputType& input, float& i, Path& p) override; + void readDouble(InputType& input, double& i, Path& p) override; + void readString(InputType& input, std::string& i, Path& p) override; + void readBool(InputType& input, bool& i, Path& p) override; + }; +} // namespace armarx::aron::data::reader