Created
February 11, 2014 13:01
-
-
Save ignisan/8934426 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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