$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r65976 - in branches/release/libs/property_tree: . doc examples test
From: sebastian.redl_at_[hidden]
Date: 2010-10-15 08:41:55
Author: cornedbee
Date: 2010-10-15 08:41:49 EDT (Fri, 15 Oct 2010)
New Revision: 65976
URL: http://svn.boost.org/trac/boost/changeset/65976
Log:
Merge long-overdue PTree changes to release (libs)
Properties modified: 
   branches/release/libs/property_tree/   (props changed)
Text files modified: 
   branches/release/libs/property_tree/doc/property_tree.qbk             |     5 --                                      
   branches/release/libs/property_tree/doc/tutorial.qbk                  |     2                                         
   branches/release/libs/property_tree/examples/custom_data_type.cpp     |    64 ++++++++++++++++++++++----------------- 
   branches/release/libs/property_tree/examples/debug_settings.cpp       |    12 +++---                                  
   branches/release/libs/property_tree/test/test_json_parser.cpp         |     4 +-                                      
   branches/release/libs/property_tree/test/test_property_tree.cpp       |     6 +++                                     
   branches/release/libs/property_tree/test/test_property_tree.hpp       |    15 +++++++++                               
   branches/release/libs/property_tree/test/test_xml_parser_common.hpp   |    17 +++++++---                              
   branches/release/libs/property_tree/test/test_xml_parser_rapidxml.cpp |     3 +                                       
   branches/release/libs/property_tree/test/xml_parser_test_data.hpp     |     4 ++                                      
   10 files changed, 85 insertions(+), 47 deletions(-)
Modified: branches/release/libs/property_tree/doc/property_tree.qbk
==============================================================================
--- branches/release/libs/property_tree/doc/property_tree.qbk	(original)
+++ branches/release/libs/property_tree/doc/property_tree.qbk	2010-10-15 08:41:49 EDT (Fri, 15 Oct 2010)
@@ -53,6 +53,7 @@
 [def __ptree_get_value_optional__ [memberref boost::property_tree::basic_ptree::get_value_optional get_value_optional]]
 [def __ptree_get_child__ [memberref boost::property_tree::basic_ptree::get_child get_child]]
 [def __ptree_put__ [memberref boost::property_tree::basic_ptree::put put]]
+[def __ptree_put__ [memberref boost::property_tree::basic_ptree::add add]]
 [def __ptree_put_value__ [memberref boost::property_tree::basic_ptree::put_value put_value]]
 
 [/ free-functions]
@@ -104,10 +105,6 @@
    itself.] Used when you want to vary control flow depending on get
    success/failure. Or to check for presence of a key.
 
-# [*Why does the separator character come before the path and not after
-    as one would expect?]
-It helps with overload resolution in some cases.
-
 [heading Future Development]
 * More parsers:  YAML, environment strings.
 * More robust XML parser.
Modified: branches/release/libs/property_tree/doc/tutorial.qbk
==============================================================================
--- branches/release/libs/property_tree/doc/tutorial.qbk	(original)
+++ branches/release/libs/property_tree/doc/tutorial.qbk	2010-10-15 08:41:49 EDT (Fri, 15 Oct 2010)
@@ -106,7 +106,7 @@
       // be achieved using a combination of the insert and put_own
       // functions.
       BOOST_FOREACH(const std::string &name, m_modules)
-         pt.__ptree_put__("debug.modules.module", name, true);
+         pt.__ptree_add__("debug.modules.module", name);
 
       // Write the property tree to the XML file.
       __write_xml__(filename, pt);
Modified: branches/release/libs/property_tree/examples/custom_data_type.cpp
==============================================================================
--- branches/release/libs/property_tree/examples/custom_data_type.cpp	(original)
+++ branches/release/libs/property_tree/examples/custom_data_type.cpp	2010-10-15 08:41:49 EDT (Fri, 15 Oct 2010)
@@ -14,35 +14,28 @@
 // container (instead of std::string that standard ptree has).
 
 #include <boost/property_tree/ptree.hpp>
-#include <boost/property_tree/info_parser.hpp>
-#include <boost/property_tree/ini_parser.hpp>
-#include <boost/property_tree/json_parser.hpp>
-#include <boost/property_tree/xml_parser.hpp>
 #include <boost/any.hpp>
 #include <list>
 #include <string>
 #include <iostream>
 
 // Custom translator that works with boost::any instead of std::string
-struct my_translator
+template <class Ext, class Int = boost::any>
+struct variant_translator
 {
+    typedef Ext external_type;
+    typedef Int internal_type;
 
-    // Custom extractor - converts data from boost::any to T
-    template<class Ptree, class T> 
-    bool get_value(const Ptree &pt, T &value) const
+    external_type
+    get_value(const internal_type &value) const
     {
-        value = boost::any_cast<T>(pt.data());
-        return true;    // Success
+        return boost::any_cast<external_type>(value);
     }
-
-    // Custom inserter - converts data from T to boost::any
-    template<class Ptree, class T> 
-    bool put_value(Ptree &pt, const T &value) const
+    internal_type
+    put_value(const external_type &value) const
     {
-        pt.data() = value;
-        return true;
+        return value;
     }
-
 };
 
 int main()
@@ -51,30 +44,45 @@
     using namespace boost::property_tree;
     
     // Property_tree with boost::any as data type
-    // Key comparison:  std::less<std::string>
     // Key type:        std::string
-    // Path type:       path
     // Data type:       boost::any
-    // Translator type: my_translator
-    typedef basic_ptree<std::less<std::string>, std::string, path, boost::any, my_translator> my_ptree;
+    // Key comparison:  default (std::less<std::string>)
+    typedef basic_ptree<std::string, boost::any> my_ptree;
     my_ptree pt;
 
     // Put/get int value
-    pt.put("int value", 3);
-    int int_value = pt.get<int>("int value");
+    typedef variant_translator<int> int_tran;
+    pt.put("int value", 3, int_tran());
+    int int_value = pt.get<int>("int value", int_tran());
     std::cout << "Int value: " << int_value << "\n";
 
     // Put/get string value
-    pt.put<std::string>("string value", "foo bar");
-    std::string string_value = pt.get<std::string>("string value");
+    typedef variant_translator<std::string> string_tran;
+    pt.put<std::string>("string value", "foo bar", string_tran());
+    std::string string_value = pt.get<std::string>(
+        "string value"
+      , string_tran()
+    );
     std::cout << "String value: " << string_value << "\n";
 
     // Put/get list<int> value
+    typedef std::list<int> intlist;
+    typedef variant_translator<intlist> intlist_tran;
     int list_data[] = { 1, 2, 3, 4, 5 };
-    pt.put<std::list<int> >("list value", std::list<int>(list_data, list_data + sizeof(list_data) / sizeof(*list_data)));
-    std::list<int> list_value = pt.get<std::list<int> >("list value");
+    pt.put<intlist>(
+        "list value"
+      , intlist(
+            list_data
+          , list_data + sizeof(list_data) / sizeof(*list_data)
+        )
+      , intlist_tran()
+    );
+    intlist list_value = pt.get<intlist>(
+        "list value"
+      , intlist_tran()
+    );
     std::cout << "List value: ";
-    for (std::list<int>::iterator it = list_value.begin(); it != list_value.end(); ++it)
+    for (intlist::iterator it = list_value.begin(); it != list_value.end(); ++it)
         std::cout << *it << ' ';
     std::cout << '\n';
 }
Modified: branches/release/libs/property_tree/examples/debug_settings.cpp
==============================================================================
--- branches/release/libs/property_tree/examples/debug_settings.cpp	(original)
+++ branches/release/libs/property_tree/examples/debug_settings.cpp	2010-10-15 08:41:49 EDT (Fri, 15 Oct 2010)
@@ -10,7 +10,7 @@
 
 #include <boost/property_tree/ptree.hpp>
 #include <boost/property_tree/xml_parser.hpp>
-//#include <boost/foreach.hpp>
+#include <boost/foreach.hpp>
 #include <string>
 #include <set>
 #include <exception>
@@ -77,15 +77,15 @@
     // Put debug level in property tree
     pt.put("debug.level", m_level);
 
-    // Iterate over modules in set and put them in property 
-    // tree. Note that put function places new key at the
+    // Iterate over modules in set and put them in property
+    // tree. Note that the add function places new key at the
     // end of list of keys. This is fine in most of the
     // situations. If you want to place item at some other
     // place (i.e. at front or somewhere in the middle),
-    // this can be achieved using combination of insert 
+    // this can be achieved using a combination of the insert
     // and put_value functions
