Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
property_tree/examples/debug_settings.cpp at develop · LRFLEW/property_tree · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
LRFLEW
/
property_tree
Public
forked from
boostorg/property_tree
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Files
Expand file tree
develop
Breadcrumbs
property_tree
/
examples
/
debug_settings.cpp
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
95 lines (85 loc) · 2.98 KB
develop
Breadcrumbs
property_tree
/
examples
/
debug_settings.cpp
Copy path
Top
File metadata and controls
Code
Blame
95 lines (85 loc) · 2.98 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
----------------------------------------------------------------------------
//
Copyright (C) 2002-2006 Marcin Kalicinski
//
//
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)
//
//
For more information, see www.boost.org
//
----------------------------------------------------------------------------
//
[debug_settings_includes
#
include
<
boost/property_tree/ptree.hpp
>
#
include
<
boost/property_tree/xml_parser.hpp
>
#
include
<
boost/foreach.hpp
>
#
include
<
string
>
#
include
<
set
>
#
include
<
exception
>
#
include
<
iostream
>
namespace
pt
=
boost::property_tree;
//
]
//
[debug_settings_data
struct
debug_settings
{
std::string m_file;
//
log filename
int
m_level;
//
debug level
std::set<std::string> m_modules;
//
modules where logging is enabled
void
load
(
const
std::string &filename);
void
save
(
const
std::string &filename);
};
//
]
//
[debug_settings_load
void
debug_settings::load
(
const
std::string &filename)
{
//
Create empty property tree object
pt::ptree tree;
//
Parse the XML into the property tree.
pt::read_xml
(filename, tree);
//
Use the throwing version of get to find the debug filename.
//
If the path cannot be resolved, an exception is thrown.
m_file = tree.
get
<std::string>(
"
debug.filename
"
);
//
Use the default-value version of get to find the debug level.
//
Note that the default value is used to deduce the target type.
m_level = tree.
get
(
"
debug.level
"
,
0
);
//
Use get_child to find the node containing the modules, and iterate over
//
its children. If the path cannot be resolved, get_child throws.
//
A C++11 for-range loop would also work.
BOOST_FOREACH
(pt::ptree::value_type &v, tree.
get_child
(
"
debug.modules
"
)) {
//
The data function is used to access the data stored in a node.
m_modules.
insert
(v.
second
.
data
());
}
}
//
]
//
[debug_settings_save
void
debug_settings::save
(
const
std::string &filename)
{
//
Create an empty property tree object.
pt::ptree tree;
//
Put the simple values into the tree. The integer is automatically
//
converted to a string. Note that the "debug" node is automatically
//
created if it doesn't exist.
tree.
put
(
"
debug.filename
"
, m_file);
tree.
put
(
"
debug.level
"
, m_level);
//
Add all the modules. Unlike put, which overwrites existing nodes, add
//
adds a new node at the lowest level, so the "modules" node will have
//
multiple "module" children.
BOOST_FOREACH
(
const
std::string &name, m_modules)
tree.
add
(
"
debug.modules.module
"
, name);
//
Write property tree to XML file
pt::write_xml
(filename, tree);
}
//
]
int
main
()
{
try
{
debug_settings ds;
ds.
load
(
"
debug_settings.xml
"
);
ds.
save
(
"
debug_settings_out.xml
"
);
std::cout <<
"
Success
\n
"
;
}
catch
(std::exception &e)
{
std::cout <<
"
Error:
"
<< e.
what
() <<
"
\n
"
;
}
return
0
;
}
You can’t perform that action at this time.