blob: 9b333d7c4a13a4d7d50b5e47c8f43ce8aa0c7d67 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
#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< sc::none > MyAllocator;
typedef sc::fifo_scheduler<> MyScheduler;
#endif
//////////////////////////////////////////////////////////////////////////////
struct Player;
struct Waiting;
namespace boost
{
namespace statechart
{
// The following class member specialization ensures that
// state_machine<>::initiate is not instantiated at a point where Waiting
// is not defined yet.
template<>
inline void asynchronous_state_machine<
Player, Waiting, MyScheduler, MyAllocator >::initiate_impl() {}
}
}
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_;
};
#endif
|