|
Boost-Commit : |
From: ahd6974-boostorg_at_[hidden]
Date: 2008-04-13 09:57:44
Author: andreas_huber69
Date: 2008-04-13 09:57:42 EDT (Sun, 13 Apr 2008)
New Revision: 44367
URL: http://svn.boost.org/trac/boost/changeset/44367
Log:
Changed the PingPong example to demonstrate how the inner workings of an asynchronous_state_machine<> subclass can be hidden.
Added:
trunk/libs/statechart/example/PingPong/Player.cpp (contents, props changed)
trunk/libs/statechart/example/PingPong/Player.hpp (contents, props changed)
trunk/libs/statechart/example/PingPong/Waiting.hpp (contents, props changed)
Properties modified:
trunk/libs/statechart/example/PingPong/PingPong.vcproj (contents, props changed)
Text files modified:
trunk/libs/statechart/doc/faq.html | 2
trunk/libs/statechart/doc/future_and_history.html | 2
trunk/libs/statechart/example/Jamfile.v2 | 6
trunk/libs/statechart/example/PingPong/PingPong.cpp | 158 ----------
trunk/libs/statechart/example/PingPong/PingPong.vcproj | 586 ++++++++++++++++++++-------------------
trunk/libs/statechart/test/Jamfile.v2 | 2
6 files changed, 313 insertions(+), 443 deletions(-)
Modified: trunk/libs/statechart/doc/faq.html
==============================================================================
--- trunk/libs/statechart/doc/faq.html (original)
+++ trunk/libs/statechart/doc/faq.html 2008-04-13 09:57:42 EDT (Sun, 13 Apr 2008)
@@ -247,6 +247,8 @@
<b>initiate();</b>
}
</pre>
+ <p>The PingPong example demonstrates how the inner workings of an
+ asynchronous_state_machine<> subclass can be hidden.</p>
<h2><a name="MachineInheritance" id="MachineInheritance">Is it possible to
inherit from a given state machine and modify its layout in the
Modified: trunk/libs/statechart/doc/future_and_history.html
==============================================================================
--- trunk/libs/statechart/doc/future_and_history.html (original)
+++ trunk/libs/statechart/doc/future_and_history.html 2008-04-13 09:57:42 EDT (Sun, 13 Apr 2008)
@@ -154,6 +154,8 @@
(due to feedback from Sean Kelly)</li>
<li>Adapted fifo_scheduler<> to the changed allocator interface of
boost::function</li>
+ <li>Changed the PingPong example to demonstrate how the inner workings of
+ an asynchronous_state_machine<> subclass can be hidden</li>
</ul>
<p>1.35.0</p>
Modified: trunk/libs/statechart/example/Jamfile.v2
==============================================================================
--- trunk/libs/statechart/example/Jamfile.v2 (original)
+++ trunk/libs/statechart/example/Jamfile.v2 2008-04-13 09:57:42 EDT (Sun, 13 Apr 2008)
@@ -59,11 +59,11 @@
[ statechart-st-example-build KeyboardNative
: Keyboard : Keyboard : $(native) ]
[ statechart-st-example-build PingPongSingle
- : PingPong : PingPong : $(custom) ]
+ : PingPong : PingPong Player : $(custom) ]
[ statechart-mt-example-build PingPongMulti1
- : PingPong : PingPong : $(custom) ]
+ : PingPong : PingPong Player : $(custom) ]
[ statechart-mt-example-build PingPongMulti2
- : PingPong : PingPong : $(custom) <define>USE_TWO_THREADS ]
+ : PingPong : PingPong Player : $(custom) <define>USE_TWO_THREADS ]
[ statechart-st-example-build StopWatch : StopWatch : StopWatch ]
[ statechart-st-example-build StopWatch2 : StopWatch : StopWatch2 ]
[ statechart-st-example-build PerformanceNormal
Modified: trunk/libs/statechart/example/PingPong/PingPong.cpp
==============================================================================
--- trunk/libs/statechart/example/PingPong/PingPong.cpp (original)
+++ trunk/libs/statechart/example/PingPong/PingPong.cpp 2008-04-13 09:57:42 EDT (Sun, 13 Apr 2008)
@@ -29,20 +29,14 @@
//////////////////////////////////////////////////////////////////////////////
+#include "Player.hpp"
-#include <boost/statechart/event.hpp>
#include <boost/statechart/asynchronous_state_machine.hpp>
-#include <boost/statechart/state.hpp>
-#include <boost/statechart/transition.hpp>
-#include <boost/statechart/custom_reaction.hpp>
-#include <boost/statechart/fifo_scheduler.hpp>
#include <boost/statechart/fifo_worker.hpp>
#include <boost/mpl/list.hpp>
-
#include <boost/config.hpp>
#include <boost/intrusive_ptr.hpp>
-#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>
#include <boost/bind.hpp>
@@ -50,31 +44,8 @@
# include <boost/thread/thread.hpp>
#endif
-#ifdef CUSTOMIZE_MEMORY_MANAGEMENT
-# ifdef BOOST_HAS_THREADS
- // for some reason the following is not automatically defined
-# if defined( BOOST_MSVC ) | defined( BOOST_INTEL )
-# define __WIN32__
-# endif
-# else
-# define BOOST_NO_MT
-# endif
-
-# ifdef BOOST_MSVC
-# pragma warning( push )
-# pragma warning( disable: 4127 ) // conditional expression is constant
-# endif
-
-# include <boost/pool/pool_alloc.hpp>
-
-# ifdef BOOST_MSVC
-# pragma warning( pop )
-# endif
-#endif
-
#include <iostream>
#include <ctime>
-#include <memory> // std::allocator
#ifdef BOOST_NO_STDC_NAMESPACE
namespace std
@@ -93,133 +64,12 @@
namespace sc = boost::statechart;
-namespace mpl = boost::mpl;
//////////////////////////////////////////////////////////////////////////////
const unsigned int noOfEvents = 1000000;
-template< class T >
-boost::intrusive_ptr< T > MakeIntrusive( T * pObject )
-{
- return boost::intrusive_ptr< T >( pObject );
-}
-
-
-//////////////////////////////////////////////////////////////////////////////
-struct BallReturned : sc::event< BallReturned >
-{
- boost::function1< void, const boost::intrusive_ptr< const BallReturned > & >
- returnToOpponent;
- boost::function0< void > abortGame;
-};
-
-struct GameAborted : sc::event< GameAborted > {};
-
-#ifdef CUSTOMIZE_MEMORY_MANAGEMENT
-typedef boost::fast_pool_allocator< int > MyAllocator;
-typedef sc::fifo_scheduler<
- sc::fifo_worker< MyAllocator >, MyAllocator > MyScheduler;
-#else
-typedef std::allocator< void > MyAllocator;
-typedef sc::fifo_scheduler<> MyScheduler;
-#endif
-
-struct Waiting;
-struct Player : sc::asynchronous_state_machine<
- Player, Waiting, MyScheduler, MyAllocator >
-{
- public:
- Player( my_context ctx, unsigned int maxNoOfReturns ) :
- my_base( ctx ),
- maxNoOfReturns_( maxNoOfReturns )
- {
- }
-
- static unsigned int & TotalNoOfProcessedEvents()
- {
- return totalNoOfProcessedEvents_;
- }
-
- unsigned int GetMaxNoOfReturns() const
- {
- return maxNoOfReturns_;
- }
-
- private:
- static unsigned int totalNoOfProcessedEvents_;
- const unsigned int maxNoOfReturns_;
-};
-
-unsigned int Player::totalNoOfProcessedEvents_ = 0;
-
-
-struct Waiting : sc::state< Waiting, Player >
-{
- public:
- //////////////////////////////////////////////////////////////////////////
- typedef mpl::list<
- sc::custom_reaction< BallReturned >,
- sc::custom_reaction< GameAborted >
- > reactions;
-
- Waiting( my_context ctx ) :
- my_base( ctx ),
- noOfReturns_( 0 ),
- pBallReturned_( new BallReturned() )
- {
- outermost_context_type & machine = outermost_context();
- // as we will always return the same event to the opponent, we construct
- // and fill it here so that we can reuse it over and over
- pBallReturned_->returnToOpponent = boost::bind(
- &MyScheduler::queue_event,
- &machine.my_scheduler(), machine.my_handle(), _1 );
- pBallReturned_->abortGame = boost::bind(
- &MyScheduler::queue_event,
- &machine.my_scheduler(), machine.my_handle(),
- MakeIntrusive( new GameAborted() ) );
- }
-
- sc::result react( const GameAborted & )
- {
- return DestroyMyself();
- }
-
- sc::result react( const BallReturned & ballReturned )
- {
- outermost_context_type & machine = outermost_context();
- ++machine.TotalNoOfProcessedEvents();
-
- if ( noOfReturns_++ < machine.GetMaxNoOfReturns() )
- {
- ballReturned.returnToOpponent( pBallReturned_ );
- return discard_event();
- }
- else
- {
- ballReturned.abortGame();
- return DestroyMyself();
- }
- }
-
- private:
- //////////////////////////////////////////////////////////////////////////
- sc::result DestroyMyself()
- {
- outermost_context_type & machine = outermost_context();
- machine.my_scheduler().destroy_processor( machine.my_handle() );
- machine.my_scheduler().terminate();
- return terminate();
- }
-
- // avoids C4512 (assignment operator could not be generated)
- Waiting & operator=( const Waiting & );
-
- unsigned int noOfReturns_;
- const boost::intrusive_ptr< BallReturned > pBallReturned_;
-};
-
//////////////////////////////////////////////////////////////////////////////
char GetKey()
@@ -274,15 +124,15 @@
MyScheduler & scheduler2 = scheduler1;
#endif
- MyScheduler::processor_handle player1 =
+ MyScheduler::processor_handle player1 =
scheduler1.create_processor< Player >( noOfEvents / 2 );
scheduler1.initiate_processor( player1 );
- MyScheduler::processor_handle player2 =
+ MyScheduler::processor_handle player2 =
scheduler2.create_processor< Player >( noOfEvents / 2 );
scheduler2.initiate_processor( player2 );
boost::intrusive_ptr< BallReturned > pInitialBall = new BallReturned();
- pInitialBall->returnToOpponent = boost::bind(
+ pInitialBall->returnToOpponent = boost::bind(
&MyScheduler::queue_event, &scheduler1, player1, _1 );
pInitialBall->abortGame = boost::bind(
&MyScheduler::queue_event,
Modified: trunk/libs/statechart/example/PingPong/PingPong.vcproj
==============================================================================
--- trunk/libs/statechart/example/PingPong/PingPong.vcproj (original)
+++ trunk/libs/statechart/example/PingPong/PingPong.vcproj 2008-04-13 09:57:42 EDT (Sun, 13 Apr 2008)
@@ -1,285 +1,301 @@
-<?xml version="1.0" encoding="Windows-1252"?>
-<VisualStudioProject
- ProjectType="Visual C++"
- Version="9.00"
- Name="PingPong"
- ProjectGUID="{11CCA9FC-6012-4B64-8C61-808D0F8D1B51}"
- RootNamespace="PingPong"
- Keyword="Win32Proj"
- TargetFrameworkVersion="131072"
- >
- <Platforms>
- <Platform
- Name="Win32"
- />
- </Platforms>
- <ToolFiles>
- </ToolFiles>
- <Configurations>
- <Configuration
- Name="Debug|Win32"
- OutputDirectory="Debug"
- IntermediateDirectory="Debug"
- ConfigurationType="1"
- InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="..\..\..\.."
- PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;BOOST_ALL_DYN_LINK"
- MinimalRebuild="true"
- BasicRuntimeChecks="3"
- RuntimeLibrary="3"
- BufferSecurityCheck="true"
- DisableLanguageExtensions="false"
- TreatWChar_tAsBuiltInType="true"
- ForceConformanceInForLoopScope="true"
- RuntimeTypeInfo="true"
- UsePrecompiledHeader="0"
- WarningLevel="4"
- WarnAsError="true"
- Detect64BitPortabilityProblems="false"
- DebugInformationFormat="4"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- OutputFile="$(OutDir)/PingPong.exe"
- LinkIncremental="2"
- AdditionalLibraryDirectories=""$(ProjectDir)..\..\..\..\bin.v2\libs\thread\build\msvc-9.0\$(ConfigurationName)\threading-multi";"$(ProjectDir)..\..\..\..\bin.v2\libs\date_time\build\msvc-9.0\$(ConfigurationName)\threading-multi""
- GenerateDebugInformation="true"
- ProgramDatabaseFile="$(OutDir)/PingPong.pdb"
- SubSystem="1"
- RandomizedBaseAddress="1"
- DataExecutionPrevention="0"
- TargetMachine="1"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- CommandLine="copy $(ProjectDir)..\..\..\..\bin.v2\libs\thread\build\msvc-9.0\$(ConfigurationName)\threading-multi\*.dll $(TargetDir)
copy $(ProjectDir)..\..\..\..\bin.v2\libs\date_time\build\msvc-9.0\$(ConfigurationName)\threading-multi\*.dll $(TargetDir)
"
- />
- </Configuration>
- <Configuration
- Name="Release|Win32"
- OutputDirectory="Release"
- IntermediateDirectory="Release"
- ConfigurationType="1"
- InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="3"
- InlineFunctionExpansion="2"
- AdditionalIncludeDirectories="..\..\..\.."
- PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;BOOST_ALL_DYN_LINK"
- StringPooling="true"
- RuntimeLibrary="2"
- BufferSecurityCheck="false"
- EnableFunctionLevelLinking="true"
- DisableLanguageExtensions="false"
- TreatWChar_tAsBuiltInType="true"
- ForceConformanceInForLoopScope="true"
- UsePrecompiledHeader="0"
- WarningLevel="4"
- WarnAsError="true"
- Detect64BitPortabilityProblems="false"
- DebugInformationFormat="0"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- OutputFile="$(OutDir)/PingPong.exe"
- LinkIncremental="1"
- AdditionalLibraryDirectories=""$(ProjectDir)..\..\..\..\bin.v2\libs\thread\build\msvc-9.0\$(ConfigurationName)\threading-multi";"$(ProjectDir)..\..\..\..\bin.v2\libs\date_time\build\msvc-9.0\$(ConfigurationName)\threading-multi""
- GenerateDebugInformation="false"
- SubSystem="1"
- OptimizeReferences="2"
- EnableCOMDATFolding="2"
- RandomizedBaseAddress="1"
- DataExecutionPrevention="0"
- TargetMachine="1"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- CommandLine="copy $(ProjectDir)..\..\..\..\bin.v2\libs\thread\build\msvc-9.0\$(ConfigurationName)\threading-multi\*.dll $(TargetDir)
copy $(ProjectDir)..\..\..\..\bin.v2\libs\date_time\build\msvc-9.0\$(ConfigurationName)\threading-multi\*.dll $(TargetDir)
"
- />
- </Configuration>
- </Configurations>
- <References>
- </References>
- <Files>
- <Filter
- Name="Source Files"
- Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
- UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
- >
- <File
- RelativePath=".\PingPong.cpp"
- >
- </File>
- </Filter>
- <Filter
- Name="Statechart Header Files"
- >
- <File
- RelativePath="..\..\..\..\boost\statechart\asynchronous_state_machine.hpp"
- >
- </File>
- <File
- RelativePath="..\..\..\..\boost\statechart\custom_reaction.hpp"
- >
- </File>
- <File
- RelativePath="..\..\..\..\boost\statechart\deep_history.hpp"
- >
- </File>
- <File
- RelativePath="..\..\..\..\boost\statechart\deferral.hpp"
- >
- </File>
- <File
- RelativePath="..\..\..\..\boost\statechart\event.hpp"
- >
- </File>
- <File
- RelativePath="..\..\..\..\boost\statechart\event_base.hpp"
- >
- </File>
- <File
- RelativePath="..\..\..\..\boost\statechart\event_processor.hpp"
- >
- </File>
- <File
- RelativePath="..\..\..\..\boost\statechart\exception_translator.hpp"
- >
- </File>
- <File
- RelativePath="..\..\..\..\boost\statechart\fifo_scheduler.hpp"
- >
- </File>
- <File
- RelativePath="..\..\..\..\boost\statechart\in_state_reaction.hpp"
- >
- </File>
- <File
- RelativePath="..\..\..\..\boost\statechart\null_exception_translator.hpp"
- >
- </File>
- <File
- RelativePath="..\..\..\..\boost\statechart\result.hpp"
- >
- </File>
- <File
- RelativePath="..\..\..\..\boost\statechart\shallow_history.hpp"
- >
- </File>
- <File
- RelativePath="..\..\..\..\boost\statechart\simple_state.hpp"
- >
- </File>
- <File
- RelativePath="..\..\..\..\boost\statechart\state.hpp"
- >
- </File>
- <File
- RelativePath="..\..\..\..\boost\statechart\state_machine.hpp"
- >
- </File>
- <File
- RelativePath="..\..\..\..\boost\statechart\termination.hpp"
- >
- </File>
- <File
- RelativePath="..\..\..\..\boost\statechart\transition.hpp"
- >
- </File>
- </Filter>
- </Files>
- <Globals>
- </Globals>
-</VisualStudioProject>
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9.00"
+ Name="PingPong"
+ ProjectGUID="{11CCA9FC-6012-4B64-8C61-808D0F8D1B51}"
+ RootNamespace="PingPong"
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="131072"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\..\..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;BOOST_ALL_DYN_LINK"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ BufferSecurityCheck="true"
+ DisableLanguageExtensions="false"
+ TreatWChar_tAsBuiltInType="true"
+ ForceConformanceInForLoopScope="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="4"
+ WarnAsError="true"
+ Detect64BitPortabilityProblems="false"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)/PingPong.exe"
+ LinkIncremental="2"
+ AdditionalLibraryDirectories=""$(ProjectDir)..\..\..\..\bin.v2\libs\thread\build\msvc-9.0\$(ConfigurationName)\threading-multi";"$(ProjectDir)..\..\..\..\bin.v2\libs\date_time\build\msvc-9.0\$(ConfigurationName)\threading-multi""
+ GenerateDebugInformation="true"
+ ProgramDatabaseFile="$(OutDir)/PingPong.pdb"
+ SubSystem="1"
+ RandomizedBaseAddress="1"
+ DataExecutionPrevention="0"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ CommandLine="copy $(ProjectDir)..\..\..\..\bin.v2\libs\thread\build\msvc-9.0\$(ConfigurationName)\threading-multi\*.dll $(TargetDir)
copy $(ProjectDir)..\..\..\..\bin.v2\libs\date_time\build\msvc-9.0\$(ConfigurationName)\threading-multi\*.dll $(TargetDir)
"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="3"
+ InlineFunctionExpansion="2"
+ AdditionalIncludeDirectories="..\..\..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;BOOST_ALL_DYN_LINK"
+ StringPooling="true"
+ RuntimeLibrary="2"
+ BufferSecurityCheck="false"
+ EnableFunctionLevelLinking="true"
+ DisableLanguageExtensions="false"
+ TreatWChar_tAsBuiltInType="true"
+ ForceConformanceInForLoopScope="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="4"
+ WarnAsError="true"
+ Detect64BitPortabilityProblems="false"
+ DebugInformationFormat="0"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)/PingPong.exe"
+ LinkIncremental="1"
+ AdditionalLibraryDirectories=""$(ProjectDir)..\..\..\..\bin.v2\libs\thread\build\msvc-9.0\$(ConfigurationName)\threading-multi";"$(ProjectDir)..\..\..\..\bin.v2\libs\date_time\build\msvc-9.0\$(ConfigurationName)\threading-multi""
+ GenerateDebugInformation="false"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ RandomizedBaseAddress="1"
+ DataExecutionPrevention="0"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ CommandLine="copy $(ProjectDir)..\..\..\..\bin.v2\libs\thread\build\msvc-9.0\$(ConfigurationName)\threading-multi\*.dll $(TargetDir)
copy $(ProjectDir)..\..\..\..\bin.v2\libs\date_time\build\msvc-9.0\$(ConfigurationName)\threading-multi\*.dll $(TargetDir)
"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath=".\PingPong.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\Player.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Statechart Header Files"
+ >
+ <File
+ RelativePath="..\..\..\..\boost\statechart\asynchronous_state_machine.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\custom_reaction.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\deep_history.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\deferral.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\event.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\event_base.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\event_processor.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\exception_translator.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\fifo_scheduler.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\in_state_reaction.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\null_exception_translator.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\result.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\shallow_history.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\simple_state.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\state.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\state_machine.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\termination.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\transition.hpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ >
+ <File
+ RelativePath=".\Player.hpp"
+ >
+ </File>
+ <File
+ RelativePath=".\Waiting.hpp"
+ >
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
Added: trunk/libs/statechart/example/PingPong/Player.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/statechart/example/PingPong/Player.cpp 2008-04-13 09:57:42 EDT (Sun, 13 Apr 2008)
@@ -0,0 +1,24 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright 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)
+//////////////////////////////////////////////////////////////////////////////
+
+
+
+#include "Player.hpp"
+#include "Waiting.hpp" // Waiting.hpp is only included here
+
+
+
+//////////////////////////////////////////////////////////////////////////////
+void Player::initiate_impl()
+{
+ // Since we can only initiate at a point where the definitions of all the
+ // states in the initial state configuration are known, we duplicate
+ // the implementation of asynchronous_state_machine<>::initiate_impl() here
+ state_machine< Player, Waiting, MyAllocator >::initiate();
+}
+
+
+unsigned int Player::totalNoOfProcessedEvents_ = 0;
Added: trunk/libs/statechart/example/PingPong/Player.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/statechart/example/PingPong/Player.hpp 2008-04-13 09:57:42 EDT (Sun, 13 Apr 2008)
@@ -0,0 +1,116 @@
+#ifndef BOOST_STATECHART_EXAMPLE_PLAYER_HPP_INCLUDED
+#define BOOST_STATECHART_EXAMPLE_PLAYER_HPP_INCLUDED
+//////////////////////////////////////////////////////////////////////////////
+// Copyright 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)
+//////////////////////////////////////////////////////////////////////////////
+
+
+
+#include <boost/statechart/event.hpp>
+#include <boost/statechart/fifo_scheduler.hpp>
+#include <boost/statechart/asynchronous_state_machine.hpp>
+
+#include <boost/config.hpp>
+#include <boost/intrusive_ptr.hpp>
+#include <boost/mpl/list.hpp>
+#include <boost/function.hpp>
+
+#ifdef CUSTOMIZE_MEMORY_MANAGEMENT
+# ifdef BOOST_HAS_THREADS
+ // for some reason the following is not automatically defined
+# if defined( BOOST_MSVC ) | defined( BOOST_INTEL )
+# define __WIN32__
+# endif
+# else
+# define BOOST_NO_MT
+# endif
+
+# ifdef BOOST_MSVC
+# pragma warning( push )
+# pragma warning( disable: 4127 ) // conditional expression is constant
+# endif
+
+# include <boost/pool/pool_alloc.hpp>
+
+# ifdef BOOST_MSVC
+# pragma warning( pop )
+# endif
+#endif
+
+#include <memory> // std::allocator
+
+
+
+namespace sc = boost::statechart;
+
+
+
+//////////////////////////////////////////////////////////////////////////////
+template< class T >
+boost::intrusive_ptr< T > MakeIntrusive( T * pObject )
+{
+ return boost::intrusive_ptr< T >( pObject );
+}
+
+
+//////////////////////////////////////////////////////////////////////////////
+struct BallReturned : sc::event< BallReturned >
+{
+ boost::function1< void, const boost::intrusive_ptr< const BallReturned > & >
+ returnToOpponent;
+ boost::function0< void > abortGame;
+};
+
+struct GameAborted : sc::event< GameAborted > {};
+
+#ifdef CUSTOMIZE_MEMORY_MANAGEMENT
+typedef boost::fast_pool_allocator< int > MyAllocator;
+typedef sc::fifo_scheduler<
+ sc::fifo_worker< MyAllocator >, MyAllocator > MyScheduler;
+#else
+typedef std::allocator< void > MyAllocator;
+typedef sc::fifo_scheduler<> MyScheduler;
+#endif
+
+struct Waiting;
+struct Player : sc::asynchronous_state_machine<
+ Player, Waiting, MyScheduler, MyAllocator >
+{
+ public:
+ Player( my_context ctx, unsigned int maxNoOfReturns ) :
+ my_base( ctx ),
+ maxNoOfReturns_( maxNoOfReturns )
+ {
+ }
+
+ static unsigned int & TotalNoOfProcessedEvents()
+ {
+ return totalNoOfProcessedEvents_;
+ }
+
+ unsigned int GetMaxNoOfReturns() const
+ {
+ return maxNoOfReturns_;
+ }
+
+ private:
+ // This function is defined in the Player.cpp
+ virtual void initiate_impl();
+
+ static unsigned int totalNoOfProcessedEvents_;
+ const unsigned int maxNoOfReturns_;
+};
+
+
+// The following class member specialization ensures that
+// state_machine<>::initiate is not instantiated at a point where Waiting
+// is not defined yet.
+template<>
+void sc::asynchronous_state_machine<
+ Player, Waiting, MyScheduler, MyAllocator >::initiate_impl() {}
+
+
+
+#endif
Added: trunk/libs/statechart/example/PingPong/Waiting.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/statechart/example/PingPong/Waiting.hpp 2008-04-13 09:57:42 EDT (Sun, 13 Apr 2008)
@@ -0,0 +1,96 @@
+#ifndef BOOST_STATECHART_EXAMPLE_WAITING_HPP_INCLUDED
+#define BOOST_STATECHART_EXAMPLE_WAITING_HPP_INCLUDED
+//////////////////////////////////////////////////////////////////////////////
+// Copyright 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)
+//////////////////////////////////////////////////////////////////////////////
+
+
+#include "Player.hpp"
+
+#include <boost/statechart/state.hpp>
+#include <boost/statechart/transition.hpp>
+#include <boost/statechart/custom_reaction.hpp>
+
+#include <boost/intrusive_ptr.hpp>
+#include <boost/mpl/list.hpp>
+#include <boost/function.hpp>
+#include <boost/bind.hpp>
+
+
+
+namespace sc = boost::statechart;
+namespace mpl = boost::mpl;
+
+
+
+//////////////////////////////////////////////////////////////////////////////
+struct Waiting : sc::state< Waiting, Player >
+{
+ public:
+ //////////////////////////////////////////////////////////////////////////
+ typedef mpl::list<
+ sc::custom_reaction< BallReturned >,
+ sc::custom_reaction< GameAborted >
+ > reactions;
+
+ Waiting( my_context ctx ) :
+ my_base( ctx ),
+ noOfReturns_( 0 ),
+ pBallReturned_( new BallReturned() )
+ {
+ outermost_context_type & machine = outermost_context();
+ // as we will always return the same event to the opponent, we construct
+ // and fill it here so that we can reuse it over and over
+ pBallReturned_->returnToOpponent = boost::bind(
+ &MyScheduler::queue_event,
+ &machine.my_scheduler(), machine.my_handle(), _1 );
+ pBallReturned_->abortGame = boost::bind(
+ &MyScheduler::queue_event,
+ &machine.my_scheduler(), machine.my_handle(),
+ MakeIntrusive( new GameAborted() ) );
+ }
+
+ sc::result react( const GameAborted & )
+ {
+ return DestroyMyself();
+ }
+
+ sc::result react( const BallReturned & ballReturned )
+ {
+ outermost_context_type & machine = outermost_context();
+ ++machine.TotalNoOfProcessedEvents();
+
+ if ( noOfReturns_++ < machine.GetMaxNoOfReturns() )
+ {
+ ballReturned.returnToOpponent( pBallReturned_ );
+ return discard_event();
+ }
+ else
+ {
+ ballReturned.abortGame();
+ return DestroyMyself();
+ }
+ }
+
+ private:
+ //////////////////////////////////////////////////////////////////////////
+ sc::result DestroyMyself()
+ {
+ outermost_context_type & machine = outermost_context();
+ machine.my_scheduler().destroy_processor( machine.my_handle() );
+ machine.my_scheduler().terminate();
+ return terminate();
+ }
+
+ // avoids C4512 (assignment operator could not be generated)
+ Waiting & operator=( const Waiting & );
+
+ unsigned int noOfReturns_;
+ const boost::intrusive_ptr< BallReturned > pBallReturned_;
+};
+
+
+
+#endif
Modified: trunk/libs/statechart/test/Jamfile.v2
==============================================================================
--- trunk/libs/statechart/test/Jamfile.v2 (original)
+++ trunk/libs/statechart/test/Jamfile.v2 2008-04-13 09:57:42 EDT (Sun, 13 Apr 2008)
@@ -151,6 +151,6 @@
[ statechart-st-compile-example Handcrafted : Handcrafted : Handcrafted ]
[ statechart-st-compile-example Keyboard : Keyboard : Keyboard : ]
[ statechart-st-compile-example Performance : Performance : Performance ]
- [ statechart-st-compile-example PingPong : PingPong : PingPong ]
+ [ statechart-st-compile-example PingPong : PingPong : PingPong Player ]
[ statechart-st-compile-example StopWatch : StopWatch : StopWatch ]
[ statechart-st-compile-example StopWatch2 : StopWatch : StopWatch2 ] ;
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