-
Notifications
You must be signed in to change notification settings - Fork 0
/
playJson.cpp
63 lines (52 loc) · 2.28 KB
/
playJson.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <vector>
#include <set>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/date_time.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/foreach.hpp>
using namespace boost::property_tree;
int main() {
//create an empty property tree object
ptree ptJson;
//parse the xml file into the property tree
read_json("../sample.json", ptJson);
//read values
std::string target = ptJson.get<std::string>("header.target");
int tradeQty = ptJson.get<int>("body.qty");
std::string symbol = ptJson.get<std::string>("body.symbol");
std::cout << "Target is " << target << ", qty is " << tradeQty << ", and symbol is " << symbol << std::endl;
//add a value
ptJson.put("body.orca-p1", "P1 did its thing");
//change a value
ptJson.put("header.target", "P2");
target = ptJson.get<std::string>("header.target");
std::string orca_p1 = ptJson.get<std::string>("body.orca-p1");
std::cout << "New target is " << target << " and orca-p1 is " << orca_p1 << std::endl;
ptree ptConfig;
std::string currentRoute = "P2";
std::string nextRoute;
bool foundCurrent = 0;
read_json("../sampleConfig.json", ptConfig);
BOOST_FOREACH(ptree::value_type & v, ptConfig.get_child("orcaConfig.PM_ORDER.")) {
std::cout << v.second.data() << std::endl;
if (foundCurrent == 1) {
nextRoute = v.second.data();
std::cout << "Setting next route to " << nextRoute << std::endl;
break;
}
if (v.second.data() == currentRoute)
foundCurrent = 1;
}
std::string msgType;
BOOST_FOREACH (ptree::value_type & v, ptConfig.get_child("orcaConfig")) {
msgType = v.first.data();
std::cout << "Message Type is " << msgType << std::endl;
BOOST_FOREACH (ptree::value_type & x, ptConfig.get_child("orcaConfig." + msgType)) {
std::cout << "\tPath entry is " << x.second.data() << std::endl;
}
}
return 0;
}