|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r59737 - trunk/boost/property_tree/detail
From: sebastian.redl_at_[hidden]
Date: 2010-02-17 13:10:47
Author: cornedbee
Date: 2010-02-17 13:10:46 EST (Wed, 17 Feb 2010)
New Revision: 59737
URL: http://svn.boost.org/trac/boost/changeset/59737
Log:
RapidXML is in PropertyTree as an implementation detail and should be treated as such, so prefix macros and put the namespace into ptree's detail namespace. Fixes bug 3817.
Text files modified:
trunk/boost/property_tree/detail/rapidxml.hpp | 146 +++++++++++++++------------------------
trunk/boost/property_tree/detail/xml_parser_read_rapidxml.hpp | 42 +++++++----
2 files changed, 81 insertions(+), 107 deletions(-)
Modified: trunk/boost/property_tree/detail/rapidxml.hpp
==============================================================================
--- trunk/boost/property_tree/detail/rapidxml.hpp (original)
+++ trunk/boost/property_tree/detail/rapidxml.hpp 2010-02-17 13:10:46 EST (Wed, 17 Feb 2010)
@@ -7,17 +7,14 @@
//
// For more information, see www.boost.org
// ----------------------------------------------------------------------------
-#ifndef RAPIDXML_HPP_INCLUDED
-#define RAPIDXML_HPP_INCLUDED
+#ifndef BOOST_PROPERTY_TREE_RAPIDXML_HPP_INCLUDED
+#define BOOST_PROPERTY_TREE_RAPIDXML_HPP_INCLUDED
//! \file rapidxml.hpp This file contains rapidxml parser and DOM implementation
-// If standard library is disabled, user must provide implementations of required functions and typedefs
-#if !defined(RAPIDXML_NO_STDLIB)
- #include <cstdlib> // For std::size_t
- #include <cassert> // For assert
- #include <new> // For placement new
-#endif
+#include <cstdlib> // For std::size_t
+#include <cassert> // For assert
+#include <new> // For placement new
// On MSVC, disable "conditional expression is constant" warning (level 4).
// This warning is almost impossible to avoid with certain types of templated code
@@ -27,40 +24,13 @@
#endif
///////////////////////////////////////////////////////////////////////////
-// RAPIDXML_PARSE_ERROR
-
-#if defined(RAPIDXML_NO_EXCEPTIONS)
-
-#define RAPIDXML_PARSE_ERROR(what, where) { parse_error_handler(what, where); assert(0); }
-
-namespace rapidxml
-{
- //! When exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS,
- //! this function is called to notify user about the error.
- //! It must be defined by the user.
- //! <br><br>
- //! This function cannot return. If it does, the results are undefined.
- //! <br><br>
- //! A very simple definition might look like that:
- //! <pre>
- //! void %rapidxml::%parse_error_handler(const char *what, void *where)
- //! {
- //! std::cout << "Parse error: " << what << "\n";
- //! std::abort();
- //! }
- //! </pre>
- //! \param what Human readable description of the error.
- //! \param where Pointer to character data where error was detected.
- void parse_error_handler(const char *what, void *where);
-}
-
-#else
+// BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR
#include <exception> // For std::exception
-#define RAPIDXML_PARSE_ERROR(what, where) throw parse_error(what, where)
+#define BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR(what, where) throw parse_error(what, where)
-namespace rapidxml
+namespace boost { namespace property_tree { namespace detail {namespace rapidxml
{
//! Parse error exception.
@@ -108,36 +78,34 @@
void *m_where;
};
-}
-
-#endif
+}}}}
///////////////////////////////////////////////////////////////////////////
// Pool sizes
-#ifndef RAPIDXML_STATIC_POOL_SIZE
+#ifndef BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE
// Size of static memory block of memory_pool.
- // Define RAPIDXML_STATIC_POOL_SIZE before including rapidxml.hpp if you want to override the default value.
+ // Define BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE before including rapidxml.hpp if you want to override the default value.
// No dynamic memory allocations are performed by memory_pool until static memory is exhausted.
- #define RAPIDXML_STATIC_POOL_SIZE (64 * 1024)
+ #define BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE (64 * 1024)
#endif
-#ifndef RAPIDXML_DYNAMIC_POOL_SIZE
+#ifndef BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE
// Size of dynamic memory block of memory_pool.
- // Define RAPIDXML_DYNAMIC_POOL_SIZE before including rapidxml.hpp if you want to override the default value.
+ // Define BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE before including rapidxml.hpp if you want to override the default value.
// After the static block is exhausted, dynamic blocks with approximately this size are allocated by memory_pool.
- #define RAPIDXML_DYNAMIC_POOL_SIZE (64 * 1024)
+ #define BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE (64 * 1024)
#endif
-#ifndef RAPIDXML_ALIGNMENT
+#ifndef BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT
// Memory allocation alignment.
- // Define RAPIDXML_ALIGNMENT before including rapidxml.hpp if you want to override the default value, which is the size of pointer.
+ // Define BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT before including rapidxml.hpp if you want to override the default value, which is the size of pointer.
// All memory allocations for nodes, attributes and strings will be aligned to this value.
// This must be a power of 2 and at least 1, otherwise memory_pool will not work.
- #define RAPIDXML_ALIGNMENT sizeof(void *)
+ #define BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT sizeof(void *)
#endif
-namespace rapidxml
+namespace boost { namespace property_tree { namespace detail {namespace rapidxml
{
// Forward declarations
template<class Ch> class xml_node;
@@ -364,20 +332,20 @@
//! It is also possible to create a standalone memory_pool, and use it
//! to allocate nodes, whose lifetime will not be tied to any document.
//! <br><br>
- //! Pool maintains <code>RAPIDXML_STATIC_POOL_SIZE</code> bytes of statically allocated memory.
+ //! Pool maintains <code>BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE</code> bytes of statically allocated memory.
//! Until static memory is exhausted, no dynamic memory allocations are done.
- //! When static memory is exhausted, pool allocates additional blocks of memory of size <code>RAPIDXML_DYNAMIC_POOL_SIZE</code> each,
+ //! When static memory is exhausted, pool allocates additional blocks of memory of size <code>BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE</code> each,
//! by using global <code>new[]</code> and <code>delete[]</code> operators.
//! This behaviour can be changed by setting custom allocation routines.
//! Use set_allocator() function to set them.
//! <br><br>
- //! Allocations for nodes, attributes and strings are aligned at <code>RAPIDXML_ALIGNMENT</code> bytes.
+ //! Allocations for nodes, attributes and strings are aligned at <code>BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT</code> bytes.
//! This value defaults to the size of pointer on target architecture.
//! <br><br>
//! To obtain absolutely top performance from the parser,
//! it is important that all nodes are allocated from a single, contiguous block of memory.
//! Otherwise, cache misses when jumping between two (or more) disjoint blocks of memory can slow down parsing quite considerably.
- //! If required, you can tweak <code>RAPIDXML_STATIC_POOL_SIZE</code>, <code>RAPIDXML_DYNAMIC_POOL_SIZE</code> and <code>RAPIDXML_ALIGNMENT</code>
+ //! If required, you can tweak <code>BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE</code>, <code>BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE</code> and <code>BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT</code>
//! to obtain best wasted memory to performance compromise.
//! To do it, define their values before rapidxml.hpp file is included.
//! \param Ch Character type of created nodes.
@@ -578,7 +546,7 @@
char *align(char *ptr)
{
- std::size_t alignment = ((RAPIDXML_ALIGNMENT - (std::size_t(ptr) & (RAPIDXML_ALIGNMENT - 1))) & (RAPIDXML_ALIGNMENT - 1));
+ std::size_t alignment = ((BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT - (std::size_t(ptr) & (BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT - 1))) & (BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT - 1));
return ptr + alignment;
}
@@ -594,10 +562,6 @@
else
{
memory = new char[size];
-#ifdef RAPIDXML_NO_EXCEPTIONS
- if (!memory) // If exceptions are disabled, verify memory allocation, because new will not be able to throw bad_alloc
- RAPIDXML_PARSE_ERROR("out of memory", 0);
-#endif
}
return static_cast<char *>(memory);
}
@@ -610,13 +574,13 @@
// If not enough memory left in current pool, allocate a new pool
if (result + size > m_end)
{
- // Calculate required pool size (may be bigger than RAPIDXML_DYNAMIC_POOL_SIZE)
- std::size_t pool_size = RAPIDXML_DYNAMIC_POOL_SIZE;
+ // Calculate required pool size (may be bigger than BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE)
+ std::size_t pool_size = BOOST_PROPERTY_TREE_RAPIDXML_DYNAMIC_POOL_SIZE;
if (pool_size < size)
pool_size = size;
// Allocate
- std::size_t alloc_size = sizeof(header) + (2 * RAPIDXML_ALIGNMENT - 2) + pool_size; // 2 alignments required in worst case: one for header, one for actual allocation
+ std::size_t alloc_size = sizeof(header) + (2 * BOOST_PROPERTY_TREE_RAPIDXML_ALIGNMENT - 2) + pool_size; // 2 alignments required in worst case: one for header, one for actual allocation
char *raw_memory = allocate_raw(alloc_size);
// Setup new pool in allocated memory
@@ -639,7 +603,7 @@
char *m_begin; // Start of raw memory making up current pool
char *m_ptr; // First free byte in current pool
char *m_end; // One past last available byte in current pool
- char m_static_memory[RAPIDXML_STATIC_POOL_SIZE]; // Static raw memory
+ char m_static_memory[BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE]; // Static raw memory
alloc_func *m_alloc_func; // Allocator function, or 0 if default is to be used
free_func *m_free_func; // Free function, or 0 if default is to be used
};
@@ -1411,7 +1375,7 @@
this->append_node(node);
}
else
- RAPIDXML_PARSE_ERROR("expected <", text);
+ BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected <", text);
}
}
@@ -1554,7 +1518,7 @@
}
else // Invalid, only codes up to 0x10FFFF are allowed in Unicode
{
- RAPIDXML_PARSE_ERROR("invalid numeric character entity", text);
+ BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("invalid numeric character entity", text);
}
}
}
@@ -1685,7 +1649,7 @@
if (*src == Ch(';'))
++src;
else
- RAPIDXML_PARSE_ERROR("expected ;", src);
+ BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected ;", src);
continue;
// Something else
@@ -1750,7 +1714,7 @@
while (text[0] != Ch('?') || text[1] != Ch('>'))
{
if (!text[0])
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);
+ BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
++text;
}
text += 2; // Skip '?>'
@@ -1768,7 +1732,7 @@
// Skip ?>
if (text[0] != Ch('?') || text[1] != Ch('>'))
- RAPIDXML_PARSE_ERROR("expected ?>", text);
+ BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected ?>", text);
text += 2;
return declaration;
@@ -1785,7 +1749,7 @@
while (text[0] != Ch('-') || text[1] != Ch('-') || text[2] != Ch('>'))
{
if (!text[0])
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);
+ BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
++text;
}
text += 3; // Skip '-->'
@@ -1799,7 +1763,7 @@
while (text[0] != Ch('-') || text[1] != Ch('-') || text[2] != Ch('>'))
{
if (!text[0])
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);
+ BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
++text;
}
@@ -1841,7 +1805,7 @@
{
case Ch('['): ++depth; break;
case Ch(']'): --depth; break;
- case 0: RAPIDXML_PARSE_ERROR("unexpected end of data", text);
+ case 0: BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
}
++text;
}
@@ -1850,7 +1814,7 @@
// Error on end of text
case Ch('\0'):
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);
+ BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
// Other character, skip it
default:
@@ -1895,7 +1859,7 @@
Ch *name = text;
skip<node_name_pred, Flags>(text);
if (text == name)
- RAPIDXML_PARSE_ERROR("expected PI target", text);
+ BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected PI target", text);
pi->name(name, text - name);
// Skip whitespace between pi target and pi
@@ -1908,7 +1872,7 @@
while (text[0] != Ch('?') || text[1] != Ch('>'))
{
if (*text == Ch('\0'))
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);
+ BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
++text;
}
@@ -1931,7 +1895,7 @@
while (text[0] != Ch('?') || text[1] != Ch('>'))
{
if (*text == Ch('\0'))
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);
+ BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
++text;
}
text += 2; // Skip '?>'
@@ -2010,7 +1974,7 @@
while (text[0] != Ch(']') || text[1] != Ch(']') || text[2] != Ch('>'))
{
if (!text[0])
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);
+ BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
++text;
}
text += 3; // Skip ]]>
@@ -2022,7 +1986,7 @@
while (text[0] != Ch(']') || text[1] != Ch(']') || text[2] != Ch('>'))
{
if (!text[0])
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);
+ BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
++text;
}
@@ -2049,7 +2013,7 @@
Ch *name = text;
skip<node_name_pred, Flags>(text);
if (text == name)
- RAPIDXML_PARSE_ERROR("expected element name", text);
+ BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected element name", text);
element->name(name, text - name);
// Skip whitespace between element name and attributes or >
@@ -2068,11 +2032,11 @@
{
++text;
if (*text != Ch('>'))
- RAPIDXML_PARSE_ERROR("expected >", text);
+ BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected >", text);
++text;
}
else
- RAPIDXML_PARSE_ERROR("expected >", text);
+ BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected >", text);
// Place zero terminator after name
if (!(Flags & parse_no_string_terminators))
@@ -2159,7 +2123,7 @@
while (*text != Ch('>'))
{
if (*text == 0)
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);
+ BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
++text;
}
++text; // Skip '>'
@@ -2203,7 +2167,7 @@
Ch *closing_name = text;
skip<node_name_pred, Flags>(text);
if (!internal::compare(node->name(), node->name_size(), closing_name, text - closing_name, true))
- RAPIDXML_PARSE_ERROR("invalid closing tag name", text);
+ BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("invalid closing tag name", text);
}
else
{
@@ -2213,7 +2177,7 @@
// Skip remaining whitespace after node name
skip<whitespace_pred, Flags>(text);
if (*text != Ch('>'))
- RAPIDXML_PARSE_ERROR("expected >", text);
+ BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected >", text);
++text; // Skip '>'
return; // Node closed, finished parsing contents
}
@@ -2228,7 +2192,7 @@
// End of data - error
case Ch('\0'):
- RAPIDXML_PARSE_ERROR("unexpected end of data", text);
+ BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("unexpected end of data", text);
// Data node
default:
@@ -2251,7 +2215,7 @@
++text; // Skip first character of attribute name
skip<attribute_name_pred, Flags>(text);
if (text == name)
- RAPIDXML_PARSE_ERROR("expected attribute name", name);
+ BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected attribute name", name);
// Create new attribute
xml_attribute<Ch> *attribute = this->allocate_attribute();
@@ -2263,7 +2227,7 @@
// Skip =
if (*text != Ch('='))
- RAPIDXML_PARSE_ERROR("expected =", text);
+ BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected =", text);
++text;
// Add terminating zero after name
@@ -2276,7 +2240,7 @@
// Skip quote and remember if it was ' or "
Ch quote = *text;
if (quote != Ch('\'') && quote != Ch('"'))
- RAPIDXML_PARSE_ERROR("expected ' or \"", text);
+ BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected ' or \"", text);
++text;
// Extract attribute value and expand char refs in it
@@ -2292,7 +2256,7 @@
// Make sure that end quote is present
if (*text != quote)
- RAPIDXML_PARSE_ERROR("expected ' or \"", text);
+ BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR("expected ' or \"", text);
++text; // Skip quote
// Add terminating zero after value
@@ -2590,10 +2554,10 @@
}
//! \endcond
-}
+}}}}
// Undefine internal macros
-#undef RAPIDXML_PARSE_ERROR
+#undef BOOST_PROPERTY_TREE_RAPIDXML_PARSE_ERROR
// On MSVC, restore warnings state
#ifdef _MSC_VER
Modified: trunk/boost/property_tree/detail/xml_parser_read_rapidxml.hpp
==============================================================================
--- trunk/boost/property_tree/detail/xml_parser_read_rapidxml.hpp (original)
+++ trunk/boost/property_tree/detail/xml_parser_read_rapidxml.hpp 2010-02-17 13:10:46 EST (Wed, 17 Feb 2010)
@@ -21,49 +21,58 @@
{
template<class Ptree, class Ch>
- void read_xml_node(rapidxml::xml_node<Ch> *node, Ptree &pt, int flags)
+ void read_xml_node(detail::rapidxml::xml_node<Ch> *node,
+ Ptree &pt, int flags)
{
+ using namespace detail::rapidxml;
switch (node->type())
{
// Element nodes
- case rapidxml::node_element:
+ case node_element:
{
// Create node
- Ptree &pt_node = pt.push_back(std::make_pair(node->name(), Ptree()))->second;
-
+ Ptree &pt_node = pt.push_back(std::make_pair(node->name(),
+ Ptree()))->second;
+
// Copy attributes
if (node->first_attribute())
{
- Ptree &pt_attr_root = pt_node.push_back(std::make_pair(xmlattr<Ch>(), Ptree()))->second;
- for (rapidxml::xml_attribute<Ch> *attr = node->first_attribute(); attr; attr = attr->next_attribute())
+ Ptree &pt_attr_root = pt_node.push_back(
+ std::make_pair(xmlattr<Ch>(), Ptree()))->second;
+ for (xml_attribute<Ch> *attr = node->first_attribute();
+ attr; attr = attr->next_attribute())
{
- Ptree &pt_attr = pt_attr_root.push_back(std::make_pair(attr->name(), Ptree()))->second;
+ Ptree &pt_attr = pt_attr_root.push_back(
+ std::make_pair(attr->name(), Ptree()))->second;
pt_attr.data() = attr->value();
}
}
// Copy children
- for (rapidxml::xml_node<Ch> *child = node->first_node(); child; child = child->next_sibling())
+ for (xml_node<Ch> *child = node->first_node();
+ child; child = child->next_sibling())
read_xml_node(child, pt_node, flags);
}
break;
// Data nodes
- case rapidxml::node_data:
- case rapidxml::node_cdata:
+ case node_data:
+ case node_cdata:
{
if (flags & no_concat_text)
- pt.push_back(std::make_pair(xmltext<Ch>(), Ptree(node->value())));
+ pt.push_back(std::make_pair(xmltext<Ch>(),
+ Ptree(node->value())));
else
pt.data() += node->value();
}
break;
// Comment nodes
- case rapidxml::node_comment:
+ case node_comment:
{
if (!(flags & no_comments))
- pt.push_back(std::make_pair(xmlcomment<Ch>(), Ptree(node->value())));
+ pt.push_back(std::make_pair(xmlcomment<Ch>(),
+ Ptree(node->value())));
}
break;
@@ -81,6 +90,7 @@
const std::string &filename)
{
typedef typename Ptree::key_type::value_type Ch;
+ using namespace detail::rapidxml;
// Load data into vector
stream.unsetf(std::ios::skipws);
@@ -93,7 +103,6 @@
try {
// Parse using appropriate flags
- using namespace rapidxml;
const int f_tws = parse_normalize_whitespace
| parse_trim_whitespace;
const int f_c = parse_comment_nodes;
@@ -112,12 +121,13 @@
// Create ptree from nodes
Ptree local;
- for (rapidxml::xml_node<Ch> *child = doc.first_node(); child; child = child->next_sibling())
+ for (xml_node<Ch> *child = doc.first_node();
+ child; child = child->next_sibling())
read_xml_node(child, local, flags);
// Swap local and result ptrees
pt.swap(local);
- } catch (rapidxml::parse_error &e) {
+ } catch (parse_error &e) {
long line = static_cast<long>(
std::count(&v.front(), e.where<Ch>(), Ch('\n')) + 1);
BOOST_PROPERTY_TREE_THROW(
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk