#pragma once #include #include #include #include #include #include void serialize(std::ostream& os, const std::string& str); template::value, int>::type = 0> void serialize(std::ostream& os, T intVal) { os << intVal; } template void serialize(std::ostream& os, const std::vector& vec) { os << "["; if (vec.size() > 0) { serialize(os, vec[0]); std::for_each(std::begin(vec) + 1, std::end(vec), [&os](const auto& el) { os << ','; serialize(os, el); }); } os << "]"; } template void serialize(std::ostream& os, const std::set& setVal) { bool first = true; os << "["; std::for_each(std::begin(setVal), std::end(setVal), [&os, &first](const auto& el) { if (!first) { os << ','; } serialize(os, el); first = false; }); os << "]"; } template void serialize(std::ostream& os, const std::map& m) { bool first = true; os << "{"; std::for_each(std::begin(m), std::end(m), [&os, &first](const auto& pair) { if (!first) { os << ','; } serialize(os, pair.first); os << ':'; serialize(os, pair.second); first = false; }); os << "}"; } void deserialize(const boost::property_tree::ptree& tree, std::string& stringVal); template::value, int>::type = 0> void deserialize(const boost::property_tree::ptree & tree, T& intVal) { intVal = tree.get_value(); } template void deserialize(const boost::property_tree::ptree& tree, std::vector& vec) { vec.clear(); for (const boost::property_tree::ptree::value_type &el : tree) { // el.first contain the string "" if it was JSON array T val; deserialize(el.second, val); vec.push_back(std::move(val)); } } template void deserialize(const boost::property_tree::ptree& tree, std::set& setVal) { setVal.clear(); for (const boost::property_tree::ptree::value_type &el : tree) { // el.first contain the string "" if it was JSON array T val; deserialize(el.second, val); setVal.insert(std::move(val)); } } template void deserialize(const boost::property_tree::ptree& tree, std::map& mapVal) { mapVal.clear(); for (const boost::property_tree::ptree::value_type &el : tree) { std::string key; T val; key = el.first; deserialize(el.second, val); mapVal.insert(std::make_pair(std::move(key), std::move(val))); } }