-    //BOOST_FOREACH(const std::string &name, m_modules)
-    //    pt.put("debug.modules.module", name, true);
+    BOOST_FOREACH(const std::string &name, m_modules)
+        pt.add("debug.modules.module", name);
     
     // Write property tree to XML file
     write_xml(filename, pt);
Modified: branches/release/libs/property_tree/test/test_json_parser.cpp
==============================================================================
--- branches/release/libs/property_tree/test/test_json_parser.cpp	(original)
+++ branches/release/libs/property_tree/test/test_json_parser.cpp	2010-10-15 08:41:49 EDT (Fri, 15 Oct 2010)
@@ -235,7 +235,7 @@
     "}\n";
 
 const char *ok_data_12 = 
-    "{\"  \\\" \\\\ \\0 \\b \\f \\n \\r \\t  \" : \"multi\" \"-\" \"string\"}";
+    "{\"  \\\" \\\\ \\b \\f \\n \\r \\t  \" : \"multi\" \"-\" \"string\"}";
 
 const char *error_data_1 = 
     "";   // No root object
@@ -342,7 +342,7 @@
     generic_parser_test_ok<Ptree, ReadFunc, WriteFunc>
     (
         ReadFunc(), WriteFunc(), ok_data_12, NULL, 
-        "testok12.json", NULL, "testok12out.json", 2, 12, 19
+        "testok12.json", NULL, "testok12out.json", 2, 12, 17
     );
 
     generic_parser_test_error<ptree, ReadFunc, WriteFunc, json_parser_error>
Modified: branches/release/libs/property_tree/test/test_property_tree.cpp
==============================================================================
--- branches/release/libs/property_tree/test/test_property_tree.cpp	(original)
+++ branches/release/libs/property_tree/test/test_property_tree.cpp	2010-10-15 08:41:49 EDT (Fri, 15 Oct 2010)
@@ -9,8 +9,10 @@
 // ----------------------------------------------------------------------------
 #include "test_utils.hpp"
 #include <boost/any.hpp>
+#include <boost/range.hpp>
 #include <list>
 #include <cmath>
+#include <iostream>
 
 // If using VC, disable some warnings that trip in boost::serialization bowels
 #ifdef BOOST_MSVC
@@ -152,6 +154,7 @@
         test_front_back(pt);
         test_get_put(pt);
         test_get_child_put_child(pt);
+        test_equal_range(pt);
         test_path_separator(pt);
         test_path(pt);
         test_precision(pt);
@@ -184,6 +187,7 @@
         test_front_back(pt);
         test_get_put(pt);
         test_get_child_put_child(pt);
+        test_equal_range(pt);
         test_path_separator(pt);
         test_path(pt);
         test_precision(pt);
@@ -216,6 +220,7 @@
         test_front_back(pt);
         test_get_put(pt);
         test_get_child_put_child(pt);
+        test_equal_range(pt);
         test_path_separator(pt);
         test_path(pt);
         test_precision(pt);
@@ -248,6 +253,7 @@
         test_front_back(pt);
         test_get_put(pt);
         test_get_child_put_child(pt);
+        test_equal_range(pt);
         test_path_separator(pt);
         test_path(pt);
         test_precision(pt);
Modified: branches/release/libs/property_tree/test/test_property_tree.hpp
==============================================================================
--- branches/release/libs/property_tree/test/test_property_tree.hpp	(original)
+++ branches/release/libs/property_tree/test/test_property_tree.hpp	2010-10-15 08:41:49 EDT (Fri, 15 Oct 2010)
@@ -914,6 +914,21 @@
 
 }
 
+void test_equal_range(PTREE *)
+{
+    PTREE pt;
+    pt.add_child(T("k1"), PTREE());
+    pt.add_child(T("k2"), PTREE());
+    pt.add_child(T("k1"), PTREE());
+    pt.add_child(T("k3"), PTREE());
+    pt.add_child(T("k1"), PTREE());
+    pt.add_child(T("k2"), PTREE());
+
+    BOOST_CHECK(boost::distance(pt.equal_range(T("k1"))) == 3);
+    BOOST_CHECK(boost::distance(pt.equal_range(T("k2"))) == 2);
+    BOOST_CHECK(boost::distance(pt.equal_range(T("k3"))) == 1);
+}
+
 void test_path_separator(PTREE *)
 {
 
Modified: branches/release/libs/property_tree/test/test_xml_parser_common.hpp
==============================================================================
--- branches/release/libs/property_tree/test/test_xml_parser_common.hpp	(original)
+++ branches/release/libs/property_tree/test/test_xml_parser_common.hpp	2010-10-15 08:41:49 EDT (Fri, 15 Oct 2010)
@@ -19,7 +19,8 @@
     template<class Ptree>
     void operator()(const std::string &filename, Ptree &pt) const
     {
-        boost::property_tree::read_xml(filename, pt);
+        boost::property_tree::read_xml(filename, pt,
+          boost::property_tree::xml_parser::no_concat_text);
     }
 };
 
