Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r67606 - in trunk: boost/spirit/home/support boost/spirit/home/support/utree libs/spirit/test/qi
From: admin_at_[hidden]
Date: 2011-01-03 00:24:13


Author: wash
Date: 2011-01-03 00:24:09 EST (Mon, 03 Jan 2011)
New Revision: 67606
URL: http://svn.boost.org/trac/boost/changeset/67606

Log:
Renamed the "get_c_string_impl" Spirit CP to "extract_c_string"; changed utree
tests for mixed expectation/sequence operators. Added spirit::result_of::get_begin
and spirit::result_of::get_end to string_traits.hpp.

Text files modified:
   trunk/boost/spirit/home/support/string_traits.hpp | 75 ++++++++++++++++++++++++++++-----------
   trunk/boost/spirit/home/support/utree/utree_traits.hpp | 9 ++--
   trunk/libs/spirit/test/qi/utree1.cpp | 47 +++++++++++++++++++++++++
   3 files changed, 106 insertions(+), 25 deletions(-)

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 2011-01-03 00:24:09 EST (Mon, 03 Jan 2011)
@@ -16,7 +16,9 @@
 #include <string>
 #include <boost/mpl/bool.hpp>
 #include <boost/mpl/identity.hpp>
+#include <boost/mpl/if.hpp>
 #include <boost/proto/proto_fwd.hpp>
+#include <boost/type_traits/is_const.hpp>
 #if defined(__GNUC__) && (__GNUC__ < 4)
 #include <boost/type_traits/add_const.hpp>
 #endif
@@ -124,10 +126,10 @@
     // Get the C string from a string
     ///////////////////////////////////////////////////////////////////////////
     template <typename String>
- struct get_c_string_impl;
+ struct extract_c_string;
 
     template <typename String>
- struct get_c_string_impl
+ struct extract_c_string
     {
         typedef typename char_type_of<String>::type char_type;
 
@@ -146,36 +148,36 @@
     
     // Forwarder that strips const
     template <typename T>
- struct get_c_string_impl<T const>
+ struct extract_c_string<T const>
     {
- static typename get_c_string_impl<T>::char_type const* call (T const str)
+ static typename extract_c_string<T>::char_type const* call (T const str)
         {
- return get_c_string_impl<T>::call(str);
+ return extract_c_string<T>::call(str);
         }
     };
 
     // Forwarder that strips references
     template <typename T>
- struct get_c_string_impl<T&>
+ struct extract_c_string<T&>
     {
- static typename get_c_string_impl<T>::char_type const* call (T& str)
+ static typename extract_c_string<T>::char_type const* call (T& str)
         {
- return get_c_string_impl<T>::call(str);
+ return extract_c_string<T>::call(str);
         }
     };
 
     // Forwarder that strips const references
     template <typename T>
- struct get_c_string_impl<T const&>
+ struct extract_c_string<T const&>
     {
- static typename get_c_string_impl<T>::char_type const* call (T const& str)
+ static typename extract_c_string<T>::char_type const* call (T const& str)
         {
- return get_c_string_impl<T>::call(str);
+ return extract_c_string<T>::call(str);
         }
     };
 
     template <typename T, typename Traits, typename Allocator>
- struct get_c_string_impl<std::basic_string<T, Traits, Allocator> >
+ struct extract_c_string<std::basic_string<T, Traits, Allocator> >
     {
         typedef T char_type;
 
@@ -193,31 +195,31 @@
     };
     
     template <typename T>
- typename get_c_string_impl<T*>::char_type const*
+ typename extract_c_string<T*>::char_type const*
     get_c_string (T* str)
     {
- return get_c_string_impl<T*>::call(str);
+ return extract_c_string<T*>::call(str);
     }
 
     template <typename T>
- typename get_c_string_impl<T const*>::char_type const*
+ typename extract_c_string<T const*>::char_type const*
     get_c_string (T const* str)
     {
- return get_c_string_impl<T const*>::call(str);
+ return extract_c_string<T const*>::call(str);
     }
     
     template <typename String>
- typename get_c_string_impl<String>::char_type const*
+ typename extract_c_string<String>::char_type const*
     get_c_string (String& str)
     {
- return get_c_string_impl<String>::call(str);
+ return extract_c_string<String>::call(str);
     }
 
     template <typename String>
- typename get_c_string_impl<String>::char_type const*
+ typename extract_c_string<String>::char_type const*
     get_c_string (String const& str)
     {
- return get_c_string_impl<String>::call(str);
+ return extract_c_string<String>::call(str);
     }
 
     ///////////////////////////////////////////////////////////////////////////
@@ -297,6 +299,37 @@
     inline typename disable_if<is_container<Str>
       , T const*>::type get_end(Str const& str)
     { return get_end(get_begin<T>(str)); }
-}}}
+}
+
+namespace result_of
+{
+ template <typename Char, typename T, typename Enable = void>
+ struct get_begin
+ {
+ typedef typename traits::char_type_of<T>::type char_type;
+
+ typedef typename mpl::if_<
+ is_const<char_type>
+ , char_type const
+ , char_type
+ >::type* type;
+ };
+
+ template <typename Char, typename Str>
+ struct get_begin<Char, Str
+ , typename enable_if<traits::is_container<Str> >::type>
+ {
+ typedef typename mpl::if_<
+ is_const<Str>
+ , typename Str::const_iterator
+ , typename Str::iterator
+ >::type type;
+ };
+
+ template <typename Char, typename T>
+ struct get_end : get_begin<Char, T> {};
+}
+
+}}
 
 #endif

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 2011-01-03 00:24:09 EST (Mon, 03 Jan 2011)
@@ -78,11 +78,12 @@
     ///////////////////////////////////////////////////////////////////////////
     // these specializations extract a c string from a utree typed string
     template <typename String>
- struct get_c_string_impl;
+ struct extract_c_string;
 
     template <typename T, utree_type::info I>
- struct get_c_string_impl<spirit::basic_string<iterator_range<T const*>, I> >
- {
+ struct extract_c_string<
+ spirit::basic_string<iterator_range<T const*>, I>
+ > {
         typedef T char_type;
 
         typedef spirit::basic_string<iterator_range<T const*>, I> string;
@@ -99,7 +100,7 @@
     };
     
     template <utree_type::info I>
- struct get_c_string_impl<spirit::basic_string<std::string, I> >
+ struct extract_c_string<spirit::basic_string<std::string, I> >
     {
         typedef char char_type;
 

Modified: trunk/libs/spirit/test/qi/utree1.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/utree1.cpp (original)
+++ trunk/libs/spirit/test/qi/utree1.cpp 2011-01-03 00:24:09 EST (Mon, 03 Jan 2011)
@@ -134,8 +134,55 @@
 
         BOOST_TEST(test_attr("0.5foo5", r3, ut) &&
             ut.which() == utree_type::list_type && check(ut, "( 0.5 \"foo\" 5 )"));
+ }
+
+ {
+ utree ut;
+
+ rule<char const*, utree()> r1 = char_;
+ rule<char const*, utree::list_type()> r2 = double_;
+ rule<char const*, utree::list_type()> r3 = char_;
+
+ BOOST_TEST(test_attr("a25.5b", r1 >> r2 >> r3, ut));
+ BOOST_TEST(ut.which() == utree_type::list_type);
+ BOOST_TEST(check(ut, "( \"a\" ( 25.5 ) ( \"b\" ) )"));
+ ut.clear();
+
+ BOOST_TEST(test_attr("a25.5b", r3 >> r2 >> r1, ut));
+ BOOST_TEST(ut.which() == utree_type::list_type);
+ BOOST_TEST(check(ut, "( ( \"a\" ) ( 25.5 ) \"b\" )"));
+ ut.clear();
+
+ BOOST_TEST(test_attr("a25.5b", char_ >> r2 >> r3, ut));
+ BOOST_TEST(ut.which() == utree_type::list_type);
+ BOOST_TEST(check(ut, "( \"a\" ( 25.5 ) ( \"b\" ) )"));
+ ut.clear();
+
+ BOOST_TEST(test_attr("a25.5b", r3 >> r2 >> char_, ut));
+ BOOST_TEST(ut.which() == utree_type::list_type);
+ BOOST_TEST(check(ut, "( ( \"a\" ) ( 25.5 ) \"b\" )"));
         ut.clear();
+
+ BOOST_TEST(test_attr("a25.5b", r1 > r2 >> r3, ut));
+ BOOST_TEST(ut.which() == utree_type::list_type);
+ BOOST_TEST(check(ut, "( \"a\" ( ( 25.5 ) ( \"b\" ) ) )"));
+ ut.clear();
+
+ BOOST_TEST(test_attr("a25.5b", r3 >> r2 > r1, ut));
+ BOOST_TEST(ut.which() == utree_type::list_type);
+ BOOST_TEST(check(ut, "( ( ( \"a\" ) ( 25.5 ) ) \"b\" )"));
+ ut.clear();
+
+ BOOST_TEST(test_attr("a25.5b", char_ > r2 >> r3, ut));
+ BOOST_TEST(ut.which() == utree_type::list_type);
+ BOOST_TEST(check(ut, "( \"a\" ( ( 25.5 ) ( \"b\" ) ) )"));
+ ut.clear();
+
+ BOOST_TEST(test_attr("a25.5b", r3 >> r2 > char_, ut));
+ BOOST_TEST(ut.which() == utree_type::list_type);
+ BOOST_TEST(check(ut, "( ( ( \"a\" ) ( 25.5 ) ) \"b\" )"));
     }
 
     return boost::report_errors();
 }
+


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