Skip to content
Snippets Groups Projects
Commit d2aaf580 authored by Raphael Grimm's avatar Raphael Grimm
Browse files

Add VirtualRobot::json::json2NameValueMap

parent 01eb6e36
No related branches found
No related tags found
No related merge requests found
#include <boost/lexical_cast.hpp>
#include <VirtualRobot/MathTools.h>
#include "converters.h"
namespace VirtualRobot::json
{
Eigen::Matrix4f posquat2eigen4f(const std::string& str)
......@@ -83,4 +84,26 @@ namespace VirtualRobot::json
}
return jar.dump(4);
}
std::map<std::string, float> json2NameValueMap(const std::string& str)
{
return json2NameValueMap(::nlohmann::json::parse(str));
}
std::map<std::string, float> json2NameValueMap(const char* str)
{
return json2NameValueMap(::nlohmann::json::parse(str));
}
std::map<std::string, float> json2NameValueMap(const nlohmann::json& j)
{
if (!j.is_object())
{
throw std::invalid_argument{"json2NameValueMap: json has to be an object"};
}
std::map<std::string, float> result;
for (const auto& el : j.items())
{
result[el.key()] = boost::lexical_cast<float>(el.value());
}
return result;
}
}
#pragma once
#include <map>
#include <string>
#include <Eigen/Core>
#include "json.hpp"
......@@ -17,4 +20,8 @@ namespace VirtualRobot::json
std::string eigen4f2posquatJson(const Eigen::Matrix4f& str);
std::string eigen4fVector2posquatArrayJson(const std::vector<Eigen::Matrix4f>& str);
std::map<std::string, float> json2NameValueMap(const std::string& str);
std::map<std::string, float> json2NameValueMap(const char* str);
std::map<std::string, float> json2NameValueMap(const nlohmann::json& j);
}
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