-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathproperties_tree.cc
43 lines (39 loc) · 1.32 KB
/
properties_tree.cc
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
//=============================================================================
// Copyright (c) 2015-2021 glywk
// https://github.com/glywk
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//=============================================================================
#include <boost/foreach.hpp>
#include <boost/property_tree/properties_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <exception>
#include <iostream>
#include <set>
#include <string>
namespace pt = boost::property_tree;
struct configuration {
void load(const std::string &filename);
pt::ptree tree;
};
void configuration::load(const std::string &filename) {
// Parse the properties into the property tree.
pt::read_properties(filename, tree);
}
/*!
* the main function simply loads the given file into boost::property_tree structure.
*/
int main(int argc, char *argv[]) {
try {
// read input from the given file
std::string filename(1 == argc ? "full.properties" : argv[1]);
configuration c;
c.load(filename);
for (auto property : c.tree) {
std::cout << property.first << "=" << property.second.data() << std::endl;
}
} catch (std::exception &e) {
std::cout << "Error: " << e.what() << "\n";
}
return 0;
}