]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/property_tree/doc/tutorial.qbk
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / property_tree / doc / tutorial.qbk
CommitLineData
7c673cae
FG
1[/
2 / Copyright (c) 2008 Marcin Kalicinski (kalita <at> poczta dot onet dot pl)
3 / Copyright (c) 2009, 2013 Sebastian Redl (sebastian dot redl <at> getdesigned dot at)
4 /
5 / Distributed under the Boost Software License, Version 1.0. (See accompanying
6 / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 /]
8[section:tutorial Five Minute Tutorial]
9[import ../examples/debug_settings.cpp]
10
11This tutorial uses XML. Note that the library is not specifically bound to XML,
12and any other supported format (such as INI or JSON) could be used instead.
13XML was chosen because the author thinks that a wide range of people is familiar
14with it.
15
16Suppose we are writing a logging system for some application, and need to read
17log configuration from a file when the program starts. The file with the log
18configuration looks like this:
19
20[pre
21<debug>
22 <filename>debug.log</filename>
23 <modules>
24 <module>Finance</module>
25 <module>Admin</module>
26 <module>HR</module>
27 </modules>
28 <level>2</level>
29</debug>
30]
31
32It contains the log filename, a list of modules where logging is enabled, and
33the debug level value.
34
35First we need some includes:
36
37[debug_settings_includes]
38
39To store the logging configuration in the program we create a debug_settings
40structure:
41
42[debug_settings_data]
43
44All that needs to be done now is to write implementations of load() and save()
45member functions. Let's first deal with load(). It contains just 7 lines of
46code, although it does all the necessary things, including error reporting:
47
48[debug_settings_load]
49
50Now the save() function. It is also 7 lines of code:
51
52[debug_settings_save]
53
54The full program [@boost:/libs/property_tree/examples/debug_settings.cpp debug_settings.cpp] is
55included in the examples directory.
56[endsect] [/tutorial]