Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63673 - in branches/release: . boost boost/algorithm/string boost/archive boost/bimap boost/detail boost/filesystem boost/functional/hash boost/gil boost/graph boost/integer boost/interprocess boost/intrusive boost/iostreams boost/msm boost/numeric/ublas boost/program_options boost/property_tree boost/python boost/range boost/serialization boost/signals boost/signals2 boost/spirit boost/spirit/home boost/spirit/home/karma boost/spirit/home/karma/detail boost/spirit/home/karma/operator boost/spirit/home/support boost/statechart boost/system boost/thread boost/utility boost/uuid boost/variant boost/wave libs libs/array/test libs/bimap libs/filesystem libs/functional/hash libs/graph_parallel libs/integer libs/interprocess libs/intrusive libs/mpl/doc/refmanual libs/mpl/doc/src/refmanual libs/msm libs/property_tree libs/python libs/range libs/range/doc libs/serialization libs/signals libs/signals2 libs/spirit libs/spirit/classic/example libs/spirit/doc libs/spirit/example libs/spirit/phoenix libs/spirit/test libs/spirit/test/qi libs/statechart libs/static_assert libs/system libs/thread libs/timer libs/utility libs/utility/swap/test libs/uuid libs/wave more status tools tools/bcp tools/build/v2 tools/build/v2/tools tools/jam tools/regression tools/release tools/wave
From: hartmut.kaiser_at_[hidden]
Date: 2010-07-05 15:55:03


Author: hkaiser
Date: 2010-07-05 15:55:02 EDT (Mon, 05 Jul 2010)
New Revision: 63673
URL: http://svn.boost.org/trac/boost/changeset/63673

Log:
Spirit: merged missing revision from trunk
Properties modified:
   branches/release/ (props changed)
   branches/release/INSTALL (props changed)
   branches/release/LICENSE_1_0.txt (props changed)
   branches/release/boost/ (props changed)
   branches/release/boost-build.jam (props changed)
   branches/release/boost.css (props changed)
   branches/release/boost.png (props changed)
   branches/release/boost/algorithm/string/ (props changed)
   branches/release/boost/archive/ (props changed)
   branches/release/boost/bimap/ (props changed)
   branches/release/boost/detail/ (props changed)
   branches/release/boost/filesystem/ (props changed)
   branches/release/boost/functional/hash/ (props changed)
   branches/release/boost/gil/ (props changed)
   branches/release/boost/graph/ (props changed)
   branches/release/boost/integer/ (props changed)
   branches/release/boost/interprocess/ (props changed)
   branches/release/boost/intrusive/ (props changed)
   branches/release/boost/iostreams/ (props changed)
   branches/release/boost/msm/ (props changed)
   branches/release/boost/numeric/ublas/ (props changed)
   branches/release/boost/program_options/ (props changed)
   branches/release/boost/property_tree/ (props changed)
   branches/release/boost/python/ (props changed)
   branches/release/boost/range/ (props changed)
   branches/release/boost/serialization/ (props changed)
   branches/release/boost/serialization/factory.hpp (props changed)
   branches/release/boost/signals/ (props changed)
   branches/release/boost/signals2/ (props changed)
   branches/release/boost/spirit/ (props changed)
   branches/release/boost/spirit/home/ (props changed)
   branches/release/boost/spirit/home/karma/ (props changed)
   branches/release/boost/spirit/home/support/attributes.hpp (contents, props changed)
   branches/release/boost/statechart/ (props changed)
   branches/release/boost/system/ (props changed)
   branches/release/boost/thread/ (props changed)
   branches/release/boost/thread.hpp (props changed)
   branches/release/boost/utility/ (props changed)
   branches/release/boost/uuid/ (props changed)
   branches/release/boost/variant/ (props changed)
   branches/release/boost/wave/ (props changed)
   branches/release/bootstrap.bat (props changed)
   branches/release/bootstrap.sh (props changed)
   branches/release/index.htm (props changed)
   branches/release/libs/ (props changed)
   branches/release/libs/array/test/array0.cpp (props changed)
   branches/release/libs/bimap/ (props changed)
   branches/release/libs/filesystem/ (props changed)
   branches/release/libs/functional/hash/ (props changed)
   branches/release/libs/graph_parallel/ (props changed)
   branches/release/libs/integer/ (props changed)
   branches/release/libs/interprocess/ (props changed)
   branches/release/libs/intrusive/ (props changed)
   branches/release/libs/mpl/doc/refmanual/broken-compiler-workarounds.html (props changed)
   branches/release/libs/mpl/doc/refmanual/categorized-index-concepts.html (props changed)
   branches/release/libs/mpl/doc/refmanual/cfg-no-preprocessed-headers.html (props changed)
   branches/release/libs/mpl/doc/refmanual/composition-and-argument-binding.html (props changed)
   branches/release/libs/mpl/doc/refmanual/data-types-concepts.html (props changed)
   branches/release/libs/mpl/doc/refmanual/data-types-miscellaneous.html (props changed)
   branches/release/libs/mpl/doc/refmanual/extensible-associative-sequence.html (props changed)
   branches/release/libs/mpl/doc/refmanual/inserter-class.html (props changed)
   branches/release/libs/mpl/doc/refmanual/tag-dispatched-metafunction.html (props changed)
   branches/release/libs/mpl/doc/refmanual/trivial-metafunctions-summary.html (props changed)
   branches/release/libs/mpl/doc/src/refmanual/Iterators-Iterator.rst (props changed)
   branches/release/libs/msm/ (props changed)
   branches/release/libs/property_tree/ (props changed)
   branches/release/libs/python/ (props changed)
   branches/release/libs/range/ (props changed)
   branches/release/libs/range/doc/ (props changed)
   branches/release/libs/serialization/ (props changed)
   branches/release/libs/signals/ (props changed)
   branches/release/libs/signals2/ (props changed)
   branches/release/libs/spirit/ (props changed)
   branches/release/libs/spirit/classic/example/ (props changed)
   branches/release/libs/spirit/doc/ (props changed)
   branches/release/libs/spirit/example/ (props changed)
   branches/release/libs/spirit/phoenix/ (props changed)
   branches/release/libs/spirit/test/ (props changed)
   branches/release/libs/spirit/test/qi/optional.cpp (props changed)
   branches/release/libs/statechart/ (props changed)
   branches/release/libs/static_assert/ (props changed)
   branches/release/libs/system/ (props changed)
   branches/release/libs/thread/ (props changed)
   branches/release/libs/timer/ (props changed)
   branches/release/libs/utility/ (props changed)
   branches/release/libs/utility/swap.html (props changed)
   branches/release/libs/utility/swap/test/std_bitset.cpp (props changed)
   branches/release/libs/utility/value_init_test.cpp (props changed)
   branches/release/libs/uuid/ (props changed)
   branches/release/libs/wave/ (props changed)
   branches/release/more/ (props changed)
   branches/release/rst.css (props changed)
   branches/release/status/ (props changed)
   branches/release/status/Jamfile.v2 (props changed)
   branches/release/tools/ (props changed)
   branches/release/tools/bcp/ (props changed)
   branches/release/tools/build/v2/ (props changed)
   branches/release/tools/build/v2/tools/ (props changed)
   branches/release/tools/jam/ (props changed)
   branches/release/tools/regression/ (props changed)
   branches/release/tools/release/ (props changed)
   branches/release/tools/wave/ (props changed)
Text files modified:
   branches/release/boost/spirit/home/karma/detail/alternative_function.hpp | 68 +++++++++++++++++++++++++++++++++++----
   branches/release/boost/spirit/home/karma/operator/alternative.hpp | 50 ++++++++++++++++++++++++++--
   branches/release/boost/spirit/home/support/attributes.hpp | 20 +++++++++++
   3 files changed, 125 insertions(+), 13 deletions(-)

Modified: branches/release/boost/spirit/home/karma/detail/alternative_function.hpp
==============================================================================
--- branches/release/boost/spirit/home/karma/detail/alternative_function.hpp (original)
+++ branches/release/boost/spirit/home/karma/detail/alternative_function.hpp 2010-07-05 15:55:02 EDT (Mon, 05 Jul 2010)
@@ -38,8 +38,9 @@
         template <typename OutputIterator, typename Context, typename Delimiter>
         static bool
         call(Component const&, OutputIterator&, Context&, Delimiter const&
- , Attribute const&)
+ , Attribute const&, bool& failed)
         {
+ failed = true;
             return false;
         }
     };
