Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
1Activity
0 of .
Results for:
No results containing your search query
P. 1
Property Tree

Property Tree

Ratings: (0)|Views: 170|Likes:
Published by Manasa Gopal
boost
boost

More info:

Published by: Manasa Gopal on Oct 05, 2013
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

04/04/2014

pdf

text

original

 
Boost.PropertyTree
Marcin Kalicinski
Copyright
©
2008 Marcin KalicinskiDistributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy atht-tp://www.boost.org/LICENSE_1_0.txt)
Table of Contents
What is Property Tree?............................................................................................................................................2Five Minute Tutorial...............................................................................................................................................3Property Tree as a Container....................................................................................................................................6Property Tree Synopsis...........................................................................................................................................7How to Populate a Property Tree...............................................................................................................................8XML Parser..................................................................................................................................................8JSON Parser..................................................................................................................................................8INI Parser.....................................................................................................................................................9INFO Parser................................................................................................................................................10How to Access Data in a Property Tree.....................................................................................................................11Appendices.........................................................................................................................................................13Reference...........................................................................................................................................................14Header <boost/property_tree/exceptions.hpp>....................................................................................................14Header <boost/property_tree/id_translator.hpp>.................................................................................................16Header <boost/property_tree/info_parser.hpp>...................................................................................................18Header <boost/property_tree/ini_parser.hpp>.....................................................................................................21Header <boost/property_tree/json_parser.hpp>...................................................................................................24Header <boost/property_tree/ptree.hpp>...........................................................................................................27Header <boost/property_tree/ptree_fwd.hpp>....................................................................................................38Header <boost/property_tree/ptree_serialization.hpp>.........................................................................................41Header <boost/property_tree/stream_translator.hpp>...........................................................................................43Header <boost/property_tree/string_path.hpp>...................................................................................................47Header <boost/property_tree/xml_parser.hpp>...................................................................................................501
 
The Property Tree library provides a data structure that stores an arbitrarily deeply nested tree of values, indexed at each level bysome key. Each node of the tree stores its own value, plus an ordered list of its subnodes and their keys. The tree allows easy accessto any of its nodes by means of a path, which is a concatenation of multiple keys.In addition, the library provides parsers and generators for a number of data formats that can be represented by such a tree, includingXML, INI, and JSON.Property trees are versatile data structures, but are particularly suited for holding con
f
guration data. The tree provides its own, tree-speci
f
c interface, and each node is also an STL-compatible Sequence for its child nodes.Conceptually, then, a node can be thought of as the following structure:
structptree{data_type data;// data associated with the nodelist<pair<key_type,ptree> >children;// ordered list of named children };
Both key_type and data_type are con
f
gurable, but will usually be std::string.Many software projects develop a similar tool at some point of their lifetime, and property tree originated the same way. We hopethe library can save many from reinventing the wheel.2Boost.PropertyTree
 
This tutorial uses XML. Note that the library is not speci
f
cally bound to XML, and any other supported format (such as INI orJSON) could be used instead. XML was chosen because the author thinks that wide range of people is familiar with it.Suppose we are writing a logging system for some application, and need to read log con
f
guration from a
f
le when the programstarts. The
f
le with the log con
f
guration looks like this:
<debug><filename>debug.log</filename><modules><module>Finance</module><module>Admin</module><module>HR</module></modules><level>2</level></debug>
It contains the log
f
lename, a list of modules where logging is enabled, and the debug level value. To store the logging con
f
gurationin the program we created a debug_settings structure:
structdebug_settings{std::string m_file;// log filename intm_level;// debug level std::set<string>m_modules;// modules where logging is enabled voidload(conststd::string&filename); voidsave(conststd::string&filename); };
All that needs to be done now is to write implementations of load() and save() member functions. Let's
f
rst deal with load(). Itcontains just 7 lines of code, although it does all the necessary things, including error reporting:3Boost.PropertyTree

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->