⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 waiting.hpp

📁 Boost provides free peer-reviewed portable C++ source libraries. We emphasize libraries that work
💻 HPP
字号:
#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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -