1 #ifndef PYDICTCONVERSION_H
2 #define PYDICTCONVERSION_H
6 #include <pybind11/pybind11.h>
7 #include <pybind11/stl.h>
8 #include <pybind11/eigen.h>
10 #include <boost/property_tree/ptree.hpp>
11 #include <boost/property_tree/json_parser.hpp>
16 inline void AddDictToPtree(pybind11::dict dict, std::string basePath, boost::property_tree::ptree &pt)
18 pybind11::object keys = pybind11::list(dict.attr(
"keys")());
19 std::vector<std::string> keysCpp = keys.cast<std::vector<std::string>>();
21 for(
auto& key : keysCpp){
24 if(pybind11::isinstance<pybind11::dict>(dict.attr(
"get")(key))){
28 }
else if(pybind11::isinstance<pybind11::list>(dict.attr(
"get")(key))){
30 for(
auto comp : pybind11::list(dict.attr(
"get")(key)))
31 val +=
"," + std::string(pybind11::str(comp));
32 pt.put(basePath + key, val.substr(1));
36 if( ((std::string)pybind11::str(dict.attr(
"get")(key))).compare(
"False")==0 ) {
37 pt.put(basePath + key,
false);
38 }
else if( ((std::string)pybind11::str(dict.attr(
"get")(key))).compare(
"True")==0 ) {
39 pt.put(basePath + key,
true);
41 pt.put(basePath + key, pybind11::str(dict.attr(
"get")(key)));
69 boost::property_tree::ptree pt;
void AddDictToPtree(pybind11::dict dict, std::string basePath, boost::property_tree::ptree &pt)
boost::property_tree::ptree ConvertDictToPtree(pybind11::dict dict)