|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r67018 - in trunk/boost/spirit/home: qi/directive support support/utree support/utree/detail
From: joel_at_[hidden]
Date: 2010-12-04 23:37:03
Author: djowel
Date: 2010-12-04 23:37:01 EST (Sat, 04 Dec 2010)
New Revision: 67018
URL: http://svn.boost.org/trac/boost/changeset/67018
Log:
added as_string directive as a synonym to "raw".
Text files modified:
trunk/boost/spirit/home/qi/directive/raw.hpp | 16 +++
trunk/boost/spirit/home/support/common_terminals.hpp | 1
trunk/boost/spirit/home/support/string_traits.hpp | 4
trunk/boost/spirit/home/support/utree/detail/utree_detail2.hpp | 6
trunk/boost/spirit/home/support/utree/utree.hpp | 6
trunk/boost/spirit/home/support/utree/utree_traits.hpp | 165 +++++++++++++++------------------------
6 files changed, 88 insertions(+), 110 deletions(-)
Modified: trunk/boost/spirit/home/qi/directive/raw.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/directive/raw.hpp (original)
+++ trunk/boost/spirit/home/qi/directive/raw.hpp 2010-12-04 23:37:01 EST (Sat, 04 Dec 2010)
@@ -30,12 +30,18 @@
template <>
struct use_directive<qi::domain, tag::raw> // enables raw
: mpl::true_ {};
+
+ template <>
+ struct use_directive<qi::domain, tag::as_string> // enables as_string
+ : mpl::true_ {};
}}
namespace boost { namespace spirit { namespace qi
{
using spirit::raw;
using spirit::raw_type;
+ using spirit::as_string;
+ using spirit::as_string_type;
template <typename Subject>
struct raw_directive : unary_parser<raw_directive<Subject> >
@@ -88,6 +94,16 @@
return result_type(subject);
}
};
+
+ template <typename Subject, typename Modifiers>
+ struct make_directive<tag::as_string, Subject, Modifiers>
+ {
+ typedef raw_directive<Subject> result_type;
+ result_type operator()(unused_type, Subject const& subject, unused_type) const
+ {
+ return result_type(subject);
+ }
+ };
}}}
namespace boost { namespace spirit { namespace traits
Modified: trunk/boost/spirit/home/support/common_terminals.hpp
==============================================================================
--- trunk/boost/spirit/home/support/common_terminals.hpp (original)
+++ trunk/boost/spirit/home/support/common_terminals.hpp 2010-12-04 23:37:01 EST (Sat, 04 Dec 2010)
@@ -71,6 +71,7 @@
( no_skip )
( omit )
( raw )
+ ( as_string )
( inf )
( eol )
( eoi )
Modified: trunk/boost/spirit/home/support/string_traits.hpp
==============================================================================
--- trunk/boost/spirit/home/support/string_traits.hpp (original)
+++ trunk/boost/spirit/home/support/string_traits.hpp 2010-12-04 23:37:01 EST (Sat, 04 Dec 2010)
@@ -187,7 +187,7 @@
{ return str.begin(); }
template <typename T, typename Str>
- inline typename Str::iterator
+ inline typename Str::iterator
get_begin(Str& str BOOST_PROTO_DISABLE_IF_IS_CONST(Str))
{ return str.begin(); }
@@ -196,7 +196,7 @@
{ return str.end(); }
template <typename T, typename Str>
- inline typename Str::iterator
+ inline typename Str::iterator
get_end(Str& str BOOST_PROTO_DISABLE_IF_IS_CONST(Str))
{ return str.end(); }
Modified: trunk/boost/spirit/home/support/utree/detail/utree_detail2.hpp
==============================================================================
--- trunk/boost/spirit/home/support/utree/detail/utree_detail2.hpp (original)
+++ trunk/boost/spirit/home/support/utree/detail/utree_detail2.hpp 2010-12-04 23:37:01 EST (Sat, 04 Dec 2010)
@@ -195,8 +195,8 @@
}
template<typename Iterator>
- typename node_iterator::difference_type
- distance_to(Iterator const& other) const
+ typename node_iterator::difference_type
+ distance_to(Iterator const& other) const
{
return std::distance(*this, node_iterator(other));
}
@@ -605,7 +605,7 @@
};
}}}
-namespace boost { namespace spirit
+namespace boost { namespace spirit
{
template <typename F>
stored_function<F>::stored_function(F f)
Modified: trunk/boost/spirit/home/support/utree/utree.hpp
==============================================================================
--- trunk/boost/spirit/home/support/utree/utree.hpp (original)
+++ trunk/boost/spirit/home/support/utree/utree.hpp 2010-12-04 23:37:01 EST (Sat, 04 Dec 2010)
@@ -32,17 +32,17 @@
# pragma warning(disable: 4244)
#endif
-namespace boost { namespace spirit
+namespace boost { namespace spirit
{
///////////////////////////////////////////////////////////////////////////
// all exceptions throw by utree are derived from utree_exception
struct utree_exception : std::exception {};
///////////////////////////////////////////////////////////////////////////
- // bad_type_exception is thrown whenever somebody calls a member function
+ // bad_type_exception is thrown whenever somebody calls a member function
// which applies to certain stored utree_type's only, but this precondition
// is violated as the utree instance holds some other type.
- struct bad_type_exception : utree_exception
+ struct bad_type_exception : utree_exception
{
virtual const char* what() const throw()
{
Modified: trunk/boost/spirit/home/support/utree/utree_traits.hpp
==============================================================================
--- trunk/boost/spirit/home/support/utree/utree_traits.hpp (original)
+++ trunk/boost/spirit/home/support/utree/utree_traits.hpp 2010-12-04 23:37:01 EST (Sat, 04 Dec 2010)
@@ -90,7 +90,7 @@
///////////////////////////////////////////////////////////////////////////
// this specialization is required to disambiguate the specializations
- // related to utree
+ // related to utree
template <>
struct assign_to_attribute_from_value<utree, utree>
{
@@ -102,130 +102,91 @@
};
///////////////////////////////////////////////////////////////////////////
- // push_back support for utree allows concatenation of strings
- // (utree strings are immutable)
- template <typename T>
- struct push_back_container<utree, T>
+ // this specialization tells Spirit.Qi to allow assignment to an utree from
+ // generic iterators
+ template <typename Iterator>
+ struct assign_to_attribute_from_iterators<utree, Iterator>
{
- ///////////////////////////////////////////////////////////////////////
- template <typename T2>
- static void push_to_nil(utree& c, T2 const& val)
- {
- c.push_back(val);
- }
-
- static void push_to_nil(utree& c, utree const& val)
+ static void
+ call(Iterator const& first, Iterator const& last, utree& attr)
{
- c = val;
+ attr.assign(first, last);
}
+ };
- static void push_to_nil(utree& c, char val)
- {
- c = utree(val);
- }
+ ///////////////////////////////////////////////////////////////////////////
+ // this specialization tells Spirit.Qi to allow assignment to a utree from
+ // string iterators
+ template <typename Iterator>
+ struct assign_to_attribute_from_string_iterators
+ {
+ typedef basic_string<
+ boost::iterator_range<Iterator>,
+ utree_type::string_type>
+ range;
- static void push_to_nil(utree& c, std::string const& val)
+ static void
+ call(Iterator first, Iterator last, utree& attr)
{
- c = utree(val);
+ utree rng(range(first, last));
+ attr.swap(rng);
}
+ };
- ///////////////////////////////////////////////////////////////////////
- template <typename T2>
- static void push_to_string(utree& c, T2 const& val)
- {
- utree ut;
- ut.push_back(c);
- ut.push_back(val);
- c.swap(ut);
- }
+ template <>
+ struct assign_to_attribute_from_iterators<utree, std::basic_string<char>::iterator>
+ : assign_to_attribute_from_string_iterators<std::basic_string<char>::iterator>
+ {};
- static void push_to_string(utree& c, utree const& val)
- {
- if (val.which() != utree_type::string_type)
- {
- utree ut;
- ut.push_back(c);
- ut.push_back(val);
- c.swap(ut);
- }
- else
- {
- utf8_string_range a = c.get<utf8_string_range>();
- utf8_string_range b = val.get<utf8_string_range>();
- c = (std::string(a.begin(), a.end())
- + std::string(b.begin(), b.end()));
- }
- }
+ template <>
+ struct assign_to_attribute_from_iterators<utree, std::basic_string<wchar_t>::iterator>
+ : assign_to_attribute_from_string_iterators<std::basic_string<wchar_t>::iterator>
+ {};
- static void push_to_string(utree& c, std::string const& val)
- {
- utf8_string_range rng = c.get<utf8_string_range>();
- c = (std::string(rng.begin(), rng.end()) + val);
- }
+ template <>
+ struct assign_to_attribute_from_iterators<utree, std::basic_string<char>::const_iterator>
+ : assign_to_attribute_from_string_iterators<std::basic_string<char>::const_iterator>
+ {};
- static void push_to_string(utree& c, char val)
- {
- utf8_string_range rng = c.get<utf8_string_range>();
- c = (std::string(rng.begin(), rng.end()) + val);
- }
+ template <>
+ struct assign_to_attribute_from_iterators<utree, std::basic_string<wchar_t>::const_iterator>
+ : assign_to_attribute_from_string_iterators<std::basic_string<wchar_t>::const_iterator>
+ {};
- ///////////////////////////////////////////////////////////////////////
- template <typename T2>
- static void push_to_string_list(utree& c, T2 const& val)
- {
- c.push_back(val);
- }
+ template <>
+ struct assign_to_attribute_from_iterators<utree, char const*>
+ : assign_to_attribute_from_string_iterators<char const*>
+ {};
- static void push_to_string_list(utree& c, utree const& val)
- {
- utree& b = c.back();
- if (b.which() == utree_type::string_type &&
- val.which() == utree_type::string_type)
- {
- push_to_string(b, val);
- }
- else
- {
- c.push_back(val);
- }
- }
+ template <>
+ struct assign_to_attribute_from_iterators<utree, char*>
+ : assign_to_attribute_from_string_iterators<char*>
+ {};
- static void push_to_string_list(utree& c, std::string const& val)
- {
- utree& b = c.back();
- if (b.which() == utree_type::string_type)
- push_to_string(b, val);
- else
- c.push_back(val);
- }
+ template <>
+ struct assign_to_attribute_from_iterators<utree, wchar_t const*>
+ : assign_to_attribute_from_string_iterators<wchar_t const*>
+ {};
- static void push_to_string_list(utree& c, char val)
- {
- utree& b = c.back();
- if (b.which() == utree_type::string_type)
- push_to_string(b, val);
- else
- c.push_back(val);
- }
+ template <>
+ struct assign_to_attribute_from_iterators<utree, wchar_t*>
+ : assign_to_attribute_from_string_iterators<wchar_t*>
+ {};
- ///////////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////////////
+ // push_back support for utree allows concatenation of strings
+ // (utree strings are immutable)
+ template <typename T>
+ struct push_back_container<utree, T>
+ {
static bool call(utree& c, T const& val)
{
switch (c.which())
{
case utree_type::nil_type:
- {
- push_to_nil(c, val);
- break;
- }
case utree_type::list_type:
{
- push_to_string_list(c, val);
- break;
- }
- case utree_type::string_type:
- {
- push_to_string(c, val);
+ c.push_back(val);
break;
}
default:
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