Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for a snapshot of the develop branch, built from commit b5267c6e8a.
PrevUpHomeNext

Chapter 31. Boost.PropertyTree

Marcin Kalicinski

Sebastian Redl

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)

Table of Contents

What is Property Tree?
Five Minute Tutorial
Property Tree as a Container
Property Tree Synopsis
How to Populate a Property Tree
XML Parser
JSON Parser
INI Parser
INFO Parser
How to Access Data in a Property Tree
Appendices
Reference
Header <boost/property_tree/exceptions.hpp>
Header <boost/property_tree/id_translator.hpp>
Header <boost/property_tree/info_parser.hpp>
Header <boost/property_tree/ini_parser.hpp>
Header <boost/property_tree/json_parser.hpp>
Header <boost/property_tree/ptree.hpp>
Header <boost/property_tree/ptree_fwd.hpp>
Header <boost/property_tree/ptree_serialization.hpp>
Header <boost/property_tree/stream_translator.hpp>
Header <boost/property_tree/string_path.hpp>
Header <boost/property_tree/xml_parser.hpp>

The Property Tree library provides a data structure that stores an arbitrarily deeply nested tree of values, indexed at each level by some key. Each node of the tree stores its own value, plus an ordered list of its subnodes and their keys. The tree allows easy access to 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, including XML, INI, and JSON.

Property trees are versatile data structures, but are particularly suited for holding configuration data. The tree provides its own, tree-specific 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:

struct ptree
{
   data_type data;                         // data associated with the node
   list< pair<key_type, ptree> > children; // ordered list of named children
};

Both key_type and data_type are configurable to some extent, but will usually be std::string or std::wstring, and the parsers only work with this kind of tree.

Many software projects develop a similar tool at some point of their lifetime, and property tree originated the same way. We hope the library can save many from reinventing the wheel.


PrevUpHomeNext