@@ -50,7 +51,7 @@
         template <typename OutputIterator, typename Context, typename Delimiter>
         static bool
         call(Component const& component, OutputIterator& sink, Context& ctx
- , Delimiter const& d, unused_type)
+ , Delimiter const& d, unused_type, bool&)
         {
 #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600))
             component; // suppresses warning: C4100: 'component' : unreferenced formal parameter
@@ -82,7 +83,7 @@
         template <typename OutputIterator, typename Context, typename Delimiter>
         static bool
         call(Component const& component, OutputIterator& sink
- , Context& ctx, Delimiter const& d, Attribute const& attr)
+ , Context& ctx, Delimiter const& d, Attribute const& attr, bool&)
         {
 #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600))
             component; // suppresses warning: C4100: 'component' : unreferenced formal parameter
@@ -122,7 +123,7 @@
             // expectations
             typename traits::optional_attribute<Attribute>::type attr_ =
                 traits::optional_value(attr);
- if (!component_type::is_compatible(attr_.which()))
+ if (!component_type::is_compatible(spirit::traits::which(attr_)))
                 return false;
 
             // returns true if any of the generators succeed
@@ -137,11 +138,11 @@
     // expression
     ///////////////////////////////////////////////////////////////////////////
     template <typename OutputIterator, typename Context, typename Delimiter,
- typename Attribute>
+ typename Attribute, typename Strict>
     struct alternative_generate_function
     {
         alternative_generate_function(OutputIterator& sink_, Context& ctx_
- , Delimiter const& d, Attribute const& attr_)
+ , Delimiter const& d, Attribute const& attr_)
           : sink(sink_), ctx(ctx_), delim(d), attr(attr_) {}
 
         template <typename Component>
@@ -158,9 +159,10 @@
             // component fails
             detail::enable_buffering<OutputIterator> buffering(sink);
             bool r = false;
+ bool failed = false; // will be ignored
             {
                 detail::disable_counting<OutputIterator> nocounting(sink);
- r = generate::call(component, sink, ctx, delim, attr);
+ r = generate::call(component, sink, ctx, delim, attr, failed);
             }
             if (r)
                 buffering.buffer_copy();
@@ -178,7 +180,8 @@
                 buffer_directive<Component>, Attribute, expected_type>
             generate;
 
- return generate::call(component, sink, ctx, delim, attr);
+ bool failed = false; // will be ignored
+ return generate::call(component, sink, ctx, delim, attr, failed);
         }
 
         OutputIterator& sink;
@@ -191,6 +194,55 @@
         alternative_generate_function& operator= (alternative_generate_function const&);
     };
 
+ // specialization for strict alternatives
+ template <typename OutputIterator, typename Context, typename Delimiter,
+ typename Attribute>
+ struct alternative_generate_function<
+ OutputIterator, Context, Delimiter, Attribute, mpl::true_>
+ {
+ alternative_generate_function(OutputIterator& sink_, Context& ctx_
+ , Delimiter const& d, Attribute const& attr_)
+ : sink(sink_), ctx(ctx_), delim(d), attr(attr_), failed(false) {}
+
+ template <typename Component>
+ bool operator()(Component const& component)
+ {
+ typedef
+ typename traits::attribute_of<Component, Context>::type
+ expected_type;
+ typedef
+ alternative_generate<Component, Attribute, expected_type>
+ generate;
+
+ if (failed)
+ return false; // give up when already failed
+
+ // wrap the given output iterator avoid output as long as one
+ // component fails
+ detail::enable_buffering<OutputIterator> buffering(sink);
+ bool r = false;
+ {
+ detail::disable_counting<OutputIterator> nocounting(sink);
+ r = generate::call(component, sink, ctx, delim, attr, failed);
+ }
+ if (r && !failed)
+ {
+ buffering.buffer_copy();
+ return true;
+ }
+ return false;
+ }
+
+ OutputIterator& sink;
+ Context& ctx;
+ Delimiter const& delim;
+ Attribute const& attr;
+ bool failed;
+
+ private:
+ // silence MSVC warning C4512: assignment operator could not be generated
+ alternative_generate_function& operator= (alternative_generate_function const&);
+ };
 }}}}
 
 #endif

