Skip to content

Instantly share code, notes, and snippets.

@ignisan
Created February 11, 2014 13:01
Show Gist options
  • Save ignisan/8934426 to your computer and use it in GitHub Desktop.
Save ignisan/8934426 to your computer and use it in GitHub Desktop.
#include<iostream>
#include<string>
#include<boost/property_tree/ptree.hpp>
#include<boost/property_tree/json_parser.hpp>
#include<boost/optional.hpp>
/* input file
{
"Level":
{
"frequency": 0.5,
"Pattern":
{
"Order": { "type": "Wait", "delay": "0.5" },
"Order": { "type": "Emit", "easing": "2", "z": "0.3", "duration": "0.8" },
"Order": { "type": "Emit", "easing": "4", "z": "0.3", "duration": "1.2" }
},
"Pattern":
{
"Order": { "type": "Wait", "delay": "0.2" },
"Order": { "type": "Emit", "easing": "3", "z": "0.3", "duration": "0.8" },
"Order": { "type": "Emit", "easing": "1", "z": "0.3", "duration": "1.2" }
}
}
}
*/
using namespace boost::property_tree;
int main() {
ptree pt;
read_json("out.json", pt);
for(auto& level: pt.get_child("")) {
std::cout << level.first << std::endl;
auto& orders = level.second.get_child("Pattern");
auto frequency = level.second.get_optional<float>("frequency");
std::cout << "freq:" << frequency << std::endl;
for(auto& order: orders) {
std::cout << order.first << std::endl;
std::string type = order.second.get<std::string>("type");
std::cout << type << std::endl;
if(type=="Emit") {
auto easing = order.second.get_optional<int>("easing");
auto z = order.second.get_optional<float>("z");
auto duration = order.second.get_optional<float>("duration");
std::cout << easing << ", " << z << ", " << duration << std::endl;
}
else if(type=="Wait"){
auto delay = order.second.get_optional<float>("delay");
std::cout << delay << std::endl;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment