4 #include <boost/format.hpp>
10 namespace json_marshal {
12 TRAJOPT_API
void fromJson(
const Json::Value& v,
bool& ref);
13 TRAJOPT_API
void fromJson(
const Json::Value& v,
int& ref);
14 TRAJOPT_API
void fromJson(
const Json::Value& v,
double& ref);
15 TRAJOPT_API
void fromJson(
const Json::Value& v, std::string& ref);
17 inline void fromJson(
const Json::Value& v, T& ref) {
21 void fromJsonArray(
const Json::Value& parent, std::vector<T>& ref) {
23 ref.reserve(parent.size());
24 for (Json::Value::const_iterator it = parent.begin(); it != parent.end(); ++it) {
31 void fromJsonArray(
const Json::Value& parent, std::vector<T>& ref,
int size) {
32 if (parent.size() != size) {
33 PRINT_AND_THROW(boost::format(
"expected list of size size %i. got: %s\n")%size%parent);
36 fromJsonArray(parent, ref);
40 inline void fromJson(
const Json::Value& v, std::vector<T>& ref) {
41 fromJsonArray(v, ref);
45 void childFromJson(
const Json::Value& parent, T& ref,
const char* name,
const T& df) {
46 if (parent.isMember(name)) {
47 const Json::Value& v = parent[name];
55 void childFromJson(
const Json::Value& parent, T& ref,
const char* name) {
56 if (parent.isMember(name)) {
57 const Json::Value& v = parent[name];
61 PRINT_AND_THROW(boost::format(
"missing field: %s")%name);