Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r67692 - in trunk/boost/spirit/home/support/utree: . detail
From: hartmut.kaiser_at_[hidden]
Date: 2011-01-05 17:35:00


Author: hkaiser
Date: 2011-01-05 17:34:51 EST (Wed, 05 Jan 2011)
New Revision: 67692
URL: http://svn.boost.org/trac/boost/changeset/67692

Log:
Spirit: utree: got rid of static class members, fixed another use case
Text files modified:
   trunk/boost/spirit/home/support/utree/detail/utree_detail2.hpp | 8 +++---
   trunk/boost/spirit/home/support/utree/utree.hpp | 16 +++++-------
   trunk/boost/spirit/home/support/utree/utree_traits.hpp | 49 ++++++++++++++++++++++++++++++---------
   3 files changed, 48 insertions(+), 25 deletions(-)

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 2011-01-05 17:34:51 EST (Wed, 05 Jan 2011)
@@ -460,10 +460,10 @@
                     break;
 
                 case type::invalid_type:
- return f(utree::invalid);
+ return f(invalid);
 
                 case type::nil_type:
- return f(utree::nil);
+ return f(nil);
 
                 case type::bool_type:
                     return f(x.b);
@@ -523,10 +523,10 @@
                     break;
 
                 case type::invalid_type:
- return visit_impl::apply(y, detail::bind(f, utree::invalid));
+ return visit_impl::apply(y, detail::bind(f, invalid));
 
                 case type::nil_type:
- return visit_impl::apply(y, detail::bind(f, utree::nil));
+ return visit_impl::apply(y, detail::bind(f, nil));
 
                 case type::bool_type:
                     return visit_impl::apply(y, detail::bind(f, x.b));

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 2011-01-05 17:34:51 EST (Wed, 05 Jan 2011)
@@ -251,18 +251,15 @@
         ///////////////////////////////////////////////////////////////////////
         // The invalid type
         struct invalid_type {};
- static invalid_type const invalid;
 
         ///////////////////////////////////////////////////////////////////////
         // The nil type
         struct nil_type {};
- static nil_type const nil;
 
         ///////////////////////////////////////////////////////////////////////
         // The list type, this can be used to initialize an utree to hold an
         // empty list
         struct list_type;
- static list_type const list;
 
         //[utree_container_types
         typedef utree value_type;
@@ -297,7 +294,7 @@
         // This constructs an `invalid_type` node. When used in places
         // where a boost::optional is expected (i.e. as an attribute for the
         // optional component), this represents the 'empty' state.
- utree(invalid_type = invalid);
+ utree(invalid_type = invalid_type());
 
         // This initializes a `nil_type` node, which represents a valid,
         // 'initialized empty' utree (different from invalid_type!).
@@ -542,14 +539,15 @@
 
     ///////////////////////////////////////////////////////////////////////////
     // predefined instances for singular types
- utree::invalid_type const utree::invalid = {};
- utree::nil_type const utree::nil = {};
- utree::list_type const utree::list = utree::list_type();
+ utree::invalid_type const invalid = {};
+ utree::nil_type const nil = {};
+ utree::list_type const empty_list = utree::list_type();
 
     ///////////////////////////////////////////////////////////////////////////
     //[utree_scope
- class scope : public boost::iterator_range<utree*> {
- public:
+ class scope : public boost::iterator_range<utree*>
+ {
+ public:
         scope(utree* first = 0,
               utree* last = 0,
               scope const* parent = 0)

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-05 17:34:51 EST (Wed, 05 Jan 2011)
@@ -170,7 +170,7 @@
 
             // make sure the attribute is a list, at least an empty one
             if (attr.empty())
- attr = utree::list;
+ attr = empty_list;
 
             iterator_type end = traits::end(val);
             for (iterator_type i = traits::begin(val); i != end; traits::next(i))
@@ -194,7 +194,7 @@
             if (attr.empty()) {
                 attr = val;
             }
- else if (val.which() == utree_type::list_type) {
+ else if (traits::which(val) == utree_type::list_type) {
                 typedef utree::const_iterator iterator_type;
 
                 iterator_type end = traits::end(val);
@@ -462,7 +462,7 @@
         static void call(utree& ut)
         {
             if (traits::which(ut) != utree_type::list_type)
- ut = utree::list;
+ ut = empty_list;
         }
     };
 
@@ -502,13 +502,6 @@
                 mpl::not_<is_same<utree::list_type, Attribute> >,
                 traits::is_container<Attribute> >
         {};
-
- template <typename Attribute>
- struct attribute_is_not_utree
- : mpl::and_<
- mpl::not_<is_same<utree, Attribute> >,
- traits::is_container<Attribute> >
- {};
     }
 
     template <
@@ -534,6 +527,38 @@
     template <
         typename IteratorA, typename IteratorB, typename Context
       , typename T1, typename T2, typename T3, typename T4>
+ struct handles_container<qi::rule<IteratorA, T1, T2, T3, T4>
+ , utree::list_type, Context, IteratorB>
+ : detail::attribute_is_not_utree_list<typename attribute_of<
+ qi::rule<IteratorA, T1, T2, T3, T4>, Context, IteratorB
+ >::type>
+ {};
+
+ template <
+ typename IteratorA, typename IteratorB, typename Context
+ , typename T1, typename T2, typename T3, typename T4>
+ struct handles_container<qi::grammar<IteratorA, T1, T2, T3, T4>
+ , utree::list_type, Context, IteratorB>
+ : detail::attribute_is_not_utree_list<typename attribute_of<
+ qi::grammar<IteratorA, T1, T2, T3, T4>, Context, IteratorB
+ >::type>
+ {};
+
+ ///////////////////////////////////////////////////////////////////////////
+ namespace detail
+ {
+ // checks if the attr is utree
+ template <typename Attribute>
+ struct attribute_is_not_utree
+ : mpl::and_<
+ mpl::not_<is_same<utree, Attribute> >,
+ traits::is_container<Attribute> >
+ {};
+ }
+
+ template <
+ typename IteratorA, typename IteratorB, typename Context
+ , typename T1, typename T2, typename T3, typename T4>
     struct handles_container<karma::rule<IteratorA, T1, T2, T3, T4>
       , utree, Context, IteratorB>
       : detail::attribute_is_not_utree<typename attribute_of<
@@ -947,7 +972,7 @@
 
         static type pre(utree const& t)
         {
- return utree::nil;
+ return nil;
         }
     };
 
@@ -1059,7 +1084,7 @@
         typedef utree const& type;
         static utree const& pre(utree const& val)
         {
- if (val.which() == utree_type::list_type && 1 == val.size())
+ if (traits::which(val) == utree_type::list_type && 1 == val.size())
                 return val.front();
             return val;
         }


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