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

NlohmannJSONReader: using .at() instead of bracket operator

parent 30875752
No related branches found
No related tags found
No related merge requests found
......@@ -39,13 +39,13 @@ namespace armarx::aron::data::reader
void getAronMetaInformationForType(const nlohmann::json& input, const std::string& expectedType, Path& p)
{
// check type
if (input[rw::json::constantes::TYPE_SLUG] != expectedType)
if (input.at(rw::json::constantes::TYPE_SLUG) != expectedType)
{
throw error::ValueNotValidException(__PRETTY_FUNCTION__, "Wrong type in json encountered.", input[rw::json::constantes::TYPE_SLUG], expectedType);
throw error::ValueNotValidException(__PRETTY_FUNCTION__, "Wrong type in json encountered.", input.at(rw::json::constantes::TYPE_SLUG), expectedType);
}
// set path
std::vector<std::string> pathElements = input[rw::json::constantes::PATH_SLUG];
std::vector<std::string> pathElements = input.at(rw::json::constantes::PATH_SLUG);
p = Path(pathElements);
}
}
......@@ -58,56 +58,56 @@ namespace armarx::aron::data::reader
void NlohmannJSONReader::readList(const nlohmann::json& input, std::vector<nlohmann::json>& elements, Path& p)
{
getAronMetaInformationForType(input, rw::json::constantes::LIST_TYPENAME_SLUG, p);
elements = input[rw::json::constantes::ELEMENTS_SLUG].get<std::vector<nlohmann::json>>();
elements = input.at(rw::json::constantes::ELEMENTS_SLUG).get<std::vector<nlohmann::json>>();
}
void NlohmannJSONReader::readDict(const nlohmann::json& input, std::map<std::string, nlohmann::json>& elements, Path& p)
{
getAronMetaInformationForType(input, rw::json::constantes::DICT_TYPENAME_SLUG, p);
elements = input[rw::json::constantes::ELEMENTS_SLUG].get<std::map<std::string, nlohmann::json>>();
elements = input.at(rw::json::constantes::ELEMENTS_SLUG).get<std::map<std::string, nlohmann::json>>();
}
void NlohmannJSONReader::readNDArray(const nlohmann::json& input, std::vector<int>& shape, std::string& typeAsString, std::vector<unsigned char>& data, Path& p)
{
getAronMetaInformationForType(input, rw::json::constantes::NDARRAY_TYPENAME_SLUG, p);
shape = input[rw::json::constantes::DIMENSIONS_SLUG].get<std::vector<int>>();
typeAsString = input[rw::json::constantes::USED_TYPE_SLUG];
data = input[rw::json::constantes::DATA_SLUG].get<std::vector<unsigned char>>();
shape = input.at(rw::json::constantes::DIMENSIONS_SLUG).get<std::vector<int>>();
typeAsString = input.at(rw::json::constantes::USED_TYPE_SLUG);
data = input.at(rw::json::constantes::DATA_SLUG).get<std::vector<unsigned char>>();
}
void NlohmannJSONReader::readInt(const nlohmann::json& input, int& i, Path& p)
{
getAronMetaInformationForType(input, rw::json::constantes::INT_TYPENAME_SLUG, p);
i = input[rw::json::constantes::VALUE_SLUG];
i = input.at(rw::json::constantes::VALUE_SLUG);
}
void NlohmannJSONReader::readLong(const nlohmann::json& input, long& i, Path& p)
{
getAronMetaInformationForType(input, rw::json::constantes::LONG_TYPENAME_SLUG, p);
i = input[rw::json::constantes::VALUE_SLUG];
i = input.at(rw::json::constantes::VALUE_SLUG);
}
void NlohmannJSONReader::readFloat(const nlohmann::json& input, float& i, Path& p)
{
getAronMetaInformationForType(input, rw::json::constantes::FLOAT_TYPENAME_SLUG, p);
i = input[rw::json::constantes::VALUE_SLUG];
i = input.at(rw::json::constantes::VALUE_SLUG);
}
void NlohmannJSONReader::readDouble(const nlohmann::json& input, double& i, Path& p)
{
getAronMetaInformationForType(input, rw::json::constantes::DOUBLE_TYPENAME_SLUG, p);
i = input[rw::json::constantes::VALUE_SLUG];
i = input.at(rw::json::constantes::VALUE_SLUG);
}
void NlohmannJSONReader::readString(const nlohmann::json& input, std::string& i, Path& p)
{
getAronMetaInformationForType(input, rw::json::constantes::STRING_TYPENAME_SLUG, p);
i = input[rw::json::constantes::VALUE_SLUG];
i = input.at(rw::json::constantes::VALUE_SLUG);
}
void NlohmannJSONReader::readBool(const nlohmann::json& input, bool& i, Path& p)
{
getAronMetaInformationForType(input, rw::json::constantes::BOOL_TYPENAME_SLUG, p);
i = input[rw::json::constantes::VALUE_SLUG];
i = input.at(rw::json::constantes::VALUE_SLUG);
}
}
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