Created
October 25, 2015 06:21
-
-
Save serge1/1aa09b08a3e94275e522 to your computer and use it in GitHub Desktop.
Boost property map usage example
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 <boost/property_tree/ptree.hpp> | |
#include <boost/any.hpp> | |
#include <boost/property_tree/info_parser.hpp> | |
#include <boost/foreach.hpp> | |
#include <list> | |
#include <string> | |
#include <iostream> | |
using namespace boost::property_tree; | |
int main() | |
{ | |
ptree tree; | |
try { | |
read_info("test.tsf", tree); | |
} | |
catch (...) | |
{ | |
std::cout << "Failed to open the file" << std::endl; | |
} | |
bool reset = tree.get("reset", false); | |
int speed = tree.get("speed", 100); | |
float freq = tree.get("freq", 200.0); | |
std::string name = tree.get("name", "noname"); | |
std::cout | |
<< reset << std::endl | |
<< speed << std::endl | |
<< freq << std::endl | |
<< name << std::endl; | |
BOOST_FOREACH(const ptree::value_type& v1, tree.get_child("")) { | |
try { | |
if (v1.first == "memory") { | |
std::cout << v1.second.get<std::string>("start") | |
<< " - " | |
<< v1.second.get<std::string>("size") | |
<< std::endl; | |
} | |
} | |
catch (...) { | |
std::cout << "'start' and 'size' entries cannot be omitted in 'memory' description" << std::endl; | |
} | |
} | |
return 0; | |
} |
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
reset 1 | |
speed 23 | |
memory internal | |
{ | |
start 0x0 | |
size 0x10000 | |
} | |
memory | |
{ | |
start 0x10000 | |
size 0x1000 | |
} | |
name "Hello my friend" | |
memory | |
{ | |
start 0x20000 | |
size 0x2000 | |
} | |
freq 12.3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment