Boost logo

Boost-Commit :

From: ahd6974-boostorg_at_[hidden]
Date: 2008-01-05 07:42:02


Author: andreas_huber69
Date: 2008-01-05 07:42:02 EST (Sat, 05 Jan 2008)
New Revision: 42475
URL: http://svn.boost.org/trac/boost/changeset/42475

Log:
Added defaults for in_state_reaction template parameters and updated tests accordingly.
Text files modified:
   trunk/boost/statechart/in_state_reaction.hpp | 48 ++++++++++++---------------------------
   trunk/boost/statechart/transition.hpp | 3 -
   trunk/libs/statechart/doc/reference.html | 48 ++++++++++++++++++++++++++++-----------
   trunk/libs/statechart/test/InStateReactionTest.cpp | 39 +++++++++++++++++++-------------
   4 files changed, 73 insertions(+), 65 deletions(-)

Modified: trunk/boost/statechart/in_state_reaction.hpp
==============================================================================
--- trunk/boost/statechart/in_state_reaction.hpp (original)
+++ trunk/boost/statechart/in_state_reaction.hpp 2008-01-05 07:42:02 EST (Sat, 05 Jan 2008)
@@ -10,10 +10,7 @@
 
 #include <boost/statechart/result.hpp>
 
-#include <boost/mpl/if.hpp>
-
-#include <boost/cast.hpp> // boost::polymorphic_downcast
-#include <boost/type_traits/is_same.hpp>
+#include <boost/statechart/detail/reaction_dispatcher.hpp>
 
 
 
@@ -28,39 +25,25 @@
 
 //////////////////////////////////////////////////////////////////////////////
 template< class Event,
- class ReactionContext,
- void ( ReactionContext::*pAction )( const Event & ) >
+ class ReactionContext = detail::no_context< Event >,
+ void ( ReactionContext::*pAction )( const Event & ) =
+ &detail::no_context< Event >::no_function >
 class in_state_reaction
 {
   private:
     //////////////////////////////////////////////////////////////////////////
- struct react_base
+ template< class State >
+ struct reactions
     {
- template< class State, class EventBase, class IdType >
- static detail::reaction_result react(
- State & stt, const EventBase & evt, const IdType & )
+ static result react_without_action( State & stt )
       {
- ( stt.template context< ReactionContext >().*pAction )( evt );
- return detail::do_discard_event;
+ return stt.discard_event();
       }
- };
 
- struct react_derived
- {
- template< class State, class EventBase, class IdType >
- static detail::reaction_result react(
- State & stt, const EventBase & evt, const IdType & eventType )
+ static result react_with_action( State & stt, const Event & evt )
       {
- if ( eventType == Event::static_type() )
- {
- ( stt.template context< ReactionContext >().*pAction )(
- *polymorphic_downcast< const Event * >( &evt ) );
- return detail::do_discard_event;
- }
- else
- {
- return detail::no_reaction;
- }
+ ( stt.template context< ReactionContext >().*pAction )( evt );
+ return react_without_action( stt );
       }
     };
 
@@ -73,11 +56,10 @@
     static detail::reaction_result react(
       State & stt, const EventBase & evt, const IdType & eventType )
     {
- typedef typename mpl::if_<
- is_same< Event, event_base >, react_base, react_derived
- >::type impl;
-
- return impl::react( stt, evt, eventType );
+ typedef detail::reaction_dispatcher<
+ reactions< State >, State, EventBase, Event, ReactionContext, IdType
+ > dispatcher;
+ return dispatcher::react( stt, evt, eventType );
     }
 };
 

Modified: trunk/boost/statechart/transition.hpp
==============================================================================
--- trunk/boost/statechart/transition.hpp (original)
+++ trunk/boost/statechart/transition.hpp 2008-01-05 07:42:02 EST (Sat, 05 Jan 2008)
@@ -38,8 +38,7 @@
         return stt.template transit< Destination >();
       }
 
- template< class Event2 >
- static result react_with_action( State & stt, const Event2 & evt )
+ static result react_with_action( State & stt, const Event & evt )
       {
         return stt.template transit< Destination >( pTransitionAction, evt );
       }

Modified: trunk/libs/statechart/doc/reference.html
==============================================================================
--- trunk/libs/statechart/doc/reference.html (original)
+++ trunk/libs/statechart/doc/reference.html 2008-01-05 07:42:02 EST (Sat, 05 Jan 2008)
@@ -4,11 +4,17 @@
 <head>
   <meta http-equiv="Content-Language" content="en-us">
   <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
- <meta name="GENERATOR" content="Microsoft FrontPage 6.0">
+ <meta name="GENERATOR" content="Microsoft FrontPage 12.0">
   <meta name="ProgId" content="FrontPage.Editor.Document">
   <link rel="stylesheet" type="text/css" href="../../../boost.css">
 
   <title>The Boost Statechart Library - Reference</title>
+ <style type="text/css">
+ .style1
+ {
+ width: 45%;
+ }
+ </style>
 </head>
 
 <body link="#0000FF" vlink="#800080">
@@ -3110,7 +3116,7 @@
 
       <td width="24%"><b>Semantics</b></td>
 
- <td width="19%"><b>Default</b></td>
+ <td width="16%"><b>Default</b></td>
     </tr>
 
     <tr>
@@ -3124,7 +3130,7 @@
       is triggered by all models of the Event
       concept</td>
 
- <td width="19%">&nbsp;</td>
+ <td width="16%">&nbsp;</td>
     </tr>
 
     <tr>
@@ -3141,7 +3147,7 @@
 
       <td width="24%">The destination state to make a transition to</td>
 
- <td width="19%">&nbsp;</td>
+ <td width="16%">&nbsp;</td>
     </tr>
 
     <tr>
@@ -3153,7 +3159,7 @@
       <td width="24%">The state of which the transition action is a
       member</td>
 
- <td width="19%"><i><code>unspecified</code></i></td>
+ <td width="16%"><i><code>unspecified</code></i></td>
     </tr>
 
     <tr>
@@ -3167,7 +3173,7 @@
       <td width="24%">The transition action that is executed during the
       transition. By default no transition action is executed</td>
 
- <td width="19%"><i><code>unspecified</code></i></td>
+ <td width="16%"><i><code>unspecified</code></i></td>
     </tr>
   </table>
 
@@ -3227,6 +3233,8 @@
       <td width="45%"><b>Requirements</b></td>
 
       <td width="24%"><b>Semantics</b></td>
+
+ <td width="16%"><b>Default</b></td>
     </tr>
 
     <tr>
@@ -3239,6 +3247,8 @@
       <code>event_base</code> is specified,
       the in-state reaction is triggered by all models of the <a href=
       "#Event">Event</a> concept</td>
+
+ <td width="16%">&nbsp;</td>
     </tr>
 
     <tr>
@@ -3248,6 +3258,8 @@
       or one of it direct or indirect contexts</td>
 
       <td width="24%">The state of which the action is a member</td>
+
+ <td width="16%"><i><code>unspecified</code></i></td>
     </tr>
 
     <tr>
@@ -3260,6 +3272,8 @@
 
       <td width="24%">The action that is executed during the in-state
       reaction</td>
+
+ <td width="16%"><i><code>unspecified</code></i></td>
     </tr>
   </table>
 
@@ -3271,8 +3285,9 @@
 {
   template&lt;
     class Event,
- class ReactionContext,
- void ( ReactionContext::*pAction )( const Event &amp; ) &gt;
+ class ReactionContext = <i>unspecified</i>,
+ void ( ReactionContext::*pAction )(
+ const Event &amp; ) = <i>unspecified</i> &gt;
   class in_state_reaction
   {
     // <i>implementation-defined</i>
@@ -3283,10 +3298,14 @@
 
   <h3>Class template <code>in_state_reaction</code> semantics</h3>
 
- <p>When executed, <code>pAction</code> is called, passing the triggering
- event as the only argument. Afterwards, a call is made to the
- <code>discard_event</code> member function of
- the state for which the reaction was defined.</p>
+ <p>When executed then the following happens:</p>
+ <ol>
+ <li>If an action was specified, <code>pAction</code> is called, passing
+ the triggering event as the only argument</li>
+ <li>A call is made to the <code>discard_event
+ </code> member function of the state for which the reaction was defined
+ </li>
+ </ol>
 
   <h1>Header &lt;boost/statechart/<a name="termination.hpp" id=
   "termination.hpp">termination.hpp</a>&gt;</h1>
@@ -3536,9 +3555,10 @@
   height="31" width="88"></a></p>
 
   <p>Revised
- <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->09 April, 2007<!--webbot bot="Timestamp" endspan i-checksum="30014" --></p>
+ <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" --></p>
 
- <p><i>Copyright &copy; 2003-<!--webbot bot="Timestamp" s-type="EDITED" s-format="%Y" startspan -->2007<!--webbot bot="Timestamp" endspan i-checksum="778" -->
+ <p><i>Copyright &copy; 2003-<!--webbot bot="Timestamp" s-type="EDITED"
+ s-format="%Y" -->
    <a href="contact.html">Andreas Huber D&ouml;nni</a></i></p>
 
   <p><i>Distributed under the Boost Software License, Version 1.0. (See

Modified: trunk/libs/statechart/test/InStateReactionTest.cpp
==============================================================================
--- trunk/libs/statechart/test/InStateReactionTest.cpp (original)
+++ trunk/libs/statechart/test/InStateReactionTest.cpp 2008-01-05 07:42:02 EST (Sat, 05 Jan 2008)
@@ -1,5 +1,5 @@
 //////////////////////////////////////////////////////////////////////////////
-// Copyright 2005-2006 Andreas Huber Doenni
+// Copyright 2005-2008 Andreas Huber Doenni
 // Distributed under the Boost Software License, Version 1.0. (See accompany-
 // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 //////////////////////////////////////////////////////////////////////////////
@@ -24,10 +24,10 @@
 struct F : sc::event< F > {};
 struct G : sc::event< G > {};
 struct H : sc::event< H > {};
+struct I : sc::event< I > {};
 
 struct A;
-struct InStateReactionTest :
- sc::state_machine< InStateReactionTest, A > {};
+struct InStateReactionTest : sc::state_machine< InStateReactionTest, A > {};
 
 struct B;
 struct A : sc::simple_state< A, InStateReactionTest, B >
@@ -59,7 +59,8 @@
 
     typedef mpl::list<
       sc::in_state_reaction< F, B, &B::IncrementCount >,
- sc::in_state_reaction< G, A, &A::IncrementCount >
+ sc::in_state_reaction< G, A, &A::IncrementCount >,
+ sc::in_state_reaction< I >
> reactions;
 
     unsigned int eventCount_;
@@ -67,29 +68,35 @@
 
 
 
+void RequireEventCounts(
+ const InStateReactionTest & machine,
+ unsigned int aCount, unsigned int bCount)
+{
+ BOOST_REQUIRE(
+ machine.state_downcast< const A & >().eventCount_ == aCount );
+ BOOST_REQUIRE(
+ machine.state_downcast< const B & >().eventCount_ == bCount );
+}
+
 int test_main( int, char* [] )
 {
   InStateReactionTest machine;
   machine.initiate();
 
- BOOST_REQUIRE( machine.state_downcast< const A & >().eventCount_ == 0 );
- BOOST_REQUIRE( machine.state_downcast< const B & >().eventCount_ == 0 );
+ RequireEventCounts(machine, 0, 0);
   machine.process_event( F() );
- BOOST_REQUIRE( machine.state_downcast< const A & >().eventCount_ == 0 );
- BOOST_REQUIRE( machine.state_downcast< const B & >().eventCount_ == 1 );
+ RequireEventCounts(machine, 0, 1);
   machine.process_event( E() );
- BOOST_REQUIRE( machine.state_downcast< const A & >().eventCount_ == 1 );
- BOOST_REQUIRE( machine.state_downcast< const B & >().eventCount_ == 1 );
+ RequireEventCounts(machine, 1, 1);
   machine.process_event( E() );
   machine.process_event( F() );
- BOOST_REQUIRE( machine.state_downcast< const A & >().eventCount_ == 2 );
- BOOST_REQUIRE( machine.state_downcast< const B & >().eventCount_ == 2 );
+ RequireEventCounts(machine, 2, 2);
   machine.process_event( G() );
- BOOST_REQUIRE( machine.state_downcast< const A & >().eventCount_ == 3 );
- BOOST_REQUIRE( machine.state_downcast< const B & >().eventCount_ == 2 );
+ RequireEventCounts(machine, 3, 2);
   machine.process_event( H() );
- BOOST_REQUIRE( machine.state_downcast< const A & >().eventCount_ == 4 );
- BOOST_REQUIRE( machine.state_downcast< const B & >().eventCount_ == 2 );
+ RequireEventCounts(machine, 4, 2);
+ machine.process_event( I() );
+ RequireEventCounts(machine, 4, 2);
 
   return 0;
 }


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