@@ -72,7 +73,7 @@
     generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
     (
         ReadFuncWS(), WriteFuncWS(), ok_data_2, NULL, 
-        "testok2a.xml", NULL, "testok2aout.xml", 6, 18, 8
+        "testok2a.xml", NULL, "testok2aout.xml", 15, 23, 89
     );
 
     generic_parser_test_ok<Ptree, ReadFuncNS, WriteFuncNS>
@@ -84,7 +85,7 @@
     generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
     (
         ReadFuncWS(), WriteFuncWS(), ok_data_3, NULL, 
-        "testok3a.xml", NULL, "testok3aout.xml", 787, 32523, 3831
+        "testok3a.xml", NULL, "testok3aout.xml", 1662, 35377, 11706
     );
 
     generic_parser_test_ok<Ptree, ReadFuncNS, WriteFuncNS>
@@ -96,14 +97,14 @@
     generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
     (
         ReadFuncWS(), WriteFuncWS(), ok_data_4, NULL, 
-        "testok4.xml", NULL, "testok4out.xml", 5, 2, 20
+        "testok4.xml", NULL, "testok4out.xml", 11, 7, 74
     );
 
     generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
     (
         ReadFuncWS(), WriteFuncWS(), ok_data_5, NULL, 
         "testok5.xml", NULL, "testok5out.xml",
-        2, umlautsize<typename Ptree::data_type::value_type>(), 3
+        3, umlautsize<typename Ptree::data_type::value_type>(), 12
     );
 
     generic_parser_test_error<Ptree, ReadFuncWS, WriteFuncWS, xml_parser_error>
@@ -118,6 +119,12 @@
         "testerr2.xml", NULL, "testerr2out.xml", 2
     );
 
+    generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
+    (
+        ReadFuncWS(), WriteFuncWS(), bug_data_pr2855, NULL,
+        "testpr2855.xml", NULL, "testpr2855out.xml", 3, 7, 14
+    );
+
 }
 
 #endif
Modified: branches/release/libs/property_tree/test/test_xml_parser_rapidxml.cpp
==============================================================================
--- branches/release/libs/property_tree/test/test_xml_parser_rapidxml.cpp	(original)
+++ branches/release/libs/property_tree/test/test_xml_parser_rapidxml.cpp	2010-10-15 08:41:49 EDT (Fri, 15 Oct 2010)
@@ -1,5 +1,6 @@
 // ----------------------------------------------------------------------------
 // Copyright (C) 2002-2006 Marcin Kalicinski
+// Copyright (C) 2009-2010 Sebastian Redl
 //
 // Distributed under the Boost Software License, Version 1.0. 
 // (See accompanying file LICENSE_1_0.txt or copy at 
@@ -19,10 +20,10 @@
 int test_main(int argc, char *argv[])
 {
     using namespace boost::property_tree;
-    using std::locale;
     test_xml_parser<ptree>();
     test_xml_parser<iptree>();
 #ifndef BOOST_NO_CWCHAR
+    using std::locale;
     // We need a UTF-8-aware global locale now.
     locale loc(locale(), new utf8_codecvt_facet);
     locale::global(loc);
Modified: branches/release/libs/property_tree/test/xml_parser_test_data.hpp
==============================================================================
--- branches/release/libs/property_tree/test/xml_parser_test_data.hpp	(original)
+++ branches/release/libs/property_tree/test/xml_parser_test_data.hpp	2010-10-15 08:41:49 EDT (Fri, 15 Oct 2010)
@@ -760,4 +760,8 @@
     "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"    
     "<start>";      // XML tag not closed
 
+const char *bug_data_pr2855 =
+    "<?xml version=\"1.0\" encoding\"utf-8\"?>\n"
+    "<start> notrim</start>";
+
 #endif