Modified: branches/release/boost/spirit/home/karma/operator/alternative.hpp
==============================================================================
--- branches/release/boost/spirit/home/karma/operator/alternative.hpp (original)
+++ branches/release/boost/spirit/home/karma/operator/alternative.hpp 2010-07-05 15:55:02 EDT (Mon, 05 Jul 2010)
@@ -12,6 +12,7 @@
 #endif
 
 #include <boost/spirit/home/karma/detail/alternative_function.hpp>
+#include <boost/spirit/home/karma/detail/get_stricttag.hpp>
 #include <boost/spirit/home/karma/domain.hpp>
 #include <boost/spirit/home/karma/generator.hpp>
 #include <boost/spirit/home/karma/meta_compiler.hpp>
@@ -75,8 +76,8 @@
 
 namespace boost { namespace spirit { namespace karma
 {
- template <typename Elements>
- struct alternative : nary_generator<alternative<Elements> >
+ template <typename Elements, typename Strict, typename Derived>
+ struct base_alternative : nary_generator<Derived>
     {
         typedef typename traits::alternative_properties<Elements>::type
             properties;
@@ -97,7 +98,7 @@
             typedef typename traits::build_variant<all_attributes>::type type;
         };
 
- alternative(Elements const& elements)
+ base_alternative(Elements const& elements)
           : elements(elements) {}
 
         template <
@@ -107,7 +108,7 @@
           , Delimiter const& d, Attribute const& attr) const
         {
             typedef detail::alternative_generate_function<
- OutputIterator, Context, Delimiter, Attribute
+ OutputIterator, Context, Delimiter, Attribute, Strict
> functor;
 
             // f return true if *any* of the parser succeeds
@@ -127,12 +128,48 @@
         Elements elements;
     };
 
+ template <typename Elements>
+ struct alternative
+ : base_alternative<Elements, mpl::false_, alternative<Elements> >
+ {
+ typedef base_alternative<Elements, mpl::false_, alternative>
+ base_alternative_;
+
+ alternative(Elements const& elements)
+ : base_alternative_(elements) {}
+ };
+
+ template <typename Elements>
+ struct strict_alternative
+ : base_alternative<Elements, mpl::true_, strict_alternative<Elements> >
+ {
+ typedef base_alternative<Elements, mpl::true_, strict_alternative>
+ base_alternative_;
+
+ strict_alternative(Elements const& elements)
+ : base_alternative_(elements) {}
+ };
+
     ///////////////////////////////////////////////////////////////////////////
     // Generator generators: make_xxx function (objects)
     ///////////////////////////////////////////////////////////////////////////
+ namespace detail
+ {
+ template <typename Elements, bool strict_mode = false>
+ struct make_alternative
+ : make_nary_composite<Elements, alternative>
+ {};
+
+ template <typename Elements>
+ struct make_alternative<Elements, true>
+ : make_nary_composite<Elements, strict_alternative>
+ {};
+ }
+
     template <typename Elements, typename Modifiers>
     struct make_composite<proto::tag::bitwise_or, Elements, Modifiers>
- : make_nary_composite<Elements, alternative>
+ : detail::make_alternative<Elements
+ , detail::get_stricttag<Modifiers>::value>
     {};
 
 }}}
@@ -143,6 +180,9 @@
     struct has_semantic_action<karma::alternative<Elements> >
       : nary_has_semantic_action<Elements> {};
 
+ template <typename Elements>
+ struct has_semantic_action<karma::strict_alternative<Elements> >
+ : nary_has_semantic_action<Elements> {};
 }}}
 
 #endif

Modified: branches/release/boost/spirit/home/support/attributes.hpp
==============================================================================
--- branches/release/boost/spirit/home/support/attributes.hpp (original)
+++ branches/release/boost/spirit/home/support/attributes.hpp 2010-07-05 15:55:02 EDT (Mon, 05 Jul 2010)
@@ -186,6 +186,26 @@
       : mpl::false_ {};
 
     ///////////////////////////////////////////////////////////////////////////
+ // return the type currently stored in the given variant
+ template <typename T, typename Enable = void>
+ struct variant_which;
+
+ template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
+ struct variant_which<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
+ {
+ static int call(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& v)
+ {
+ return v.which();
+ }
+ };
+
+ template <typename T>
+ int which(T const& v)
+ {
+ return variant_which<T>::call(v);
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
     template <typename T, typename Domain>
     struct not_is_optional
       : mpl::true_


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