Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64229 - trunk/boost/spirit/home/support
From: hartmut.kaiser_at_[hidden]
Date: 2010-07-21 15:17:51


Author: hkaiser
Date: 2010-07-21 15:17:50 EDT (Wed, 21 Jul 2010)
New Revision: 64229
URL: http://svn.boost.org/trac/boost/changeset/64229

Log:
Spirit: fixed debug output for variants
Text files modified:
   trunk/boost/spirit/home/support/attributes.hpp | 76 +++++++++++++++++++++++++++++----------
   trunk/boost/spirit/home/support/attributes_fwd.hpp | 2
   2 files changed, 57 insertions(+), 21 deletions(-)

Modified: trunk/boost/spirit/home/support/attributes.hpp
==============================================================================
--- trunk/boost/spirit/home/support/attributes.hpp (original)
+++ trunk/boost/spirit/home/support/attributes.hpp 2010-07-21 15:17:50 EDT (Wed, 21 Jul 2010)
@@ -815,57 +815,88 @@
             Out& out;
             mutable bool is_first;
         };
+
+ // print elements in a variant
+ template <typename Out>
+ struct print_visitor : static_visitor<>
+ {
+ print_visitor(Out& out) : out(out) {}
+
+ template <typename T>
+ void operator()(T const& val) const
+ {
+ print_attribute(out, val);
+ }
+
+ Out& out;
+ };
     }
 
     template <typename Out, typename T, typename Enable>
     struct print_attribute_debug
     {
- // for stl container data types
+ // for plain data types
         template <typename T_>
- static void call_impl(Out& out, T_ const& val, mpl::true_)
+ static void call_impl3(Out& out, T_ const& val, mpl::false_)
         {
- out << '[';
- if (!val.empty())
- {
- for (typename T_::const_iterator i = val.begin(); i != val.end(); ++i)
- {
- if (i != val.begin())
- out << ", ";
- print_attribute(out, *i);
- }
+ out << val;
+ }
 
- }
+ // for fusion data types
+ template <typename T_>
+ static void call_impl3(Out& out, T_ const& val, mpl::true_)
+ {
+ out << '[';
+ fusion::for_each(val, detail::print_fusion_sequence<Out>(out));
             out << ']';
         }
 
- // for non-fusion data types
+ // non-stl container
         template <typename T_>
         static void call_impl2(Out& out, T_ const& val, mpl::false_)
         {
- out << val;
+ call_impl3(out, val, fusion::traits::is_sequence<T_>());
         }
 
- // for fusion data types
+ // stl container
         template <typename T_>
         static void call_impl2(Out& out, T_ const& val, mpl::true_)
         {
             out << '[';
- fusion::for_each(val, detail::print_fusion_sequence<Out>(out));
+ if (!traits::is_empty(val))
+ {
+ bool first = true;
+ typename container_iterator<T_ const>::type iend = traits::end(val);
+ for (typename container_iterator<T_ const>::type i = traits::begin(val);
+ !traits::compare(i, iend); traits::next(i))
+ {
+ if (!first)
+ out << ", ";
+ first = false;
+ print_attribute(out, *i);
+ }
+ }
             out << ']';
         }
 
- // for non-stl container data types
+ // for variant types
         template <typename T_>
         static void call_impl(Out& out, T_ const& val, mpl::false_)
         {
- call_impl2(out, val, fusion::traits::is_sequence<T_>());
+ apply_visitor(detail::print_visitor<Out>(out), val);
+ }
+
+ // for non-variant types
+ template <typename T_>
+ static void call_impl(Out& out, T_ const& val, mpl::true_)
+ {
+ call_impl2(out, val, is_container<T_>());
         }
 
         // main entry point
         static void call(Out& out, T const& val)
         {
- call_impl(out, val
- , mpl::and_<is_container<T>, not_is_variant<T, void> >());
+ call_impl(out, val, not_is_variant<T>());
         }
     };
 
@@ -884,6 +915,11 @@
             out << "<empty>";
     }
 
+ template <typename Out>
+ inline void print_attribute(Out& out, unused_type)
+ {
+ }
+
     ///////////////////////////////////////////////////////////////////////////
     // generate debug output for lookahead token (character) stream
     namespace detail

Modified: trunk/boost/spirit/home/support/attributes_fwd.hpp
==============================================================================
--- trunk/boost/spirit/home/support/attributes_fwd.hpp (original)
+++ trunk/boost/spirit/home/support/attributes_fwd.hpp 2010-07-21 15:17:50 EDT (Wed, 21 Jul 2010)
@@ -126,7 +126,7 @@
     ///////////////////////////////////////////////////////////////////////////
     // Determine, whether T is a variant like type
     ///////////////////////////////////////////////////////////////////////////
- template <typename T, typename Domain>
+ template <typename T, typename Domain = void>
     struct not_is_variant;
 
     ///////////////////////////////////////////////////////////////////////////


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