Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r67057 - in trunk/boost/spirit/home: qi qi/directive support support/utree support/utree/detail
From: joel_at_[hidden]
Date: 2010-12-05 23:04:31


Author: djowel
Date: 2010-12-05 23:04:25 EST (Sun, 05 Dec 2010)
New Revision: 67057
URL: http://svn.boost.org/trac/boost/changeset/67057

Log:
correct as_string behavior
Text files modified:
   trunk/boost/spirit/home/qi/directive.hpp | 1
   trunk/boost/spirit/home/qi/directive/raw.hpp | 16 ----------
   trunk/boost/spirit/home/support/common_terminals.hpp | 1
   trunk/boost/spirit/home/support/utree/detail/utree_detail1.hpp | 1
   trunk/boost/spirit/home/support/utree/detail/utree_detail2.hpp | 60 ++++++++++++++++++++++++++++++++++----
   trunk/boost/spirit/home/support/utree/utree.hpp | 1
   trunk/boost/spirit/home/support/utree/utree_traits.hpp | 61 ---------------------------------------
   7 files changed, 58 insertions(+), 83 deletions(-)

Modified: trunk/boost/spirit/home/qi/directive.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/directive.hpp (original)
+++ trunk/boost/spirit/home/qi/directive.hpp 2010-12-05 23:04:25 EST (Sun, 05 Dec 2010)
@@ -11,6 +11,7 @@
 #pragma once
 #endif
 
+#include <boost/spirit/home/qi/directive/as_string.hpp>
 #include <boost/spirit/home/qi/directive/encoding.hpp>
 #include <boost/spirit/home/qi/directive/hold.hpp>
 #include <boost/spirit/home/qi/directive/lexeme.hpp>

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-05 23:04:25 EST (Sun, 05 Dec 2010)
@@ -30,18 +30,12 @@
     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> >
@@ -94,16 +88,6 @@
             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-05 23:04:25 EST (Sun, 05 Dec 2010)
@@ -72,6 +72,7 @@
         ( omit )
         ( raw )
         ( as_string )
+ ( as_wstring )
         ( inf )
         ( eol )
         ( eoi )

Modified: trunk/boost/spirit/home/support/utree/detail/utree_detail1.hpp
==============================================================================
--- trunk/boost/spirit/home/support/utree/detail/utree_detail1.hpp (original)
+++ trunk/boost/spirit/home/support/utree/detail/utree_detail1.hpp 2010-12-05 23:04:25 EST (Sun, 05 Dec 2010)
@@ -16,6 +16,7 @@
     struct visit_impl;
 
     struct index_impl;
+ struct assign_impl;
 
     template <typename T>
     struct get_impl;

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-05 23:04:25 EST (Sun, 05 Dec 2010)
@@ -17,6 +17,7 @@
 #include <boost/type_traits/is_pointer.hpp>
 #include <boost/utility/enable_if.hpp>
 #include <boost/throw_exception.hpp>
+#include <boost/iterator/iterator_traits.hpp>
 
 namespace boost { namespace spirit { namespace detail
 {
@@ -972,18 +973,63 @@
             insert(pos, *first++);
     }
 
+ namespace detail
+ {
+ struct assign_impl
+ {
+ template <typename Iter>
+ static void dispatch(utree& ut, Iter first, Iter last)
+ {
+ ut.ensure_list_type();
+ ut.clear();
+ while (first != last)
+ {
+ ut.push_back(*first);
+ ++first;
+ }
+ }
+
+ template <typename Iter>
+ static void dispatch_string(utree& ut, Iter first, Iter last)
+ {
+ ut.free();
+ ut.s.construct(first, last);
+ ut.set_type(utree_type::string_type);
+ }
+
+ static void dispatch(utree& ut,
+ std::basic_string<char>::iterator first,
+ std::basic_string<char>::iterator last)
+ {
+ dispatch_string(ut, first, last);
+ }
+
+ static void dispatch(utree& ut,
+ std::basic_string<char>::const_iterator first,
+ std::basic_string<char>::const_iterator last)
+ {
+ dispatch_string(ut, first, last);
+ }
+
+ static void dispatch(utree& ut, char const* first, char const* last)
+ {
+ dispatch_string(ut, first, last);
+ }
+
+ template <typename Iter>
+ static void call(utree& ut, Iter first, Iter last)
+ {
+ dispatch(ut, first, last);
+ }
+ };
+ }
+
     template <typename Iter>
     inline void utree::assign(Iter first, Iter last)
     {
         if (get_type() == type::reference_type)
             return p->assign(first, last);
- ensure_list_type();
- clear();
- while (first != last)
- {
- push_back(*first);
- ++first;
- }
+ detail::assign_impl::call(*this, first, last);
     }
 
     inline void utree::clear()

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-05 23:04:25 EST (Sun, 05 Dec 2010)
@@ -403,6 +403,7 @@
         template <typename UTreeX, typename UTreeY>
         friend struct detail::visit_impl;
         friend struct detail::index_impl;
+ friend struct detail::assign_impl;
 
         template <typename T>
         friend struct detail::get_impl;

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-05 23:04:25 EST (Sun, 05 Dec 2010)
@@ -115,65 +115,6 @@
     };
 
     ///////////////////////////////////////////////////////////////////////////
- // 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
- call(Iterator first, Iterator last, utree& attr)
- {
- utree rng(range(first, last));
- attr.swap(rng);
- }
- };
-
- template <>
- struct assign_to_attribute_from_iterators<utree, std::basic_string<char>::iterator>
- : assign_to_attribute_from_string_iterators<std::basic_string<char>::iterator>
- {};
-
- 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>
- {};
-
- 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>
- {};
-
- 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 <>
- struct assign_to_attribute_from_iterators<utree, char const*>
- : assign_to_attribute_from_string_iterators<char const*>
- {};
-
- template <>
- struct assign_to_attribute_from_iterators<utree, char*>
- : assign_to_attribute_from_string_iterators<char*>
- {};
-
- template <>
- struct assign_to_attribute_from_iterators<utree, wchar_t const*>
- : assign_to_attribute_from_string_iterators<wchar_t const*>
- {};
-
- 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>
@@ -595,7 +536,7 @@
     };
 
     ///////////////////////////////////////////////////////////////////////////
- // this specialization is used whenever a utree is passed to a rule as part
+ // this specialization is used whenever a utree is passed to a rule as part
     // of a sequence
     template <typename Iterator>
     struct transform_attribute<


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