Skip to content
Snippets Groups Projects
Commit 30875752 authored by Fabian Reister's avatar Fabian Reister
Browse files

new class NlohmannJSONReaderWithoutTypeCheck to read json files without type info

parent 832b2e7d
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
/*
* 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
/*
* 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment