Skip to content

Instantly share code, notes, and snippets.

@serge1
Created October 25, 2015 06:21
Show Gist options
  • Save serge1/1aa09b08a3e94275e522 to your computer and use it in GitHub Desktop.
Save serge1/1aa09b08a3e94275e522 to your computer and use it in GitHub Desktop.
Boost property map usage example
#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;
}
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