├── .gitattributes ├── .travis.yml ├── CMakeLists.txt ├── Statechart.sln ├── build.jam ├── doc ├── A.gif ├── Camera.gif ├── Camera2.gif ├── CameraWithHistory1.gif ├── CameraWithHistory2.gif ├── DeepHistoryLimitation1.gif ├── DeepHistoryLimitation2.gif ├── EventDispatch.gif ├── ExceptionsAndOrthStates.gif ├── HelloWorld.gif ├── JoinAndFork.gif ├── LCA.gif ├── OrthogonalStates.gif ├── OutermostUnstableState.gif ├── PerformanceCustom1.gif ├── PerformanceCustom2.gif ├── PerformanceCustom3.gif ├── PerformanceCustom4.gif ├── PerformanceNative1.gif ├── PerformanceNative2.gif ├── PerformanceNative3.gif ├── PerformanceNative4.gif ├── PerformanceNormal1.gif ├── PerformanceNormal2.gif ├── PerformanceNormal3.gif ├── PerformanceNormal4.gif ├── SimpleEventDispatch.gif ├── StopWatch.gif ├── ThrowingEntryAction.gif ├── ThrowingInStateReaction.gif ├── ThrowingTransitionAction.gif ├── TransAcrossOrthRegions.gif ├── acknowledgments.html ├── configuration.html ├── contact.html ├── definitions.html ├── faq.html ├── future_and_history.html ├── index.html ├── performance.html ├── rationale.html ├── rationale.pdf ├── reference.html ├── reference.pdf ├── tutorial.html ├── tutorial.pdf └── uml_mapping.html ├── example ├── BitMachine │ ├── BitMachine.cpp │ ├── BitMachine.vcproj │ ├── UniqueObject.hpp │ └── UniqueObjectAllocator.hpp ├── Camera │ ├── Camera.cpp │ ├── Camera.hpp │ ├── Camera.vcproj │ ├── Configuring.cpp │ ├── Configuring.hpp │ ├── Main.cpp │ ├── Precompiled.cpp │ ├── Precompiled.hpp │ ├── Shooting.cpp │ └── Shooting.hpp ├── Handcrafted │ ├── Handcrafted.cpp │ └── Handcrafted.vcproj ├── Jamfile.v2 ├── Keyboard │ ├── Keyboard.cpp │ └── Keyboard.vcproj ├── Performance │ ├── Performance.cpp │ ├── Performance.vcproj │ └── Performance.xls ├── PingPong │ ├── PingPong.cpp │ ├── PingPong.vcproj │ ├── Player.cpp │ ├── Player.hpp │ └── Waiting.hpp └── StopWatch │ ├── StopWatch.cpp │ ├── StopWatch.vcproj │ └── StopWatch2.cpp ├── include └── boost │ └── statechart │ ├── asynchronous_state_machine.hpp │ ├── custom_reaction.hpp │ ├── deep_history.hpp │ ├── deferral.hpp │ ├── detail │ ├── avoid_unused_warning.hpp │ ├── constructor.hpp │ ├── counted_base.hpp │ ├── leaf_state.hpp │ ├── memory.hpp │ ├── node_state.hpp │ ├── reaction_dispatcher.hpp │ ├── rtti_policy.hpp │ └── state_base.hpp │ ├── event.hpp │ ├── event_base.hpp │ ├── event_processor.hpp │ ├── exception_translator.hpp │ ├── fifo_scheduler.hpp │ ├── fifo_worker.hpp │ ├── history.hpp │ ├── in_state_reaction.hpp │ ├── null_exception_translator.hpp │ ├── processor_container.hpp │ ├── result.hpp │ ├── shallow_history.hpp │ ├── simple_state.hpp │ ├── state.hpp │ ├── state_machine.hpp │ ├── termination.hpp │ └── transition.hpp ├── index.html ├── meta └── libraries.json └── test ├── CustomReactionTest.cpp ├── CustomReactionTest.vcproj ├── DeferralBug.cpp ├── DeferralTest.cpp ├── DeferralTest.vcproj ├── FifoSchedulerTest.cpp ├── FifoSchedulerTest.vcproj ├── HistoryTest.cpp ├── HistoryTest.vcproj ├── InStateReactionTest.cpp ├── InStateReactionTest.vcproj ├── InconsistentHistoryTest1.cpp ├── InconsistentHistoryTest1.vcproj ├── InconsistentHistoryTest2.cpp ├── InconsistentHistoryTest2.vcproj ├── InconsistentHistoryTest3.cpp ├── InconsistentHistoryTest3.vcproj ├── InconsistentHistoryTest4.cpp ├── InconsistentHistoryTest4.vcproj ├── InconsistentHistoryTest5.cpp ├── InconsistentHistoryTest5.vcproj ├── InconsistentHistoryTest6.cpp ├── InconsistentHistoryTest6.vcproj ├── InconsistentHistoryTest7.cpp ├── InconsistentHistoryTest7.vcproj ├── InconsistentHistoryTest8.cpp ├── InconsistentHistoryTest8.vcproj ├── InnermostDefault.hpp ├── InvalidChartTest1.cpp ├── InvalidChartTest1.vcproj ├── InvalidChartTest2.cpp ├── InvalidChartTest2.vcproj ├── InvalidChartTest3.cpp ├── InvalidChartTest3.vcproj ├── InvalidResultAssignTest.cpp ├── InvalidResultAssignTest.vcproj ├── InvalidResultCopyTest.cpp ├── InvalidResultCopyTest.vcproj ├── InvalidResultDefCtorTest.cpp ├── InvalidResultDefCtorTest.vcproj ├── InvalidTransitionTest1.cpp ├── InvalidTransitionTest1.vcproj ├── InvalidTransitionTest2.cpp ├── InvalidTransitionTest2.vcproj ├── Jamfile.v2 ├── OuterOrthogonal.hpp ├── StateCastTest.cpp ├── StateCastTest.vcproj ├── StateIterationTest.cpp ├── StateIterationTest.vcproj ├── TerminationTest.cpp ├── TerminationTest.vcproj ├── ThrowingBoostAssert.hpp ├── TransitionTest.cpp ├── TransitionTest.vcproj ├── TriggeringEventTest.cpp ├── TriggeringEventTest.vcproj ├── TuTest.cpp ├── TuTest.hpp ├── TuTest.vcproj ├── TuTestMain.cpp ├── TypeInfoTest.cpp ├── TypeInfoTest.vcproj ├── UnconsumedResultTest.cpp ├── UnconsumedResultTest.vcproj ├── UnsuppDeepHistoryTest.cpp └── UnsuppDeepHistoryTest.vcproj /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto !eol svneol=native#text/plain 2 | *.gitattributes text svneol=native#text/plain 3 | 4 | # Scriptish formats 5 | *.bat text svneol=native#text/plain 6 | *.bsh text svneol=native#text/x-beanshell 7 | *.cgi text svneol=native#text/plain 8 | *.cmd text svneol=native#text/plain 9 | *.js text svneol=native#text/javascript 10 | *.php text svneol=native#text/x-php 11 | *.pl text svneol=native#text/x-perl 12 | *.pm text svneol=native#text/x-perl 13 | *.py text svneol=native#text/x-python 14 | *.sh eol=lf svneol=LF#text/x-sh 15 | configure eol=lf svneol=LF#text/x-sh 16 | 17 | # Image formats 18 | *.bmp binary svneol=unset#image/bmp 19 | *.gif binary svneol=unset#image/gif 20 | *.ico binary svneol=unset#image/ico 21 | *.jpeg binary svneol=unset#image/jpeg 22 | *.jpg binary svneol=unset#image/jpeg 23 | *.png binary svneol=unset#image/png 24 | *.tif binary svneol=unset#image/tiff 25 | *.tiff binary svneol=unset#image/tiff 26 | *.svg text svneol=native#image/svg%2Bxml 27 | 28 | # Data formats 29 | *.pdf binary svneol=unset#application/pdf 30 | *.avi binary svneol=unset#video/avi 31 | *.doc binary svneol=unset#application/msword 32 | *.dsp text svneol=crlf#text/plain 33 | *.dsw text svneol=crlf#text/plain 34 | *.eps binary svneol=unset#application/postscript 35 | *.gz binary svneol=unset#application/gzip 36 | *.mov binary svneol=unset#video/quicktime 37 | *.mp3 binary svneol=unset#audio/mpeg 38 | *.ppt binary svneol=unset#application/vnd.ms-powerpoint 39 | *.ps binary svneol=unset#application/postscript 40 | *.psd binary svneol=unset#application/photoshop 41 | *.rdf binary svneol=unset#text/rdf 42 | *.rss text svneol=unset#text/xml 43 | *.rtf binary svneol=unset#text/rtf 44 | *.sln text svneol=native#text/plain 45 | *.swf binary svneol=unset#application/x-shockwave-flash 46 | *.tgz binary svneol=unset#application/gzip 47 | *.vcproj text svneol=native#text/xml 48 | *.vcxproj text svneol=native#text/xml 49 | *.vsprops text svneol=native#text/xml 50 | *.wav binary svneol=unset#audio/wav 51 | *.xls binary svneol=unset#application/vnd.ms-excel 52 | *.zip binary svneol=unset#application/zip 53 | 54 | # Text formats 55 | .htaccess text svneol=native#text/plain 56 | *.bbk text svneol=native#text/xml 57 | *.cmake text svneol=native#text/plain 58 | *.css text svneol=native#text/css 59 | *.dtd text svneol=native#text/xml 60 | *.htm text svneol=native#text/html 61 | *.html text svneol=native#text/html 62 | *.ini text svneol=native#text/plain 63 | *.log text svneol=native#text/plain 64 | *.mak text svneol=native#text/plain 65 | *.qbk text svneol=native#text/plain 66 | *.rst text svneol=native#text/plain 67 | *.sql text svneol=native#text/x-sql 68 | *.txt text svneol=native#text/plain 69 | *.xhtml text svneol=native#text/xhtml%2Bxml 70 | *.xml text svneol=native#text/xml 71 | *.xsd text svneol=native#text/xml 72 | *.xsl text svneol=native#text/xml 73 | *.xslt text svneol=native#text/xml 74 | *.xul text svneol=native#text/xul 75 | *.yml text svneol=native#text/plain 76 | boost-no-inspect text svneol=native#text/plain 77 | CHANGES text svneol=native#text/plain 78 | COPYING text svneol=native#text/plain 79 | INSTALL text svneol=native#text/plain 80 | Jamfile text svneol=native#text/plain 81 | Jamroot text svneol=native#text/plain 82 | Jamfile.v2 text svneol=native#text/plain 83 | Jamrules text svneol=native#text/plain 84 | Makefile* text svneol=native#text/plain 85 | README text svneol=native#text/plain 86 | TODO text svneol=native#text/plain 87 | 88 | # Code formats 89 | *.c text svneol=native#text/plain 90 | *.cpp text svneol=native#text/plain 91 | *.h text svneol=native#text/plain 92 | *.hpp text svneol=native#text/plain 93 | *.ipp text svneol=native#text/plain 94 | *.tpp text svneol=native#text/plain 95 | *.jam text svneol=native#text/plain 96 | *.java text svneol=native#text/plain 97 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2016, 2017 Peter Dimov 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) 4 | 5 | language: cpp 6 | 7 | sudo: false 8 | 9 | python: "2.7" 10 | 11 | branches: 12 | only: 13 | - master 14 | - develop 15 | - /feature\/.*/ 16 | 17 | env: 18 | matrix: 19 | - BOGUS_JOB=true 20 | 21 | matrix: 22 | 23 | exclude: 24 | - env: BOGUS_JOB=true 25 | 26 | include: 27 | - os: linux 28 | compiler: g++ 29 | env: TOOLSET=gcc CXXSTD=03,11 30 | 31 | - os: linux 32 | compiler: g++-5 33 | env: TOOLSET=gcc-5 CXXSTD=03,11,14,1z 34 | addons: 35 | apt: 36 | packages: 37 | - g++-5 38 | sources: 39 | - ubuntu-toolchain-r-test 40 | 41 | - os: linux 42 | compiler: g++-6 43 | env: TOOLSET=gcc-6 CXXSTD=03,11,14,1z 44 | addons: 45 | apt: 46 | packages: 47 | - g++-6 48 | sources: 49 | - ubuntu-toolchain-r-test 50 | 51 | - os: linux 52 | compiler: g++-7 53 | env: TOOLSET=gcc-7 CXXSTD=03,11,14,17 54 | addons: 55 | apt: 56 | packages: 57 | - g++-7 58 | sources: 59 | - ubuntu-toolchain-r-test 60 | 61 | - os: linux 62 | compiler: clang++ 63 | env: TOOLSET=clang CXXSTD=03,11,14,1z 64 | addons: 65 | apt: 66 | packages: 67 | - libstdc++-4.9-dev 68 | sources: 69 | - ubuntu-toolchain-r-test 70 | 71 | - os: osx 72 | compiler: clang++ 73 | env: TOOLSET=clang CXXSTD=03,11,14,1z 74 | 75 | install: 76 | - BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true 77 | - cd .. 78 | - git clone -b $BOOST_BRANCH https://github.com/boostorg/boost.git boost-root 79 | - cd boost-root 80 | - git submodule update --init tools/build 81 | - git submodule update --init libs/config 82 | - git submodule update --init tools/boostdep 83 | - cp -r $TRAVIS_BUILD_DIR/* libs/statechart 84 | - python tools/boostdep/depinst/depinst.py statechart 85 | - ./bootstrap.sh 86 | - ./b2 headers 87 | 88 | script: 89 | - ./b2 -j3 libs/statechart/test toolset=$TOOLSET cxxstd=$CXXSTD 90 | 91 | notifications: 92 | email: 93 | on_success: always 94 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated by `boostdep --cmake statechart` 2 | # Copyright 2020 Peter Dimov 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # https://www.boost.org/LICENSE_1_0.txt 5 | 6 | cmake_minimum_required(VERSION 3.5...3.16) 7 | 8 | project(boost_statechart VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) 9 | 10 | add_library(boost_statechart INTERFACE) 11 | add_library(Boost::statechart ALIAS boost_statechart) 12 | 13 | target_include_directories(boost_statechart INTERFACE include) 14 | 15 | target_link_libraries(boost_statechart 16 | INTERFACE 17 | Boost::assert 18 | Boost::bind 19 | Boost::config 20 | Boost::conversion 21 | Boost::core 22 | Boost::detail 23 | Boost::function 24 | Boost::mpl 25 | Boost::smart_ptr 26 | Boost::static_assert 27 | Boost::thread 28 | Boost::type_traits 29 | ) 30 | 31 | if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt") 32 | 33 | add_subdirectory(test) 34 | 35 | endif() 36 | 37 | -------------------------------------------------------------------------------- /build.jam: -------------------------------------------------------------------------------- 1 | # Copyright René Ferdinand Rivera Morell 2024 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at 4 | # http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | require-b2 5.2 ; 7 | 8 | constant boost_dependencies : 9 | /boost/assert//boost_assert 10 | /boost/bind//boost_bind 11 | /boost/config//boost_config 12 | /boost/conversion//boost_conversion 13 | /boost/core//boost_core 14 | /boost/detail//boost_detail 15 | /boost/function//boost_function 16 | /boost/mpl//boost_mpl 17 | /boost/smart_ptr//boost_smart_ptr 18 | /boost/static_assert//boost_static_assert 19 | /boost/thread//boost_thread 20 | /boost/type_traits//boost_type_traits ; 21 | 22 | project /boost/statechart 23 | ; 24 | 25 | explicit 26 | [ alias boost_statechart : : : 27 | : include $(boost_dependencies) ] 28 | [ alias all : boost_statechart example test ] 29 | ; 30 | 31 | call-if : boost-library statechart 32 | ; 33 | -------------------------------------------------------------------------------- /doc/A.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/A.gif -------------------------------------------------------------------------------- /doc/Camera.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/Camera.gif -------------------------------------------------------------------------------- /doc/Camera2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/Camera2.gif -------------------------------------------------------------------------------- /doc/CameraWithHistory1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/CameraWithHistory1.gif -------------------------------------------------------------------------------- /doc/CameraWithHistory2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/CameraWithHistory2.gif -------------------------------------------------------------------------------- /doc/DeepHistoryLimitation1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/DeepHistoryLimitation1.gif -------------------------------------------------------------------------------- /doc/DeepHistoryLimitation2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/DeepHistoryLimitation2.gif -------------------------------------------------------------------------------- /doc/EventDispatch.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/EventDispatch.gif -------------------------------------------------------------------------------- /doc/ExceptionsAndOrthStates.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/ExceptionsAndOrthStates.gif -------------------------------------------------------------------------------- /doc/HelloWorld.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/HelloWorld.gif -------------------------------------------------------------------------------- /doc/JoinAndFork.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/JoinAndFork.gif -------------------------------------------------------------------------------- /doc/LCA.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/LCA.gif -------------------------------------------------------------------------------- /doc/OrthogonalStates.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/OrthogonalStates.gif -------------------------------------------------------------------------------- /doc/OutermostUnstableState.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/OutermostUnstableState.gif -------------------------------------------------------------------------------- /doc/PerformanceCustom1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/PerformanceCustom1.gif -------------------------------------------------------------------------------- /doc/PerformanceCustom2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/PerformanceCustom2.gif -------------------------------------------------------------------------------- /doc/PerformanceCustom3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/PerformanceCustom3.gif -------------------------------------------------------------------------------- /doc/PerformanceCustom4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/PerformanceCustom4.gif -------------------------------------------------------------------------------- /doc/PerformanceNative1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/PerformanceNative1.gif -------------------------------------------------------------------------------- /doc/PerformanceNative2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/PerformanceNative2.gif -------------------------------------------------------------------------------- /doc/PerformanceNative3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/PerformanceNative3.gif -------------------------------------------------------------------------------- /doc/PerformanceNative4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/PerformanceNative4.gif -------------------------------------------------------------------------------- /doc/PerformanceNormal1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/PerformanceNormal1.gif -------------------------------------------------------------------------------- /doc/PerformanceNormal2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/PerformanceNormal2.gif -------------------------------------------------------------------------------- /doc/PerformanceNormal3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/PerformanceNormal3.gif -------------------------------------------------------------------------------- /doc/PerformanceNormal4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/PerformanceNormal4.gif -------------------------------------------------------------------------------- /doc/SimpleEventDispatch.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/SimpleEventDispatch.gif -------------------------------------------------------------------------------- /doc/StopWatch.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/StopWatch.gif -------------------------------------------------------------------------------- /doc/ThrowingEntryAction.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/ThrowingEntryAction.gif -------------------------------------------------------------------------------- /doc/ThrowingInStateReaction.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/ThrowingInStateReaction.gif -------------------------------------------------------------------------------- /doc/ThrowingTransitionAction.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/ThrowingTransitionAction.gif -------------------------------------------------------------------------------- /doc/TransAcrossOrthRegions.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/TransAcrossOrthRegions.gif -------------------------------------------------------------------------------- /doc/acknowledgments.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | The Boost Statechart Library - Acknowledgments 12 | 13 | 14 | 15 | 17 | 18 | 22 | 23 | 28 | 29 |
19 |

C++ Boost

21 |
24 |

The Boost Statechart Library

25 | 26 |

Acknowledgments

27 |
30 |
31 | 32 |

Very special thanks go to:

33 | 34 | 43 | 44 |

Special thanks go to:

45 | 46 | 86 | 87 |

Thanks for feedback and/or encouragement go to:

88 | 89 |

Bardur Arantsson, Arne Babnik, Robert Bell, Bohdan, Wayne Chao, 90 | Topher Cooper, Philippe David, Peter Dimov, Reece Dunn, Grant Erickson, 91 | John Fuller, Jeff Garland, Eugene Gladyshev, David A. Greene, Douglas 92 | Gregor, Gustavo Guerra, Aleksey Gurtovoy, Federico J. Fernández, 93 | Iain K. Hanson, Steve Hawkes, David B. Held, Jürgen Hunold, Sean 94 | Kelly, Oliver Kowalke, Thomas Mathys, Simon Meiklejohn, Jiang Miao, Johan 95 | Nilsson, Matthieu Paindavoine, Chris Paulse, Yuval Ronen, Chris Russell, 96 | Bryan Silverthorn, Rob Stewart, Kwee Heong Tan, Marcin Tustin, Vincent N. 97 | Virgilio, Gang Wang, Steven Watanabe, Richard Webb and Scott Woods.

98 |
99 | 100 |

Valid HTML 4.01 Transitional

103 | 104 |

Revised 06 November, 2010

105 | 106 |

Copyright © 2003-2010 Andreas Huber 107 | Dönni

108 | 109 | 110 |

Distributed under the Boost Software License, Version 1.0. (See 111 | accompanying file LICENSE_1_0.txt or 112 | copy at http://www.boost.org/LICENSE_1_0.txt)

114 | 115 | 116 | -------------------------------------------------------------------------------- /doc/contact.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | The Boost Statechart Library - Author 12 | 13 | 14 | 15 | 17 | 18 | 22 | 23 | 28 | 29 |
19 |

C++ Boost

21 |
24 |

The Boost Statechart Library

25 | 26 |

Contacting the author

27 |
30 |
31 | 32 |

First of all, thank you for considering to provide feedback about 33 | Boost.Statechart! All feedback (including questions) is valuable for the 34 | progress of the library and its documentation. Please post to either of the 35 | following groups if the matter could also be of interest to other 36 | people:

37 | 38 | 46 | 47 |

Please prefix the subject line of your post with [statechart]. 48 | This will help all group members to quickly find the threads they are 49 | interested in.

50 | 51 |

I try hard to regularly read both lists but every now and then I'm on 52 | holiday or even miss a post. If you don't get a satisfactory answer within 53 | a few days or feel that the matter is of no interest to others, you can 54 | also reach me by email. To prevent spammers from harvesting my email off 55 | the web server I can only give you an obfuscated address: ahd6974-spamboostorgtrap@yahoo.com. 57 | You need to remove the words spam and trap to obtain my real 58 | address.

59 |
60 | 61 |

Valid HTML 4.01 Transitional

64 | 65 |

Revised 66 | 09 January, 2007

67 | 68 |

Copyright © 2006-2007 69 | Andreas Huber Dönni

70 | 71 |

Distributed under the Boost Software License, Version 1.0. (See 72 | accompanying file LICENSE_1_0.txt or 73 | copy at http://www.boost.org/LICENSE_1_0.txt)

75 | 76 | 77 | -------------------------------------------------------------------------------- /doc/rationale.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/rationale.pdf -------------------------------------------------------------------------------- /doc/reference.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/reference.pdf -------------------------------------------------------------------------------- /doc/tutorial.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/doc/tutorial.pdf -------------------------------------------------------------------------------- /example/BitMachine/UniqueObject.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_EXAMPLE_UNIQUE_OBJECT_HPP_INCLUDED 2 | #define BOOST_STATECHART_EXAMPLE_UNIQUE_OBJECT_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2002-2006 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include "UniqueObjectAllocator.hpp" 12 | 13 | #include // size_t 14 | 15 | 16 | 17 | ////////////////////////////////////////////////////////////////////////////// 18 | template< class Derived > 19 | class UniqueObject 20 | { 21 | public: 22 | ////////////////////////////////////////////////////////////////////////// 23 | void * operator new( std::size_t size ) 24 | { 25 | return UniqueObjectAllocator< Derived >::allocate( size ); 26 | } 27 | 28 | void operator delete( void * p, std::size_t size ) 29 | { 30 | UniqueObjectAllocator< Derived >::deallocate( p, size ); 31 | } 32 | 33 | protected: 34 | ////////////////////////////////////////////////////////////////////////// 35 | UniqueObject() {} 36 | ~UniqueObject() {} 37 | }; 38 | 39 | 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /example/BitMachine/UniqueObjectAllocator.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_EXAMPLE_UNIQUE_OBJECT_ALLOCATOR_HPP_INCLUDED 2 | #define BOOST_STATECHART_EXAMPLE_UNIQUE_OBJECT_ALLOCATOR_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2002-2006 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | 13 | #include 14 | 15 | #ifdef BOOST_MSVC 16 | # pragma warning( push ) 17 | # pragma warning( disable: 4511 ) // copy constructor could not be generated 18 | # pragma warning( disable: 4512 ) // assignment operator could not be generated 19 | #endif 20 | 21 | #include 22 | 23 | #ifdef BOOST_MSVC 24 | # pragma warning( pop ) 25 | #endif 26 | 27 | #include 28 | #include 29 | 30 | #include // size_t 31 | 32 | 33 | 34 | ////////////////////////////////////////////////////////////////////////////// 35 | template< class T > 36 | class UniqueObjectAllocator 37 | { 38 | public: 39 | ////////////////////////////////////////////////////////////////////////// 40 | static void * allocate( std::size_t size ) 41 | { 42 | boost::statechart::detail::avoid_unused_warning( size ); 43 | BOOST_ASSERT( !constructed_ && ( size == sizeof( T ) ) ); 44 | constructed_ = true; 45 | return &storage_.data_[ 0 ]; 46 | } 47 | 48 | static void deallocate( void * p, std::size_t size ) 49 | { 50 | boost::statechart::detail::avoid_unused_warning( p ); 51 | boost::statechart::detail::avoid_unused_warning( size ); 52 | BOOST_ASSERT( constructed_ && 53 | ( p == &storage_.data_[ 0 ] ) && ( size == sizeof( T ) ) ); 54 | constructed_ = false; 55 | } 56 | 57 | private: 58 | ////////////////////////////////////////////////////////////////////////// 59 | union storage 60 | { 61 | char data_[ sizeof( T ) ]; 62 | typename boost::type_with_alignment< 63 | boost::alignment_of< T >::value >::type aligner_; 64 | }; 65 | 66 | static bool constructed_; 67 | static storage storage_; 68 | }; 69 | 70 | template< class T > 71 | bool UniqueObjectAllocator< T >::constructed_ = false; 72 | template< class T > 73 | typename UniqueObjectAllocator< T >::storage 74 | UniqueObjectAllocator< T >::storage_; 75 | 76 | 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /example/Camera/Camera.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2002-2006 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include "Precompiled.hpp" 10 | #include "Camera.hpp" 11 | #include "Configuring.hpp" 12 | #include "Shooting.hpp" 13 | 14 | 15 | 16 | ////////////////////////////////////////////////////////////////////////////// 17 | NotShooting::NotShooting() 18 | { 19 | std::cout << "Entering NotShooting\n"; 20 | } 21 | 22 | NotShooting::~NotShooting() 23 | { 24 | std::cout << "Exiting NotShooting\n"; 25 | } 26 | 27 | sc::result NotShooting::react( const EvShutterHalf & ) 28 | { 29 | if ( context< Camera >().IsBatteryLow() ) 30 | { 31 | return forward_event(); 32 | } 33 | else 34 | { 35 | return transit< Shooting >(); 36 | } 37 | } 38 | 39 | ////////////////////////////////////////////////////////////////////////////// 40 | Idle::Idle() 41 | { 42 | std::cout << "Entering Idle\n"; 43 | } 44 | 45 | Idle::~Idle() 46 | { 47 | std::cout << "Exiting Idle\n"; 48 | } 49 | 50 | sc::result Idle::react( const EvConfig & ) 51 | { 52 | return transit< Configuring >(); 53 | } 54 | -------------------------------------------------------------------------------- /example/Camera/Camera.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_EXAMPLE_CAMERA_HPP_INCLUDED 2 | #define BOOST_STATECHART_EXAMPLE_CAMERA_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2002-2006 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | 18 | #ifdef BOOST_INTEL 19 | # pragma warning( disable: 304 ) // access control not specified 20 | #endif 21 | 22 | 23 | 24 | namespace sc = boost::statechart; 25 | 26 | 27 | 28 | ////////////////////////////////////////////////////////////////////////////// 29 | struct EvShutterHalf : sc::event< EvShutterHalf > {}; 30 | struct EvShutterFull : sc::event< EvShutterFull > {}; 31 | struct EvShutterRelease : sc::event< EvShutterRelease > {}; 32 | struct EvConfig : sc::event< EvConfig > {}; 33 | 34 | struct NotShooting; 35 | struct Camera : sc::state_machine< Camera, NotShooting > 36 | { 37 | bool IsMemoryAvailable() const { return true; } 38 | bool IsBatteryLow() const { return false; } 39 | }; 40 | 41 | struct Idle; 42 | struct NotShooting : sc::simple_state< NotShooting, Camera, Idle > 43 | { 44 | typedef sc::custom_reaction< EvShutterHalf > reactions; 45 | 46 | NotShooting(); 47 | ~NotShooting(); 48 | 49 | sc::result react( const EvShutterHalf & ); 50 | }; 51 | 52 | struct Idle : sc::simple_state< Idle, NotShooting > 53 | { 54 | typedef sc::custom_reaction< EvConfig > reactions; 55 | 56 | Idle(); 57 | ~Idle(); 58 | 59 | sc::result react( const EvConfig & ); 60 | }; 61 | 62 | 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /example/Camera/Configuring.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2002-2006 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include "Precompiled.hpp" 10 | #include "Configuring.hpp" 11 | #include 12 | #include 13 | 14 | 15 | 16 | Configuring::Configuring() 17 | { 18 | std::cout << "Entering Configuring\n"; 19 | } 20 | 21 | Configuring::~Configuring() 22 | { 23 | std::cout << "Exiting Configuring\n"; 24 | } 25 | -------------------------------------------------------------------------------- /example/Camera/Configuring.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_EXAMPLE_CONFIGURING_HPP_INCLUDED 2 | #define BOOST_STATECHART_EXAMPLE_CONFIGURING_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2002-2006 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include "Camera.hpp" 12 | 13 | #include 14 | #include 15 | 16 | #include 17 | 18 | #ifdef BOOST_INTEL 19 | # pragma warning( disable: 304 ) // access control not specified 20 | #endif 21 | 22 | 23 | 24 | namespace sc = boost::statechart; 25 | 26 | 27 | 28 | ////////////////////////////////////////////////////////////////////////////// 29 | struct Configuring : sc::simple_state< Configuring, NotShooting > 30 | { 31 | typedef sc::transition< EvConfig, Idle > reactions; 32 | 33 | Configuring(); 34 | ~Configuring(); 35 | }; 36 | 37 | 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /example/Camera/Main.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2002-2006 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | ////////////////////////////////////////////////////////////////////////////// 10 | // This program shows how a state machine can be spread over several 11 | // translation units if necessary. The inner workings of a digital camera are 12 | // modeled, the corresponding state chart looks as follows: 13 | // 14 | // --------------------------- 15 | // | | 16 | // | NotShooting | 17 | // | | 18 | // | ------------- |<---O 19 | // | O--->| Idle | | -------------- 20 | // | ------------- | EvShutterHalf | | 21 | // | | ^ |------------------>| Shooting | 22 | // | EvConfig | | EvConfig | | | 23 | // | v | | EvShutterRelease | | 24 | // | ------------- |<------------------| | 25 | // | | Configuring | | | | 26 | // | ------------- | -------------- 27 | // --------------------------- 28 | // 29 | // The states Configuring and Shooting will contain a large amount of logic, 30 | // so they are implemented in their own translation units. This way one team 31 | // could implement the Configuring mode while the other would work on the 32 | // Shooting mode. Once the above state chart is implemented, the teams could 33 | // work completely independently of each other. 34 | 35 | 36 | 37 | #include "Precompiled.hpp" 38 | #include "Camera.hpp" 39 | #include 40 | 41 | 42 | 43 | ////////////////////////////////////////////////////////////////////////////// 44 | char GetKey() 45 | { 46 | char key; 47 | std::cin >> key; 48 | return key; 49 | } 50 | 51 | 52 | ////////////////////////////////////////////////////////////////////////////// 53 | int main() 54 | { 55 | std::cout << "Boost.Statechart Camera example\n\n"; 56 | 57 | std::cout << "h: Press shutter half-way\n"; 58 | std::cout << "f: Press shutter fully\n"; 59 | std::cout << "r: Release shutter\n"; 60 | std::cout << "c: Enter/exit configuration\n"; 61 | std::cout << "e: Exits the program\n\n"; 62 | std::cout << "You may chain commands, e.g. hfr first presses the shutter half-way,\n"; 63 | std::cout << "fully and then releases it.\n\n"; 64 | 65 | 66 | Camera myCamera; 67 | myCamera.initiate(); 68 | 69 | char key = GetKey(); 70 | 71 | while ( key != 'e' ) 72 | { 73 | switch( key ) 74 | { 75 | case 'h': 76 | { 77 | myCamera.process_event( EvShutterHalf() ); 78 | } 79 | break; 80 | 81 | case 'f': 82 | { 83 | myCamera.process_event( EvShutterFull() ); 84 | } 85 | break; 86 | 87 | case 'r': 88 | { 89 | myCamera.process_event( EvShutterRelease() ); 90 | } 91 | break; 92 | 93 | case 'c': 94 | { 95 | myCamera.process_event( EvConfig() ); 96 | } 97 | break; 98 | 99 | default: 100 | { 101 | std::cout << "Invalid key!\n"; 102 | } 103 | break; 104 | } 105 | 106 | key = GetKey(); 107 | } 108 | 109 | return 0; 110 | } 111 | -------------------------------------------------------------------------------- /example/Camera/Precompiled.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2002-2006 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include "Precompiled.hpp" 10 | -------------------------------------------------------------------------------- /example/Camera/Precompiled.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_EXAMPLE_PRECOMPILED_HPP_INCLUDED 2 | #define BOOST_STATECHART_EXAMPLE_PRECOMPILED_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2002-2006 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /example/Camera/Shooting.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2002-2006 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include "Precompiled.hpp" 10 | #include "Shooting.hpp" 11 | #include 12 | 13 | #include 14 | 15 | #ifdef BOOST_INTEL 16 | # pragma warning( disable: 383 ) // reference to temporary used 17 | #endif 18 | 19 | 20 | 21 | ////////////////////////////////////////////////////////////////////////////// 22 | Shooting::Shooting() 23 | { 24 | std::cout << "Entering Shooting\n"; 25 | } 26 | 27 | Shooting::~Shooting() 28 | { 29 | std::cout << "Exiting Shooting\n"; 30 | } 31 | 32 | ////////////////////////////////////////////////////////////////////////////// 33 | struct Storing : sc::simple_state< Storing, Shooting > 34 | { 35 | Storing() 36 | { 37 | std::cout << "Picture taken!\n"; 38 | } 39 | }; 40 | 41 | ////////////////////////////////////////////////////////////////////////////// 42 | struct Focused : sc::simple_state< Focused, Shooting > 43 | { 44 | typedef sc::custom_reaction< EvShutterFull > reactions; 45 | 46 | sc::result react( const EvShutterFull & ); 47 | }; 48 | 49 | sc::result Focused::react( const EvShutterFull & ) 50 | { 51 | if ( context< Camera >().IsMemoryAvailable() ) 52 | { 53 | return transit< Storing >(); 54 | } 55 | else 56 | { 57 | std::cout << "Cache memory full. Please wait...\n"; 58 | return discard_event(); 59 | } 60 | } 61 | 62 | ////////////////////////////////////////////////////////////////////////////// 63 | Focusing::Focusing( my_context ctx ) : my_base( ctx ) 64 | { 65 | post_event( boost::intrusive_ptr< EvInFocus >( new EvInFocus() ) ); 66 | } 67 | 68 | sc::result Focusing::react( const EvInFocus & evt ) 69 | { 70 | return transit< Focused >( &Shooting::DisplayFocused, evt ); 71 | } 72 | -------------------------------------------------------------------------------- /example/Camera/Shooting.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_EXAMPLE_SHOOTING_HPP_INCLUDED 2 | #define BOOST_STATECHART_EXAMPLE_SHOOTING_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2002-2006 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include "Camera.hpp" 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | #ifdef BOOST_INTEL 24 | # pragma warning( disable: 304 ) // access control not specified 25 | #endif 26 | 27 | 28 | 29 | namespace sc = boost::statechart; 30 | namespace mpl = boost::mpl; 31 | 32 | 33 | 34 | ////////////////////////////////////////////////////////////////////////////// 35 | struct EvInFocus : sc::event< EvInFocus > {}; 36 | 37 | struct Focusing; 38 | struct Shooting : sc::simple_state< Shooting, Camera, Focusing > 39 | { 40 | typedef sc::transition< EvShutterRelease, NotShooting > reactions; 41 | 42 | Shooting(); 43 | ~Shooting(); 44 | 45 | void DisplayFocused( const EvInFocus & ) 46 | { 47 | std::cout << "Focused!\n"; 48 | } 49 | }; 50 | 51 | struct Focusing : sc::state< Focusing, Shooting > 52 | { 53 | typedef mpl::list< 54 | sc::custom_reaction< EvInFocus >, 55 | sc::deferral< EvShutterFull > 56 | > reactions; 57 | 58 | Focusing( my_context ctx ); 59 | sc::result react( const EvInFocus & ); 60 | }; 61 | 62 | 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /example/Handcrafted/Handcrafted.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 27 | 30 | 33 | 36 | 39 | 42 | 61 | 64 | 67 | 70 | 81 | 84 | 87 | 90 | 93 | 96 | 99 | 102 | 103 | 111 | 114 | 117 | 120 | 123 | 126 | 146 | 149 | 152 | 155 | 167 | 170 | 173 | 176 | 179 | 182 | 185 | 188 | 189 | 190 | 191 | 192 | 193 | 197 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | -------------------------------------------------------------------------------- /example/Jamfile.v2: -------------------------------------------------------------------------------- 1 | ############################################################################## 2 | # Copyright 2005-2006 Andreas Huber Doenni 3 | # Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | # ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ############################################################################## 6 | 7 | project libs/statechart/example 8 | : requirements /boost/statechart//boost_statechart ; 9 | 10 | local custom = CUSTOMIZE_MEMORY_MANAGEMENT ; 11 | local native = BOOST_STATECHART_USE_NATIVE_RTTI ; 12 | 13 | rule independent-obj-build ( 14 | name : directory : cpp-sources + : requirements * ) 15 | { 16 | local objs ; 17 | 18 | for local cpp-source in $(cpp-sources) 19 | { 20 | obj $(name)$(cpp-source) 21 | : $(directory)/$(cpp-source).cpp : $(requirements) ; 22 | objs += $(name)$(cpp-source) ; 23 | } 24 | 25 | return $(objs) ; 26 | } 27 | 28 | rule statechart-st-example-build ( 29 | name : directory : cpp-sources + : requirements * ) 30 | { 31 | exe $(name) : [ independent-obj-build $(name) 32 | : $(directory) : $(cpp-sources) 33 | # Some platforms have either problems with the automatic 34 | # detection of the threading mode (e.g. vc-7_1 & 35 | # gcc >= 3.4.0) or don't support single-threaded mode 36 | # (e.g. vc-8_0). We therefore manually turn MT 37 | # off here 38 | : single BOOST_DISABLE_THREADS $(requirements) ] ; 39 | 40 | return $(name) ; 41 | } 42 | 43 | rule statechart-mt-example-build ( 44 | name : directory : cpp-sources + : requirements * ) 45 | { 46 | exe $(name) : [ independent-obj-build $(name) 47 | : $(directory) : $(cpp-sources) 48 | : multi $(requirements) ] 49 | /boost/thread//boost_thread ; 50 | 51 | return $(name) ; 52 | } 53 | 54 | stage run 55 | : [ statechart-st-example-build BitMachine : BitMachine : BitMachine ] 56 | [ statechart-st-example-build Camera 57 | : Camera : Camera Configuring Main Shooting ] 58 | [ statechart-st-example-build Handcrafted : Handcrafted : Handcrafted ] 59 | [ statechart-st-example-build KeyboardNormal : Keyboard : Keyboard ] 60 | [ statechart-st-example-build KeyboardNative 61 | : Keyboard : Keyboard : $(native) ] 62 | [ statechart-st-example-build PingPongSingle 63 | : PingPong : PingPong Player : $(custom) /boost/pool//boost_pool ] 64 | [ statechart-mt-example-build PingPongMulti1 65 | : PingPong : PingPong Player : $(custom) /boost/pool//boost_pool ] 66 | [ statechart-mt-example-build PingPongMulti2 67 | : PingPong : PingPong Player : $(custom) USE_TWO_THREADS /boost/pool//boost_pool ] 68 | [ statechart-st-example-build StopWatch : StopWatch : StopWatch ] 69 | [ statechart-st-example-build StopWatch2 : StopWatch : StopWatch2 ] 70 | [ statechart-st-example-build PerformanceNormal 71 | : Performance : Performance ] 72 | [ statechart-st-example-build PerformanceCustom 73 | : Performance : Performance : $(custom) /boost/pool//boost_pool ] 74 | [ statechart-st-example-build PerformanceNative 75 | : Performance : Performance : $(native) ] 76 | : on EXE SHARED_LIB ; 77 | -------------------------------------------------------------------------------- /example/Performance/Performance.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/statechart/2b1270f7ab9027320a6b7e187ea1d37d329b3624/example/Performance/Performance.xls -------------------------------------------------------------------------------- /example/PingPong/Player.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2008 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include "Player.hpp" 10 | #include "Waiting.hpp" // Waiting.hpp is only included here 11 | 12 | 13 | 14 | ////////////////////////////////////////////////////////////////////////////// 15 | void Player::initiate_impl() 16 | { 17 | // Since we can only initiate at a point where the definitions of all the 18 | // states in the initial state configuration are known, we duplicate 19 | // the implementation of asynchronous_state_machine<>::initiate_impl() here 20 | sc::state_machine< Player, Waiting, MyAllocator >::initiate(); 21 | } 22 | 23 | 24 | unsigned int Player::totalNoOfProcessedEvents_ = 0; 25 | -------------------------------------------------------------------------------- /example/PingPong/Player.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_EXAMPLE_PLAYER_HPP_INCLUDED 2 | #define BOOST_STATECHART_EXAMPLE_PLAYER_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2008 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #ifdef CUSTOMIZE_MEMORY_MANAGEMENT 21 | # ifdef BOOST_HAS_THREADS 22 | // for some reason the following is not automatically defined 23 | # if defined( BOOST_MSVC ) | defined( BOOST_INTEL ) 24 | # define __WIN32__ 25 | # endif 26 | # else 27 | # define BOOST_NO_MT 28 | # endif 29 | 30 | # ifdef BOOST_MSVC 31 | # pragma warning( push ) 32 | # pragma warning( disable: 4127 ) // conditional expression is constant 33 | # endif 34 | 35 | # include 36 | 37 | # ifdef BOOST_MSVC 38 | # pragma warning( pop ) 39 | # endif 40 | #endif 41 | 42 | #include // std::allocator 43 | 44 | 45 | 46 | namespace sc = boost::statechart; 47 | 48 | 49 | 50 | ////////////////////////////////////////////////////////////////////////////// 51 | template< class T > 52 | boost::intrusive_ptr< T > MakeIntrusive( T * pObject ) 53 | { 54 | return boost::intrusive_ptr< T >( pObject ); 55 | } 56 | 57 | 58 | ////////////////////////////////////////////////////////////////////////////// 59 | struct BallReturned : sc::event< BallReturned > 60 | { 61 | boost::function1< void, const boost::intrusive_ptr< const BallReturned > & > 62 | returnToOpponent; 63 | boost::function0< void > abortGame; 64 | }; 65 | 66 | struct GameAborted : sc::event< GameAborted > {}; 67 | 68 | #ifdef CUSTOMIZE_MEMORY_MANAGEMENT 69 | typedef boost::fast_pool_allocator< int > MyAllocator; 70 | typedef sc::fifo_scheduler< 71 | sc::fifo_worker< MyAllocator >, MyAllocator > MyScheduler; 72 | #else 73 | typedef std::allocator< sc::none > MyAllocator; 74 | typedef sc::fifo_scheduler<> MyScheduler; 75 | #endif 76 | 77 | 78 | ////////////////////////////////////////////////////////////////////////////// 79 | struct Player; 80 | struct Waiting; 81 | 82 | namespace boost 83 | { 84 | namespace statechart 85 | { 86 | // The following class member specialization ensures that 87 | // state_machine<>::initiate is not instantiated at a point where Waiting 88 | // is not defined yet. 89 | template<> 90 | inline void asynchronous_state_machine< 91 | Player, Waiting, MyScheduler, MyAllocator >::initiate_impl() {} 92 | } 93 | } 94 | 95 | 96 | struct Player : sc::asynchronous_state_machine< 97 | Player, Waiting, MyScheduler, MyAllocator > 98 | { 99 | public: 100 | Player( my_context ctx, unsigned int maxNoOfReturns ) : 101 | my_base( ctx ), 102 | maxNoOfReturns_( maxNoOfReturns ) 103 | { 104 | } 105 | 106 | static unsigned int & TotalNoOfProcessedEvents() 107 | { 108 | return totalNoOfProcessedEvents_; 109 | } 110 | 111 | unsigned int GetMaxNoOfReturns() const 112 | { 113 | return maxNoOfReturns_; 114 | } 115 | 116 | private: 117 | // This function is defined in the Player.cpp 118 | virtual void initiate_impl(); 119 | 120 | static unsigned int totalNoOfProcessedEvents_; 121 | const unsigned int maxNoOfReturns_; 122 | }; 123 | 124 | 125 | 126 | #endif 127 | -------------------------------------------------------------------------------- /example/PingPong/Waiting.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_EXAMPLE_WAITING_HPP_INCLUDED 2 | #define BOOST_STATECHART_EXAMPLE_WAITING_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2008 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | #include "Player.hpp" 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | 22 | 23 | namespace sc = boost::statechart; 24 | namespace mpl = boost::mpl; 25 | 26 | 27 | 28 | ////////////////////////////////////////////////////////////////////////////// 29 | struct Waiting : sc::state< Waiting, Player > 30 | { 31 | public: 32 | ////////////////////////////////////////////////////////////////////////// 33 | typedef mpl::list< 34 | sc::custom_reaction< BallReturned >, 35 | sc::custom_reaction< GameAborted > 36 | > reactions; 37 | 38 | Waiting( my_context ctx ) : 39 | my_base( ctx ), 40 | noOfReturns_( 0 ), 41 | pBallReturned_( new BallReturned() ) 42 | { 43 | outermost_context_type & machine = outermost_context(); 44 | // as we will always return the same event to the opponent, we construct 45 | // and fill it here so that we can reuse it over and over 46 | pBallReturned_->returnToOpponent = boost::bind( 47 | &MyScheduler::queue_event, 48 | &machine.my_scheduler(), machine.my_handle(), _1 ); 49 | pBallReturned_->abortGame = boost::bind( 50 | &MyScheduler::queue_event, 51 | &machine.my_scheduler(), machine.my_handle(), 52 | MakeIntrusive( new GameAborted() ) ); 53 | } 54 | 55 | sc::result react( const GameAborted & ) 56 | { 57 | return DestroyMyself(); 58 | } 59 | 60 | sc::result react( const BallReturned & ballReturned ) 61 | { 62 | outermost_context_type & machine = outermost_context(); 63 | ++machine.TotalNoOfProcessedEvents(); 64 | 65 | if ( noOfReturns_++ < machine.GetMaxNoOfReturns() ) 66 | { 67 | ballReturned.returnToOpponent( pBallReturned_ ); 68 | return discard_event(); 69 | } 70 | else 71 | { 72 | ballReturned.abortGame(); 73 | return DestroyMyself(); 74 | } 75 | } 76 | 77 | private: 78 | ////////////////////////////////////////////////////////////////////////// 79 | sc::result DestroyMyself() 80 | { 81 | outermost_context_type & machine = outermost_context(); 82 | machine.my_scheduler().destroy_processor( machine.my_handle() ); 83 | machine.my_scheduler().terminate(); 84 | return terminate(); 85 | } 86 | 87 | // avoids C4512 (assignment operator could not be generated) 88 | Waiting & operator=( const Waiting & ); 89 | 90 | unsigned int noOfReturns_; 91 | const boost::intrusive_ptr< BallReturned > pBallReturned_; 92 | }; 93 | 94 | 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /include/boost/statechart/asynchronous_state_machine.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_ASYNCHRONOUS_STATE_MACHINE_HPP_INCLUDED 2 | #define BOOST_STATECHART_ASYNCHRONOUS_STATE_MACHINE_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2002-2006 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include // std::allocator 17 | 18 | 19 | namespace boost 20 | { 21 | namespace statechart 22 | { 23 | 24 | 25 | 26 | class event_base; 27 | 28 | 29 | 30 | ////////////////////////////////////////////////////////////////////////////// 31 | template< class MostDerived, 32 | class InitialState, 33 | class Scheduler = fifo_scheduler<>, 34 | class Allocator = std::allocator< none >, 35 | class ExceptionTranslator = null_exception_translator > 36 | class asynchronous_state_machine : public state_machine< 37 | MostDerived, InitialState, Allocator, ExceptionTranslator >, 38 | public event_processor< Scheduler > 39 | { 40 | typedef state_machine< MostDerived, 41 | InitialState, Allocator, ExceptionTranslator > machine_base; 42 | typedef event_processor< Scheduler > processor_base; 43 | protected: 44 | ////////////////////////////////////////////////////////////////////////// 45 | typedef asynchronous_state_machine my_base; 46 | 47 | asynchronous_state_machine( typename processor_base::my_context ctx ) : 48 | processor_base( ctx ) 49 | { 50 | } 51 | 52 | virtual ~asynchronous_state_machine() {} 53 | 54 | public: 55 | ////////////////////////////////////////////////////////////////////////// 56 | // The following declarations should be private. 57 | // They are only public because many compilers lack template friends. 58 | ////////////////////////////////////////////////////////////////////////// 59 | void terminate() 60 | { 61 | processor_base::terminate(); 62 | } 63 | 64 | private: 65 | ////////////////////////////////////////////////////////////////////////// 66 | virtual void initiate_impl() 67 | { 68 | machine_base::initiate(); 69 | } 70 | 71 | virtual void process_event_impl( const event_base & evt ) 72 | { 73 | machine_base::process_event( evt ); 74 | } 75 | 76 | virtual void terminate_impl() 77 | { 78 | machine_base::terminate(); 79 | } 80 | }; 81 | 82 | 83 | 84 | } // namespace statechart 85 | } // namespace boost 86 | 87 | 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /include/boost/statechart/custom_reaction.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_CUSTOM_REACTION_HPP_INCLUDED 2 | #define BOOST_STATECHART_CUSTOM_REACTION_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2002-2006 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | 13 | #include // boost::polymorphic_downcast 14 | 15 | 16 | 17 | namespace boost 18 | { 19 | namespace statechart 20 | { 21 | 22 | 23 | 24 | class event_base; 25 | 26 | ////////////////////////////////////////////////////////////////////////////// 27 | template< class Event > 28 | class custom_reaction 29 | { 30 | public: 31 | ////////////////////////////////////////////////////////////////////////// 32 | // The following declarations should be private. 33 | // They are only public because many compilers lack template friends. 34 | ////////////////////////////////////////////////////////////////////////// 35 | template< class State, class EventBase, class IdType > 36 | static detail::reaction_result react( 37 | State & stt, const EventBase & evt, const IdType & eventType ) 38 | { 39 | if ( eventType == Event::static_type() ) 40 | { 41 | return detail::result_utility::get_result( 42 | stt.react( *polymorphic_downcast< const Event * >( &evt ) ) ); 43 | } 44 | else 45 | { 46 | return detail::no_reaction; 47 | } 48 | } 49 | }; 50 | 51 | template<> 52 | class custom_reaction< event_base > 53 | { 54 | public: 55 | ////////////////////////////////////////////////////////////////////////// 56 | // The following declarations should be private. 57 | // They are only public because many compilers lack template friends. 58 | ////////////////////////////////////////////////////////////////////////// 59 | template< class State, class EventBase, class IdType > 60 | static detail::reaction_result react( 61 | State & stt, const EventBase & evt, const IdType & ) 62 | { 63 | return detail::result_utility::get_result( stt.react( evt ) ); 64 | } 65 | }; 66 | 67 | 68 | 69 | } // namespace statechart 70 | } // namespace boost 71 | 72 | 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /include/boost/statechart/deep_history.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_DEEP_HISTORY_HPP_INCLUDED 2 | #define BOOST_STATECHART_DEEP_HISTORY_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2002-2006 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | #include 13 | 14 | 15 | 16 | namespace boost 17 | { 18 | namespace statechart 19 | { 20 | 21 | 22 | 23 | ////////////////////////////////////////////////////////////////////////////// 24 | template< class DefaultState > 25 | class deep_history 26 | { 27 | public: 28 | ////////////////////////////////////////////////////////////////////////// 29 | // If you receive a 30 | // "use of undefined type 'boost::STATIC_ASSERTION_FAILURE'" or similar 31 | // compiler error here then you forgot to pass either 32 | // statechart::has_deep_history or statechart::has_full_history as the 33 | // last parameter of DefaultState's context. 34 | BOOST_STATIC_ASSERT( DefaultState::context_type::deep_history::value ); 35 | 36 | ////////////////////////////////////////////////////////////////////////// 37 | // The following declarations should be private. 38 | // They are only public because many compilers lack template friends. 39 | ////////////////////////////////////////////////////////////////////////// 40 | typedef typename DefaultState::outermost_context_base_type 41 | outermost_context_base_type; 42 | typedef typename DefaultState::context_type context_type; 43 | typedef typename DefaultState::context_ptr_type context_ptr_type; 44 | typedef typename DefaultState::context_type_list context_type_list; 45 | typedef typename DefaultState::orthogonal_position orthogonal_position; 46 | 47 | static void deep_construct( 48 | const context_ptr_type & pContext, 49 | outermost_context_base_type & outermostContextBase ) 50 | { 51 | outermostContextBase.template construct_with_deep_history< 52 | DefaultState >( pContext ); 53 | } 54 | }; 55 | 56 | 57 | 58 | } // namespace statechart 59 | } // namespace boost 60 | 61 | 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /include/boost/statechart/deferral.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_DEFERRAL_HPP_INCLUDED 2 | #define BOOST_STATECHART_DEFERRAL_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2002-2006 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | 13 | 14 | 15 | namespace boost 16 | { 17 | namespace statechart 18 | { 19 | 20 | 21 | 22 | class event_base; 23 | 24 | ////////////////////////////////////////////////////////////////////////////// 25 | template< class Event > 26 | class deferral 27 | { 28 | public: 29 | ////////////////////////////////////////////////////////////////////////// 30 | // The following declarations should be private. 31 | // They are only public because many compilers lack template friends. 32 | ////////////////////////////////////////////////////////////////////////// 33 | template< class State, class EventBase, class IdType > 34 | static detail::reaction_result react( 35 | State & stt, const EventBase &, const IdType & eventType ) 36 | { 37 | if ( eventType == Event::static_type() ) 38 | { 39 | return detail::result_utility::get_result( stt.defer_event() ); 40 | } 41 | else 42 | { 43 | return detail::no_reaction; 44 | } 45 | } 46 | }; 47 | 48 | template<> 49 | class deferral< event_base > 50 | { 51 | public: 52 | ////////////////////////////////////////////////////////////////////////// 53 | // The following declarations should be private. 54 | // They are only public because many compilers lack template friends. 55 | ////////////////////////////////////////////////////////////////////////// 56 | template< class State, class EventBase, class IdType > 57 | static detail::reaction_result react( 58 | State & stt, const EventBase &, const IdType & ) 59 | { 60 | return detail::result_utility::get_result( stt.defer_event() ); 61 | } 62 | }; 63 | 64 | 65 | 66 | } // namespace statechart 67 | } // namespace boost 68 | 69 | 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /include/boost/statechart/detail/avoid_unused_warning.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_DETAIL_AVOID_UNUSED_WARNING_HPP_INCLUDED 2 | #define BOOST_STATECHART_DETAIL_AVOID_UNUSED_WARNING_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2002-2006 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | namespace boost 12 | { 13 | namespace statechart 14 | { 15 | namespace detail 16 | { 17 | 18 | 19 | 20 | template< typename T > 21 | inline void avoid_unused_warning( const T & ) {} 22 | 23 | 24 | 25 | } // namespace detail 26 | } // namespace statechart 27 | } // namespace boost 28 | 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /include/boost/statechart/detail/constructor.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_DETAIL_CONSTRUCTOR_HPP_INCLUDED 2 | #define BOOST_STATECHART_DETAIL_CONSTRUCTOR_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2002-2006 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | 25 | 26 | namespace boost 27 | { 28 | namespace statechart 29 | { 30 | namespace detail 31 | { 32 | 33 | 34 | 35 | template< class ContextList, class OutermostContextBase > 36 | struct constructor; 37 | 38 | ////////////////////////////////////////////////////////////////////////////// 39 | template< class ContextList, class OutermostContextBase > 40 | struct outer_constructor 41 | { 42 | typedef typename mpl::front< ContextList >::type to_construct; 43 | typedef typename to_construct::context_ptr_type context_ptr_type; 44 | typedef typename to_construct::inner_context_ptr_type 45 | inner_context_ptr_type; 46 | 47 | typedef typename to_construct::inner_initial_list inner_initial_list; 48 | typedef typename mpl::pop_front< ContextList >::type inner_context_list; 49 | typedef typename mpl::front< inner_context_list >::type::orthogonal_position 50 | inner_orthogonal_position; 51 | typedef typename mpl::advance< 52 | typename mpl::begin< inner_initial_list >::type, 53 | inner_orthogonal_position >::type to_construct_iter; 54 | 55 | typedef typename mpl::erase< 56 | inner_initial_list, 57 | to_construct_iter, 58 | typename mpl::end< inner_initial_list >::type 59 | >::type first_inner_initial_list; 60 | 61 | typedef typename mpl::erase< 62 | inner_initial_list, 63 | typename mpl::begin< inner_initial_list >::type, 64 | typename mpl::next< to_construct_iter >::type 65 | >::type last_inner_initial_list; 66 | 67 | static void construct( 68 | const context_ptr_type & pContext, 69 | OutermostContextBase & outermostContextBase ) 70 | { 71 | const inner_context_ptr_type pInnerContext = 72 | to_construct::shallow_construct( pContext, outermostContextBase ); 73 | to_construct::template deep_construct_inner< 74 | first_inner_initial_list >( pInnerContext, outermostContextBase ); 75 | constructor< inner_context_list, OutermostContextBase >::construct( 76 | pInnerContext, outermostContextBase ); 77 | to_construct::template deep_construct_inner< 78 | last_inner_initial_list >( pInnerContext, outermostContextBase ); 79 | } 80 | }; 81 | 82 | ////////////////////////////////////////////////////////////////////////////// 83 | template< class ContextList, class OutermostContextBase > 84 | struct inner_constructor 85 | { 86 | typedef typename mpl::front< ContextList >::type to_construct; 87 | typedef typename to_construct::context_ptr_type context_ptr_type; 88 | 89 | static void construct( 90 | const context_ptr_type & pContext, 91 | OutermostContextBase & outermostContextBase ) 92 | { 93 | to_construct::deep_construct( pContext, outermostContextBase ); 94 | } 95 | }; 96 | 97 | ////////////////////////////////////////////////////////////////////////////// 98 | template< class ContextList, class OutermostContextBase > 99 | struct constructor_impl : public mpl::eval_if< 100 | mpl::equal_to< mpl::size< ContextList >, mpl::long_< 1 > >, 101 | mpl::identity< inner_constructor< ContextList, OutermostContextBase > >, 102 | mpl::identity< outer_constructor< ContextList, OutermostContextBase > > > 103 | { 104 | }; 105 | 106 | 107 | ////////////////////////////////////////////////////////////////////////////// 108 | template< class ContextList, class OutermostContextBase > 109 | struct constructor : 110 | constructor_impl< ContextList, OutermostContextBase >::type {}; 111 | 112 | ////////////////////////////////////////////////////////////////////////////// 113 | template< class CommonContext, class DestinationState > 114 | struct make_context_list 115 | { 116 | typedef typename mpl::reverse< typename mpl::push_front< 117 | typename mpl::erase< 118 | typename DestinationState::context_type_list, 119 | typename mpl::find< 120 | typename DestinationState::context_type_list, 121 | CommonContext 122 | >::type, 123 | typename mpl::end< 124 | typename DestinationState::context_type_list 125 | >::type 126 | >::type, 127 | DestinationState 128 | >::type >::type type; 129 | }; 130 | 131 | 132 | 133 | } // namespace detail 134 | } // namespace statechart 135 | } // namespace boost 136 | 137 | 138 | 139 | #endif 140 | -------------------------------------------------------------------------------- /include/boost/statechart/detail/counted_base.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_DETAIL_COUNTED_BASE_HPP_INCLUDED 2 | #define BOOST_STATECHART_DETAIL_COUNTED_BASE_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2002-2006 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | #include // BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP 13 | 14 | 15 | 16 | namespace boost 17 | { 18 | namespace statechart 19 | { 20 | namespace detail 21 | { 22 | 23 | 24 | 25 | template< bool NeedsLocking > 26 | struct count_base 27 | { 28 | count_base() : count_( 0 ) {} 29 | mutable boost::detail::atomic_count count_; 30 | }; 31 | 32 | template<> 33 | struct count_base< false > 34 | { 35 | count_base() : count_( 0 ) {} 36 | mutable long count_; 37 | }; 38 | 39 | ////////////////////////////////////////////////////////////////////////////// 40 | template< bool NeedsLocking = true > 41 | class counted_base : private count_base< NeedsLocking > 42 | { 43 | typedef count_base< NeedsLocking > base_type; 44 | public: 45 | ////////////////////////////////////////////////////////////////////////// 46 | bool ref_counted() const 47 | { 48 | return base_type::count_ != 0; 49 | } 50 | 51 | long ref_count() const 52 | { 53 | return base_type::count_; 54 | } 55 | 56 | protected: 57 | ////////////////////////////////////////////////////////////////////////// 58 | counted_base() {} 59 | ~counted_base() {} 60 | 61 | // do nothing copy implementation is intentional (the number of 62 | // referencing pointers of the source and the destination is not changed 63 | // through the copy operation) 64 | counted_base( const counted_base & ) : base_type() {} 65 | counted_base & operator=( const counted_base & ) { return *this; } 66 | 67 | public: 68 | ////////////////////////////////////////////////////////////////////////// 69 | // The following declarations should be private. 70 | // They are only public because many compilers lack template friends. 71 | ////////////////////////////////////////////////////////////////////////// 72 | void add_ref() const 73 | { 74 | ++base_type::count_; 75 | } 76 | 77 | bool release() const 78 | { 79 | BOOST_ASSERT( base_type::count_ > 0 ); 80 | return --base_type::count_ == 0; 81 | } 82 | }; 83 | 84 | 85 | 86 | } // namespace detail 87 | } // namespace statechart 88 | } // namespace boost 89 | 90 | 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /include/boost/statechart/detail/leaf_state.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_DETAIL_LEAF_STATE_HPP_INCLUDED 2 | #define BOOST_STATECHART_DETAIL_LEAF_STATE_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2002-2006 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | 13 | 14 | 15 | namespace boost 16 | { 17 | namespace statechart 18 | { 19 | namespace detail 20 | { 21 | 22 | 23 | 24 | ////////////////////////////////////////////////////////////////////////////// 25 | template< class Allocator, class RttiPolicy > 26 | class leaf_state : public state_base< Allocator, RttiPolicy > 27 | { 28 | typedef state_base< Allocator, RttiPolicy > base_type; 29 | protected: 30 | ////////////////////////////////////////////////////////////////////////// 31 | leaf_state( typename RttiPolicy::id_provider_type idProvider ) : 32 | base_type( idProvider ) 33 | { 34 | } 35 | 36 | ~leaf_state() {} 37 | 38 | public: 39 | ////////////////////////////////////////////////////////////////////////// 40 | // The following declarations should be private. 41 | // They are only public because many compilers lack template friends. 42 | ////////////////////////////////////////////////////////////////////////// 43 | void set_list_position( 44 | typename base_type::state_list_type::iterator listPosition ) 45 | { 46 | listPosition_ = listPosition; 47 | } 48 | 49 | typedef typename base_type::leaf_state_ptr_type 50 | direct_state_base_ptr_type; 51 | 52 | virtual void remove_from_state_list( 53 | typename base_type::state_list_type::iterator & statesEnd, 54 | typename base_type::node_state_base_ptr_type & pOutermostUnstableState, 55 | bool performFullExit ) 56 | { 57 | --statesEnd; 58 | swap( *listPosition_, *statesEnd ); 59 | ( *listPosition_ )->set_list_position( listPosition_ ); 60 | direct_state_base_ptr_type & pState = *statesEnd; 61 | // Because the list owns the leaf_state, this leads to the immediate 62 | // termination of this state. 63 | pState->exit_impl( pState, pOutermostUnstableState, performFullExit ); 64 | } 65 | 66 | virtual void exit_impl( 67 | direct_state_base_ptr_type & pSelf, 68 | typename base_type::node_state_base_ptr_type & pOutermostUnstableState, 69 | bool performFullExit ) = 0; 70 | 71 | private: 72 | ////////////////////////////////////////////////////////////////////////// 73 | typename base_type::state_list_type::iterator listPosition_; 74 | }; 75 | 76 | 77 | 78 | } // namespace detail 79 | } // namespace statechart 80 | } // namespace boost 81 | 82 | 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /include/boost/statechart/detail/memory.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_DETAIL_MEMORY_HPP_INCLUDED 2 | #define BOOST_STATECHART_DETAIL_MEMORY_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2005-2006 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | #include // std::size_t 17 | #include // std::allocator_traits 18 | 19 | 20 | namespace boost 21 | { 22 | namespace statechart 23 | { 24 | 25 | #ifdef BOOST_NO_CXX11_ALLOCATOR 26 | typedef void none; 27 | #else 28 | // The specialization std::allocator doesn't satisfy C++17's 29 | // allocator completeness requirements. Therefore it is deprecated 30 | // and should no longer be used. Supply a replacement type for all 31 | // the allocator default template arguments in the library. 32 | struct none {}; 33 | #endif 34 | 35 | namespace detail 36 | { 37 | 38 | 39 | 40 | // defect: 'allocate' and 'deallocate' cannot handle stateful allocators! 41 | 42 | template< class MostDerived, class Allocator > 43 | void * allocate( std::size_t size ) 44 | { 45 | avoid_unused_warning( size ); 46 | // The assert below fails when memory is allocated for an event<>, 47 | // simple_state<> or state<> subtype object, *and* the first template 48 | // parameter passed to one of these templates is not equal to the most- 49 | // derived object being constructed. 50 | // The following examples apply to all these subtypes: 51 | // // Example 1 52 | // struct A {}; 53 | // struct B : sc::simple_state< A, /* ... */ > 54 | // // Above, the first template parameter must be equal to the most- 55 | // // derived type 56 | // 57 | // // Example 2 58 | // struct A : sc::event< A > 59 | // struct B : A { /* ... */ }; 60 | // void f() { delete new B(); } 61 | // // Above the most-derived type being constructed is B, but A was passed 62 | // // as the most-derived type to event<>. 63 | BOOST_ASSERT( size == sizeof( MostDerived ) ); 64 | typedef typename boost::detail::allocator::rebind_to< 65 | Allocator, MostDerived 66 | >::type md_allocator; 67 | md_allocator alloc; 68 | #ifdef BOOST_NO_CXX11_ALLOCATOR 69 | return alloc.allocate( 1, static_cast< MostDerived * >( 0 ) ); 70 | #else 71 | typedef std::allocator_traits md_traits; 72 | return md_traits::allocate( alloc, 1, static_cast< MostDerived * >( 0 ) ); 73 | #endif 74 | } 75 | 76 | template< class MostDerived, class Allocator > 77 | void deallocate( void * pObject ) 78 | { 79 | typedef typename boost::detail::allocator::rebind_to< 80 | Allocator, MostDerived 81 | >::type md_allocator; 82 | md_allocator alloc; 83 | #ifdef BOOST_NO_CXX11_ALLOCATOR 84 | alloc.deallocate( static_cast< MostDerived * >( pObject ), 1 ); 85 | #else 86 | typedef std::allocator_traits md_traits; 87 | md_traits::deallocate( alloc, static_cast< MostDerived * >( pObject ), 1 ); 88 | #endif 89 | } 90 | 91 | 92 | 93 | } // namespace detail 94 | } // namespace statechart 95 | } // namespace boost 96 | 97 | 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /include/boost/statechart/detail/reaction_dispatcher.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_REACTION_DISPATCHER_HPP_INCLUDED 2 | #define BOOST_STATECHART_REACTION_DISPATCHER_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2008 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | 13 | #include 14 | 15 | #include // boost::polymorphic_downcast 16 | #include 17 | 18 | 19 | 20 | namespace boost 21 | { 22 | namespace statechart 23 | { 24 | namespace detail 25 | { 26 | 27 | 28 | 29 | ////////////////////////////////////////////////////////////////////////////// 30 | template< class Event > 31 | struct no_context 32 | { 33 | void no_function( const Event & ); 34 | }; 35 | 36 | ////////////////////////////////////////////////////////////////////////////// 37 | template< 38 | class Reactions, class State, class EventBase, class Event, 39 | class ActionContext, class IdType > 40 | class reaction_dispatcher 41 | { 42 | private: 43 | struct without_action 44 | { 45 | static result react( State & stt, const EventBase & ) 46 | { 47 | return Reactions::react_without_action( stt ); 48 | } 49 | }; 50 | 51 | struct base_with_action 52 | { 53 | static result react( State & stt, const EventBase & evt ) 54 | { 55 | return Reactions::react_with_action( stt, evt ); 56 | } 57 | }; 58 | 59 | struct base 60 | { 61 | static result react( 62 | State & stt, const EventBase & evt, const IdType & ) 63 | { 64 | typedef typename mpl::if_< 65 | is_same< ActionContext, detail::no_context< Event > >, 66 | without_action, base_with_action 67 | >::type reaction; 68 | return reaction::react( stt, evt ); 69 | } 70 | }; 71 | 72 | struct derived_with_action 73 | { 74 | static result react( State & stt, const EventBase & evt ) 75 | { 76 | return Reactions::react_with_action( 77 | stt, *polymorphic_downcast< const Event * >( &evt ) ); 78 | } 79 | }; 80 | 81 | struct derived 82 | { 83 | static result react( 84 | State & stt, const EventBase & evt, const IdType & eventType ) 85 | { 86 | if ( eventType == Event::static_type() ) 87 | { 88 | typedef typename mpl::if_< 89 | is_same< ActionContext, detail::no_context< Event > >, 90 | without_action, derived_with_action 91 | >::type reaction; 92 | return reaction::react( stt, evt ); 93 | } 94 | else 95 | { 96 | return detail::result_utility::make_result( detail::no_reaction ); 97 | } 98 | } 99 | }; 100 | 101 | public: 102 | static reaction_result react( 103 | State & stt, const EventBase & evt, const IdType & eventType ) 104 | { 105 | typedef typename mpl::if_< 106 | is_same< Event, EventBase >, base, derived 107 | >::type reaction; 108 | return result_utility::get_result( 109 | reaction::react( stt, evt, eventType ) ); 110 | } 111 | }; 112 | 113 | 114 | 115 | } // namespace detail 116 | } // namespace statechart 117 | } // namespace boost 118 | 119 | 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /include/boost/statechart/event.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_EVENT_HPP_INCLUDED 2 | #define BOOST_STATECHART_EVENT_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2002-2007 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include // boost::polymorphic_downcast 16 | 17 | #include // std::allocator 18 | 19 | 20 | 21 | namespace boost 22 | { 23 | namespace statechart 24 | { 25 | 26 | 27 | 28 | ////////////////////////////////////////////////////////////////////////////// 29 | template< class MostDerived, class Allocator = std::allocator< none > > 30 | class event : public detail::rtti_policy::rtti_derived_type< 31 | MostDerived, event_base > 32 | { 33 | public: 34 | ////////////////////////////////////////////////////////////////////////// 35 | // Compiler-generated copy constructor and copy assignment operator are 36 | // fine 37 | 38 | void * operator new( std::size_t size ) 39 | { 40 | return detail::allocate< MostDerived, Allocator >( size ); 41 | } 42 | 43 | void * operator new( std::size_t, void * p ) 44 | { 45 | return p; 46 | } 47 | 48 | void operator delete( void * pEvent ) 49 | { 50 | detail::deallocate< MostDerived, Allocator >( pEvent ); 51 | } 52 | 53 | void operator delete( void * pEvent, void * p ) 54 | { 55 | } 56 | 57 | protected: 58 | ////////////////////////////////////////////////////////////////////////// 59 | event() {} 60 | virtual ~event() {} 61 | 62 | private: 63 | ////////////////////////////////////////////////////////////////////////// 64 | virtual intrusive_ptr< const event_base > clone() const 65 | { 66 | return intrusive_ptr< const event_base >( new MostDerived( 67 | *polymorphic_downcast< const MostDerived * >( this ) ) ); 68 | } 69 | }; 70 | 71 | 72 | 73 | } // namespace statechart 74 | } // namespace boost 75 | 76 | 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /include/boost/statechart/event_base.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_EVENT_BASE_HPP_INCLUDED 2 | #define BOOST_STATECHART_EVENT_BASE_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2002-2006 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | 19 | 20 | namespace boost 21 | { 22 | namespace statechart 23 | { 24 | namespace detail 25 | { 26 | 27 | 28 | 29 | // This helper is necessary because there doesn't seem to be consensus among 30 | // compilers on how a friend declaration for a function in another namespace 31 | // has to look like. 32 | class delete_helper 33 | { 34 | public: 35 | template< class T > 36 | static void delete_object( const T * pObject ) 37 | { 38 | delete pObject; 39 | } 40 | }; 41 | 42 | 43 | 44 | } // namespace detail 45 | 46 | 47 | 48 | ////////////////////////////////////////////////////////////////////////////// 49 | class event_base : public detail::rtti_policy::rtti_base_type< 50 | detail::counted_base<> > 51 | { 52 | typedef detail::rtti_policy::rtti_base_type< 53 | detail::counted_base<> > base_type; 54 | public: 55 | ////////////////////////////////////////////////////////////////////////// 56 | intrusive_ptr< const event_base > intrusive_from_this() const; 57 | 58 | protected: 59 | ////////////////////////////////////////////////////////////////////////// 60 | event_base( detail::rtti_policy::id_provider_type idProvider ) : 61 | base_type( idProvider ) 62 | { 63 | } 64 | 65 | virtual ~event_base() {} 66 | 67 | private: 68 | ////////////////////////////////////////////////////////////////////////// 69 | virtual intrusive_ptr< const event_base > clone() const = 0; 70 | 71 | friend class detail::delete_helper; 72 | }; 73 | 74 | 75 | 76 | #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP 77 | } // namespace statechart 78 | #endif 79 | 80 | 81 | 82 | inline void intrusive_ptr_add_ref( const ::boost::statechart::event_base * pBase ) 83 | { 84 | pBase->add_ref(); 85 | } 86 | 87 | inline void intrusive_ptr_release( const ::boost::statechart::event_base * pBase ) 88 | { 89 | if ( pBase->release() ) 90 | { 91 | ::boost::statechart::detail::delete_helper::delete_object( pBase ); 92 | } 93 | } 94 | 95 | 96 | 97 | #ifndef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP 98 | } // namespace statechart 99 | #endif 100 | namespace statechart 101 | { 102 | 103 | 104 | 105 | // We're implementing this here so that GCC3.4.2 can find 106 | // intrusive_ptr_add_ref, which is indirectly called from the intrusive_ptr 107 | // ctor. 108 | inline intrusive_ptr< const event_base > event_base::intrusive_from_this() const 109 | { 110 | if ( base_type::ref_counted() ) 111 | { 112 | return intrusive_ptr< const event_base >( this ); 113 | } 114 | else 115 | { 116 | return clone(); 117 | } 118 | } 119 | 120 | 121 | 122 | } // namespace statechart 123 | } // namespace boost 124 | 125 | 126 | 127 | #endif 128 | -------------------------------------------------------------------------------- /include/boost/statechart/event_processor.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_EVENT_PROCESSOR_INCLUDED 2 | #define BOOST_STATECHART_EVENT_PROCESSOR_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2002-2008 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | namespace boost 12 | { 13 | namespace statechart 14 | { 15 | 16 | 17 | 18 | class event_base; 19 | 20 | 21 | 22 | ////////////////////////////////////////////////////////////////////////////// 23 | template< class Scheduler > 24 | class event_processor 25 | { 26 | public: 27 | ////////////////////////////////////////////////////////////////////////// 28 | virtual ~event_processor() {} 29 | 30 | Scheduler & my_scheduler() const 31 | { 32 | return myScheduler_; 33 | } 34 | 35 | typedef typename Scheduler::processor_handle processor_handle; 36 | 37 | processor_handle my_handle() const 38 | { 39 | return myHandle_; 40 | } 41 | 42 | void initiate() 43 | { 44 | initiate_impl(); 45 | } 46 | 47 | void process_event( const event_base & evt ) 48 | { 49 | process_event_impl( evt ); 50 | } 51 | 52 | void terminate() 53 | { 54 | terminate_impl(); 55 | } 56 | 57 | protected: 58 | ////////////////////////////////////////////////////////////////////////// 59 | typedef const typename Scheduler::processor_context & my_context; 60 | 61 | event_processor( my_context ctx ) : 62 | myScheduler_( ctx.my_scheduler() ), 63 | myHandle_( ctx.my_handle() ) 64 | { 65 | } 66 | 67 | private: 68 | ////////////////////////////////////////////////////////////////////////// 69 | virtual void initiate_impl() = 0; 70 | virtual void process_event_impl( const event_base & evt ) = 0; 71 | virtual void terminate_impl() = 0; 72 | 73 | // avoids C4512 (assignment operator could not be generated) 74 | event_processor & operator=( const event_processor & ); 75 | 76 | Scheduler & myScheduler_; 77 | const processor_handle myHandle_; 78 | }; 79 | 80 | 81 | 82 | } // namespace statechart 83 | } // namespace boost 84 | 85 | 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /include/boost/statechart/exception_translator.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_EXCEPTION_TRANSLATOR_HPP_INCLUDED 2 | #define BOOST_STATECHART_EXCEPTION_TRANSLATOR_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2002-2006 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | #include 13 | 14 | 15 | 16 | namespace boost 17 | { 18 | namespace statechart 19 | { 20 | 21 | 22 | 23 | ////////////////////////////////////////////////////////////////////////////// 24 | class exception_thrown : public event< exception_thrown > {}; 25 | 26 | 27 | 28 | ////////////////////////////////////////////////////////////////////////////// 29 | template< class ExceptionEvent = exception_thrown > 30 | class exception_translator 31 | { 32 | public: 33 | ////////////////////////////////////////////////////////////////////////// 34 | // The following declarations should be private. 35 | // They are only public because many compilers lack template friends. 36 | ////////////////////////////////////////////////////////////////////////// 37 | template< class Action, class ExceptionEventHandler > 38 | result operator()( Action action, ExceptionEventHandler eventHandler ) 39 | { 40 | try 41 | { 42 | return action(); 43 | } 44 | catch ( ... ) 45 | { 46 | return eventHandler( ExceptionEvent() ); 47 | } 48 | } 49 | }; 50 | 51 | 52 | 53 | } // namespace statechart 54 | } // namespace boost 55 | 56 | 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /include/boost/statechart/history.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_HISTORY_HPP_INCLUDED 2 | #define BOOST_STATECHART_HISTORY_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2002-2006 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | #include 13 | 14 | 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /include/boost/statechart/in_state_reaction.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_IN_STATE_REACTION_HPP_INCLUDED 2 | #define BOOST_STATECHART_IN_STATE_REACTION_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2005-2008 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | 13 | #include 14 | 15 | 16 | 17 | namespace boost 18 | { 19 | namespace statechart 20 | { 21 | 22 | 23 | 24 | class event_base; 25 | 26 | ////////////////////////////////////////////////////////////////////////////// 27 | template< class Event, 28 | class ReactionContext = detail::no_context< Event >, 29 | void ( ReactionContext::*pAction )( const Event & ) = 30 | &detail::no_context< Event >::no_function > 31 | class in_state_reaction 32 | { 33 | private: 34 | ////////////////////////////////////////////////////////////////////////// 35 | template< class State > 36 | struct reactions 37 | { 38 | static result react_without_action( State & stt ) 39 | { 40 | return stt.discard_event(); 41 | } 42 | 43 | static result react_with_action( State & stt, const Event & evt ) 44 | { 45 | ( stt.template context< ReactionContext >().*pAction )( evt ); 46 | return react_without_action( stt ); 47 | } 48 | }; 49 | 50 | public: 51 | ////////////////////////////////////////////////////////////////////////// 52 | // The following declarations should be private. 53 | // They are only public because many compilers lack template friends. 54 | ////////////////////////////////////////////////////////////////////////// 55 | template< class State, class EventBase, class IdType > 56 | static detail::reaction_result react( 57 | State & stt, const EventBase & evt, const IdType & eventType ) 58 | { 59 | typedef detail::reaction_dispatcher< 60 | reactions< State >, State, EventBase, Event, ReactionContext, IdType 61 | > dispatcher; 62 | return dispatcher::react( stt, evt, eventType ); 63 | } 64 | }; 65 | 66 | 67 | 68 | } // namespace statechart 69 | } // namespace boost 70 | 71 | 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /include/boost/statechart/null_exception_translator.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_NULL_EXCEPTION_TRANSLATOR_HPP_INCLUDED 2 | #define BOOST_STATECHART_NULL_EXCEPTION_TRANSLATOR_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2002-2006 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | 13 | 14 | 15 | namespace boost 16 | { 17 | namespace statechart 18 | { 19 | 20 | 21 | 22 | ////////////////////////////////////////////////////////////////////////////// 23 | class null_exception_translator 24 | { 25 | public: 26 | ////////////////////////////////////////////////////////////////////////// 27 | // The following declarations should be private. 28 | // They are only public because many compilers lack template friends. 29 | ////////////////////////////////////////////////////////////////////////// 30 | template< class Action, class ExceptionEventHandler > 31 | result operator()( Action action, ExceptionEventHandler ) 32 | { 33 | return action(); 34 | } 35 | }; 36 | 37 | 38 | 39 | } // namespace statechart 40 | } // namespace boost 41 | 42 | 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /include/boost/statechart/result.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_RESULT_HPP_INCLUDED 2 | #define BOOST_STATECHART_RESULT_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2002-2010 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | 13 | 14 | 15 | namespace boost 16 | { 17 | namespace statechart 18 | { 19 | namespace detail 20 | { 21 | 22 | 23 | 24 | ////////////////////////////////////////////////////////////////////////////// 25 | enum reaction_result 26 | { 27 | no_reaction, 28 | do_forward_event, 29 | do_discard_event, 30 | do_defer_event, 31 | consumed 32 | }; 33 | 34 | struct result_utility; 35 | 36 | ////////////////////////////////////////////////////////////////////////////// 37 | class safe_reaction_result 38 | { 39 | public: 40 | ////////////////////////////////////////////////////////////////////////// 41 | safe_reaction_result( const safe_reaction_result & other ) : 42 | reactionResult_( other.reactionResult_ ) 43 | { 44 | // This assert fails when an attempt is made to make multiple copies of 45 | // a result value. This makes little sense, given the requirement that 46 | // an obtained result value must be returned out of the react function. 47 | BOOST_ASSERT( reactionResult_ != consumed ); 48 | other.reactionResult_ = consumed; 49 | } 50 | 51 | ~safe_reaction_result() 52 | { 53 | // This assert fails when an obtained result value is not returned out 54 | // of the react() function. This can happen if the user accidentally 55 | // makes more than one call to reaction functions inside react() or 56 | // accidentally makes one or more calls to reaction functions outside 57 | // react() 58 | BOOST_ASSERT( reactionResult_ == consumed ); 59 | } 60 | 61 | private: 62 | ////////////////////////////////////////////////////////////////////////// 63 | safe_reaction_result( reaction_result reactionResult ) : 64 | reactionResult_( reactionResult ) 65 | { 66 | } 67 | 68 | operator reaction_result() const 69 | { 70 | const reaction_result val = reactionResult_; 71 | reactionResult_ = consumed; 72 | return val; 73 | } 74 | 75 | safe_reaction_result & operator=( const safe_reaction_result & ); 76 | 77 | mutable reaction_result reactionResult_; 78 | 79 | friend struct result_utility; 80 | }; 81 | 82 | 83 | 84 | } // namespace detail 85 | 86 | 87 | 88 | #ifdef NDEBUG 89 | typedef detail::reaction_result result; 90 | #else 91 | typedef detail::safe_reaction_result result; 92 | #endif 93 | 94 | 95 | namespace detail 96 | { 97 | 98 | 99 | 100 | ////////////////////////////////////////////////////////////////////////////// 101 | struct result_utility 102 | { 103 | static ::boost::statechart::result make_result( reaction_result value ) 104 | { 105 | return value; 106 | } 107 | 108 | static reaction_result get_result( ::boost::statechart::result value ) 109 | { 110 | return value; 111 | } 112 | }; 113 | 114 | 115 | 116 | } // namespace detail 117 | } // namespace statechart 118 | } // namespace boost 119 | 120 | 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /include/boost/statechart/shallow_history.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_SHALLOW_HISTORY_HPP_INCLUDED 2 | #define BOOST_STATECHART_SHALLOW_HISTORY_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2002-2006 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | #include 13 | 14 | 15 | 16 | namespace boost 17 | { 18 | namespace statechart 19 | { 20 | 21 | 22 | 23 | ////////////////////////////////////////////////////////////////////////////// 24 | template< class DefaultState > 25 | class shallow_history 26 | { 27 | public: 28 | ////////////////////////////////////////////////////////////////////////// 29 | // If you receive a 30 | // "use of undefined type 'boost::STATIC_ASSERTION_FAILURE'" or similar 31 | // compiler error here then you forgot to pass either 32 | // statechart::has_deep_history or statechart::has_full_history as the 33 | // last parameter of DefaultState's context. 34 | BOOST_STATIC_ASSERT( DefaultState::context_type::shallow_history::value ); 35 | 36 | ////////////////////////////////////////////////////////////////////////// 37 | // The following declarations should be private. 38 | // They are only public because many compilers lack template friends. 39 | ////////////////////////////////////////////////////////////////////////// 40 | typedef typename DefaultState::outermost_context_base_type 41 | outermost_context_base_type; 42 | typedef typename DefaultState::context_type context_type; 43 | typedef typename DefaultState::context_ptr_type context_ptr_type; 44 | typedef typename DefaultState::context_type_list context_type_list; 45 | typedef typename DefaultState::orthogonal_position orthogonal_position; 46 | 47 | static void deep_construct( 48 | const context_ptr_type & pContext, 49 | outermost_context_base_type & outermostContextBase ) 50 | { 51 | outermostContextBase.template construct_with_shallow_history< 52 | DefaultState >( pContext ); 53 | } 54 | }; 55 | 56 | 57 | 58 | } // namespace statechart 59 | } // namespace boost 60 | 61 | 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /include/boost/statechart/state.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_STATE_HPP_INCLUDED 2 | #define BOOST_STATECHART_STATE_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2002-2006 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | 13 | #include 14 | 15 | 16 | 17 | namespace boost 18 | { 19 | namespace statechart 20 | { 21 | 22 | 23 | 24 | template< class MostDerived, 25 | class Context, 26 | class InnerInitial = mpl::list<>, 27 | history_mode historyMode = has_no_history > 28 | class state : public simple_state< 29 | MostDerived, Context, InnerInitial, historyMode > 30 | { 31 | typedef simple_state< MostDerived, Context, InnerInitial, historyMode > 32 | base_type; 33 | 34 | protected: 35 | ////////////////////////////////////////////////////////////////////////// 36 | struct my_context 37 | { 38 | my_context( typename base_type::context_ptr_type pContext ) : 39 | pContext_( pContext ) 40 | { 41 | } 42 | 43 | typename base_type::context_ptr_type pContext_; 44 | }; 45 | 46 | typedef state my_base; 47 | 48 | state( my_context ctx ) 49 | { 50 | this->set_context( ctx.pContext_ ); 51 | } 52 | 53 | ~state() {} 54 | 55 | public: 56 | ////////////////////////////////////////////////////////////////////////// 57 | // The following declarations should be private. 58 | // They are only public because many compilers lack template friends. 59 | ////////////////////////////////////////////////////////////////////////// 60 | // See base class for documentation 61 | typedef typename base_type::outermost_context_base_type 62 | outermost_context_base_type; 63 | typedef typename base_type::inner_context_ptr_type inner_context_ptr_type; 64 | typedef typename base_type::context_ptr_type context_ptr_type; 65 | typedef typename base_type::inner_initial_list inner_initial_list; 66 | 67 | static void initial_deep_construct( 68 | outermost_context_base_type & outermostContextBase ) 69 | { 70 | deep_construct( &outermostContextBase, outermostContextBase ); 71 | } 72 | 73 | // See base class for documentation 74 | static void deep_construct( 75 | const context_ptr_type & pContext, 76 | outermost_context_base_type & outermostContextBase ) 77 | { 78 | const inner_context_ptr_type pInnerContext( 79 | shallow_construct( pContext, outermostContextBase ) ); 80 | base_type::template deep_construct_inner< inner_initial_list >( 81 | pInnerContext, outermostContextBase ); 82 | } 83 | 84 | static inner_context_ptr_type shallow_construct( 85 | const context_ptr_type & pContext, 86 | outermost_context_base_type & outermostContextBase ) 87 | { 88 | const inner_context_ptr_type pInnerContext( 89 | new MostDerived( my_context( pContext ) ) ); 90 | outermostContextBase.add( pInnerContext ); 91 | return pInnerContext; 92 | } 93 | }; 94 | 95 | 96 | 97 | } // namespace statechart 98 | } // namespace boost 99 | 100 | 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /include/boost/statechart/termination.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_TERMINATION_HPP_INCLUDED 2 | #define BOOST_STATECHART_TERMINATION_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2002-2006 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | 13 | 14 | 15 | namespace boost 16 | { 17 | namespace statechart 18 | { 19 | 20 | 21 | 22 | class event_base; 23 | 24 | ////////////////////////////////////////////////////////////////////////////// 25 | template< class Event > 26 | class termination 27 | { 28 | public: 29 | ////////////////////////////////////////////////////////////////////////// 30 | // The following declarations should be private. 31 | // They are only public because many compilers lack template friends. 32 | ////////////////////////////////////////////////////////////////////////// 33 | template< class State, class EventBase, class IdType > 34 | static detail::reaction_result react( 35 | State & stt, const EventBase &, const IdType & eventType ) 36 | { 37 | if ( eventType == Event::static_type() ) 38 | { 39 | return detail::result_utility::get_result( stt.terminate() ); 40 | } 41 | else 42 | { 43 | return detail::no_reaction; 44 | } 45 | } 46 | }; 47 | 48 | template<> 49 | class termination< event_base > 50 | { 51 | public: 52 | ////////////////////////////////////////////////////////////////////////// 53 | // The following declarations should be private. 54 | // They are only public because many compilers lack template friends. 55 | ////////////////////////////////////////////////////////////////////////// 56 | template< class State, class EventBase, class IdType > 57 | static detail::reaction_result react( 58 | State & stt, const EventBase &, const IdType & ) 59 | { 60 | return detail::result_utility::get_result( stt.terminate() ); 61 | } 62 | }; 63 | 64 | 65 | 66 | } // namespace statechart 67 | } // namespace boost 68 | 69 | 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /include/boost/statechart/transition.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_TRANSITION_HPP_INCLUDED 2 | #define BOOST_STATECHART_TRANSITION_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2002-2008 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | 13 | #include 14 | 15 | 16 | 17 | namespace boost 18 | { 19 | namespace statechart 20 | { 21 | 22 | 23 | 24 | ////////////////////////////////////////////////////////////////////////////// 25 | template< class Event, class Destination, 26 | class TransitionContext = detail::no_context< Event >, 27 | void ( TransitionContext::*pTransitionAction )( const Event & ) = 28 | &detail::no_context< Event >::no_function > 29 | class transition 30 | { 31 | private: 32 | ////////////////////////////////////////////////////////////////////////// 33 | template< class State > 34 | struct reactions 35 | { 36 | static result react_without_action( State & stt ) 37 | { 38 | return stt.template transit< Destination >(); 39 | } 40 | 41 | static result react_with_action( State & stt, const Event & evt ) 42 | { 43 | return stt.template transit< Destination >( pTransitionAction, evt ); 44 | } 45 | }; 46 | 47 | public: 48 | ////////////////////////////////////////////////////////////////////////// 49 | // The following declarations should be private. 50 | // They are only public because many compilers lack template friends. 51 | ////////////////////////////////////////////////////////////////////////// 52 | template< class State, class EventBase, class IdType > 53 | static detail::reaction_result react( 54 | State & stt, const EventBase & evt, const IdType & eventType ) 55 | { 56 | typedef detail::reaction_dispatcher< 57 | reactions< State >, State, EventBase, Event, TransitionContext, IdType 58 | > dispatcher; 59 | return dispatcher::react( stt, evt, eventType ); 60 | } 61 | }; 62 | 63 | 64 | 65 | } // namespace statechart 66 | } // namespace boost 67 | 68 | 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

Automatic redirection failed, please go to doc/index.html.

15 |
16 | 17 |

Valid HTML 4.01 Transitional

20 | 21 |

Revised 22 | 18 July, 2006

23 | 24 |

Copyright © 2003-2006 Andreas Huber Dönni 25 |

26 | 27 |

Distributed under the Boost Software License, Version 1.0. (See 28 | accompanying file LICENSE_1_0.txt or 29 | copy at http://www.boost.org/LICENSE_1_0.txt)

31 | 32 | 33 | -------------------------------------------------------------------------------- /meta/libraries.json: -------------------------------------------------------------------------------- 1 | { 2 | "key": "statechart", 3 | "name": "Statechart", 4 | "authors": [ 5 | "Andreas Huber Dönni" 6 | ], 7 | "description": "Boost.Statechart - Arbitrarily complex finite state machines can be implemented in easily readable and maintainable C++ code.", 8 | "category": [ 9 | "State" 10 | ], 11 | "maintainers": [ 12 | "Andreas Huber " 13 | ], 14 | "cxxstd": "03" 15 | } 16 | -------------------------------------------------------------------------------- /test/DeferralBug.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2010 Igor R (http://thread.gmane.org/gmane.comp.lib.boost.user/62985) 3 | // Copyright 2010 Andreas Huber Doenni 4 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 5 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 | ////////////////////////////////////////////////////////////////////////////// 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | #include 17 | 18 | 19 | 20 | namespace sc = boost::statechart; 21 | namespace mpl = boost::mpl; 22 | 23 | 24 | 25 | struct ev1to2 : sc::event< ev1to2 > {}; 26 | struct ev2to3 : sc::event< ev2to3 > {}; 27 | struct ev3to4_1 : sc::event< ev3to4_1 > {}; 28 | struct ev3to4_2 : sc::event< ev3to4_2 > {}; 29 | 30 | struct s1; 31 | struct fsm : sc::state_machine< fsm, s1 > {}; 32 | 33 | struct s2; 34 | struct s1 : sc::simple_state< s1, fsm > 35 | { 36 | typedef mpl::list< 37 | sc::transition< ev1to2, s2 >, 38 | sc::deferral< ev2to3 >, 39 | sc::deferral< ev3to4_1 >, 40 | sc::deferral< ev3to4_2 > 41 | > reactions; 42 | }; 43 | 44 | struct s3; 45 | struct s2 : sc::simple_state< s2, fsm > 46 | { 47 | typedef mpl::list< 48 | sc::transition< ev2to3, s3 >, 49 | sc::deferral< ev3to4_1 >, 50 | sc::deferral< ev3to4_2 > 51 | > reactions; 52 | }; 53 | 54 | struct s4_1; 55 | struct s4_2; 56 | struct s3 : sc::simple_state< s3, fsm > 57 | { 58 | typedef mpl::list< 59 | sc::transition< ev3to4_1, s4_1 >, 60 | sc::transition< ev3to4_2, s4_2 > 61 | > reactions; 62 | }; 63 | 64 | struct s4_1 : sc::simple_state< s4_1, fsm > {}; 65 | struct s4_2 : sc::simple_state< s4_2, fsm > {}; 66 | 67 | int test_main( int, char* [] ) 68 | { 69 | fsm machine; 70 | machine.initiate(); 71 | machine.process_event( ev3to4_1() ); 72 | machine.process_event( ev2to3() ); 73 | machine.process_event( ev3to4_2() ); 74 | machine.process_event( ev1to2() ); 75 | BOOST_REQUIRE( machine.state_cast< const s4_1 * >() != 0 ); 76 | machine.initiate(); 77 | machine.process_event( ev3to4_1() ); 78 | machine.process_event( ev3to4_2() ); 79 | machine.process_event( ev1to2() ); 80 | machine.process_event( ev2to3() ); 81 | BOOST_REQUIRE( machine.state_cast< const s4_1 * >() != 0 ); 82 | 83 | return 0; 84 | } 85 | -------------------------------------------------------------------------------- /test/InStateReactionTest.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2005-2008 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #include 18 | 19 | namespace sc = boost::statechart; 20 | namespace mpl = boost::mpl; 21 | 22 | 23 | struct E : sc::event< E > {}; 24 | struct F : sc::event< F > {}; 25 | struct G : sc::event< G > {}; 26 | struct H : sc::event< H > {}; 27 | struct I : sc::event< I > {}; 28 | 29 | struct A; 30 | struct InStateReactionTest : sc::state_machine< InStateReactionTest, A > {}; 31 | 32 | struct B; 33 | struct A : sc::simple_state< A, InStateReactionTest, B > 34 | { 35 | A() : eventCount_( 0 ) {} 36 | 37 | // The following 3 functions could be implemented with one function 38 | // template, but this causes problems with CW and Intel 9.1. 39 | void IncrementCount( const sc::event_base & ) { ++eventCount_; } 40 | void IncrementCount( const E & ) { ++eventCount_; } 41 | void IncrementCount( const G & ) { ++eventCount_; } 42 | 43 | typedef mpl::list< 44 | sc::in_state_reaction< E, A, &A::IncrementCount >, 45 | sc::in_state_reaction< sc::event_base, A, &A::IncrementCount > 46 | > reactions; 47 | 48 | unsigned int eventCount_; 49 | }; 50 | 51 | struct B : sc::simple_state< B, A > 52 | { 53 | B() : eventCount_( 0 ) {} 54 | 55 | void IncrementCount( const F & ) 56 | { 57 | ++eventCount_; 58 | } 59 | 60 | typedef mpl::list< 61 | sc::in_state_reaction< F, B, &B::IncrementCount >, 62 | sc::in_state_reaction< G, A, &A::IncrementCount >, 63 | sc::in_state_reaction< I > 64 | > reactions; 65 | 66 | unsigned int eventCount_; 67 | }; 68 | 69 | 70 | 71 | void RequireEventCounts( 72 | const InStateReactionTest & machine, 73 | unsigned int aCount, unsigned int bCount) 74 | { 75 | BOOST_REQUIRE( 76 | machine.state_downcast< const A & >().eventCount_ == aCount ); 77 | BOOST_REQUIRE( 78 | machine.state_downcast< const B & >().eventCount_ == bCount ); 79 | } 80 | 81 | int test_main( int, char* [] ) 82 | { 83 | InStateReactionTest machine; 84 | machine.initiate(); 85 | 86 | RequireEventCounts(machine, 0, 0); 87 | machine.process_event( F() ); 88 | RequireEventCounts(machine, 0, 1); 89 | machine.process_event( E() ); 90 | RequireEventCounts(machine, 1, 1); 91 | machine.process_event( E() ); 92 | machine.process_event( F() ); 93 | RequireEventCounts(machine, 2, 2); 94 | machine.process_event( G() ); 95 | RequireEventCounts(machine, 3, 2); 96 | machine.process_event( H() ); 97 | RequireEventCounts(machine, 4, 2); 98 | machine.process_event( I() ); 99 | RequireEventCounts(machine, 4, 2); 100 | 101 | return 0; 102 | } 103 | -------------------------------------------------------------------------------- /test/InconsistentHistoryTest1.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2005-2006 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | 16 | 17 | namespace sc = boost::statechart; 18 | namespace mpl = boost::mpl; 19 | 20 | 21 | 22 | struct A; 23 | struct InconsistentHistoryTest : sc::state_machine< 24 | InconsistentHistoryTest, A > {}; 25 | 26 | struct B; 27 | // A does not have history 28 | struct A : sc::simple_state< A, InconsistentHistoryTest, 29 | mpl::list< sc::shallow_history< B > > > {}; 30 | 31 | struct B : sc::simple_state< B, A > {}; 32 | 33 | 34 | int main() 35 | { 36 | InconsistentHistoryTest machine; 37 | machine.initiate(); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /test/InconsistentHistoryTest1.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 27 | 30 | 33 | 36 | 39 | 42 | 60 | 63 | 66 | 69 | 81 | 84 | 87 | 90 | 93 | 96 | 99 | 102 | 103 | 111 | 114 | 117 | 120 | 123 | 126 | 141 | 144 | 147 | 150 | 163 | 166 | 169 | 172 | 175 | 178 | 181 | 184 | 185 | 186 | 187 | 188 | 189 | 194 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | -------------------------------------------------------------------------------- /test/InconsistentHistoryTest2.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2005-2006 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | 17 | namespace sc = boost::statechart; 18 | 19 | 20 | 21 | struct EvX : sc::event< EvX > {}; 22 | 23 | struct A; 24 | struct InconsistentHistoryTest : sc::state_machine< 25 | InconsistentHistoryTest, A > {}; 26 | 27 | struct B; 28 | // A only has deep history 29 | struct A : sc::simple_state< 30 | A, InconsistentHistoryTest, B, sc::has_deep_history > 31 | { 32 | typedef sc::transition< EvX, sc::shallow_history< B > > reactions; 33 | }; 34 | 35 | struct B : sc::simple_state< B, A > {}; 36 | 37 | 38 | int main() 39 | { 40 | InconsistentHistoryTest machine; 41 | machine.initiate(); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /test/InconsistentHistoryTest2.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 27 | 30 | 33 | 36 | 39 | 42 | 60 | 63 | 66 | 69 | 81 | 84 | 87 | 90 | 93 | 96 | 99 | 102 | 103 | 111 | 114 | 117 | 120 | 123 | 126 | 141 | 144 | 147 | 150 | 163 | 166 | 169 | 172 | 175 | 178 | 181 | 184 | 185 | 186 | 187 | 188 | 189 | 194 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | -------------------------------------------------------------------------------- /test/InconsistentHistoryTest3.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2005-2006 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | 16 | 17 | namespace sc = boost::statechart; 18 | namespace mpl = boost::mpl; 19 | 20 | 21 | 22 | struct A; 23 | struct InconsistentHistoryTest : sc::state_machine< 24 | InconsistentHistoryTest, A > {}; 25 | 26 | struct B; 27 | // A does not have history 28 | struct A : sc::simple_state< 29 | A, InconsistentHistoryTest, mpl::list< sc::deep_history< B > > > {}; 30 | 31 | struct B : sc::simple_state< B, A > {}; 32 | 33 | 34 | int main() 35 | { 36 | InconsistentHistoryTest machine; 37 | machine.initiate(); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /test/InconsistentHistoryTest3.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 27 | 30 | 33 | 36 | 39 | 42 | 60 | 63 | 66 | 69 | 81 | 84 | 87 | 90 | 93 | 96 | 99 | 102 | 103 | 111 | 114 | 117 | 120 | 123 | 126 | 141 | 144 | 147 | 150 | 163 | 166 | 169 | 172 | 175 | 178 | 181 | 184 | 185 | 186 | 187 | 188 | 189 | 194 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | -------------------------------------------------------------------------------- /test/InconsistentHistoryTest4.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2005-2006 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | 17 | namespace sc = boost::statechart; 18 | 19 | 20 | 21 | struct EvX : sc::event< EvX > {}; 22 | 23 | struct A; 24 | struct InconsistentHistoryTest : sc::state_machine< 25 | InconsistentHistoryTest, A > {}; 26 | 27 | struct B; 28 | // A only has shallow history 29 | struct A : sc::simple_state< 30 | A, InconsistentHistoryTest, B, sc::has_shallow_history > 31 | { 32 | typedef sc::transition< EvX, sc::deep_history< B > > reactions; 33 | }; 34 | 35 | struct B : sc::simple_state< B, A > {}; 36 | 37 | 38 | int main() 39 | { 40 | InconsistentHistoryTest machine; 41 | machine.initiate(); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /test/InconsistentHistoryTest5.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2005-2006 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include 10 | #include 11 | 12 | 13 | 14 | namespace sc = boost::statechart; 15 | namespace mpl = boost::mpl; 16 | 17 | 18 | 19 | struct A; 20 | struct InconsistentHistoryTest : sc::state_machine< 21 | InconsistentHistoryTest, A > {}; 22 | 23 | struct B; 24 | struct A : sc::simple_state< A, InconsistentHistoryTest, B > {}; 25 | 26 | struct B : sc::simple_state< B, A > {}; 27 | 28 | 29 | int main() 30 | { 31 | InconsistentHistoryTest machine; 32 | machine.initiate(); 33 | // A does not have history 34 | machine.clear_shallow_history< A, 0 >(); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /test/InconsistentHistoryTest6.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2005-2006 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | 16 | namespace sc = boost::statechart; 17 | 18 | 19 | 20 | struct EvX : sc::event< EvX > {}; 21 | 22 | struct A; 23 | struct InconsistentHistoryTest : sc::state_machine< 24 | InconsistentHistoryTest, A > {}; 25 | 26 | struct B; 27 | // A only has deep history 28 | struct A : sc::simple_state< 29 | A, InconsistentHistoryTest, B, sc::has_deep_history > 30 | { 31 | typedef sc::custom_reaction< EvX > reactions; 32 | 33 | sc::result react( const EvX & ) 34 | { 35 | // A only has deep history 36 | clear_shallow_history< A, 0 >(); 37 | return discard_event(); 38 | } 39 | }; 40 | 41 | struct B : sc::simple_state< B, A > {}; 42 | 43 | 44 | int main() 45 | { 46 | InconsistentHistoryTest machine; 47 | machine.initiate(); 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /test/InconsistentHistoryTest7.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2005-2006 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include 10 | #include 11 | 12 | 13 | 14 | namespace sc = boost::statechart; 15 | namespace mpl = boost::mpl; 16 | 17 | 18 | 19 | struct A; 20 | struct InconsistentHistoryTest : sc::state_machine< 21 | InconsistentHistoryTest, A > {}; 22 | 23 | struct B; 24 | struct A : sc::simple_state< A, InconsistentHistoryTest, B > {}; 25 | 26 | struct B : sc::simple_state< B, A > {}; 27 | 28 | 29 | int main() 30 | { 31 | InconsistentHistoryTest machine; 32 | machine.initiate(); 33 | // A does not have history 34 | machine.clear_deep_history< A, 0 >(); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /test/InconsistentHistoryTest8.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2005-2006 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | 16 | namespace sc = boost::statechart; 17 | 18 | 19 | 20 | struct EvX : sc::event< EvX > {}; 21 | 22 | struct A; 23 | struct InconsistentHistoryTest : sc::state_machine< 24 | InconsistentHistoryTest, A > {}; 25 | 26 | struct B; 27 | // A only has deep history 28 | struct A : sc::simple_state< 29 | A, InconsistentHistoryTest, B, sc::has_shallow_history > 30 | { 31 | typedef sc::custom_reaction< EvX > reactions; 32 | 33 | sc::result react( const EvX & ) 34 | { 35 | // A only has shallow history 36 | clear_deep_history< A, 0 >(); 37 | return discard_event(); 38 | } 39 | }; 40 | 41 | struct B : sc::simple_state< B, A > {}; 42 | 43 | 44 | int main() 45 | { 46 | InconsistentHistoryTest machine; 47 | machine.initiate(); 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /test/InnermostDefault.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_TEST_INNERMOST_DEFAULT_HPP_INCLUDED 2 | #define BOOST_STATECHART_TEST_INNERMOST_DEFAULT_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2004-2006 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | 13 | 14 | 15 | namespace sc = boost::statechart; 16 | 17 | 18 | 19 | ////////////////////////////////////////////////////////////////////////////// 20 | template< class MostDerived, class Context > 21 | struct InnermostDefault : sc::state< MostDerived, Context > 22 | { 23 | typedef sc::state< MostDerived, Context > base_type; 24 | typedef typename base_type::my_context my_context; 25 | typedef InnermostDefault my_base; 26 | 27 | InnermostDefault( my_context ctx ) : base_type( ctx ) 28 | { 29 | this->outermost_context().template ActualEntry< MostDerived >(); 30 | } 31 | 32 | ~InnermostDefault() 33 | { 34 | this->outermost_context().template ActualDestructor< MostDerived >(); 35 | } 36 | 37 | void exit() 38 | { 39 | this->outermost_context().template ActualExitFunction< MostDerived >(); 40 | } 41 | }; 42 | 43 | ////////////////////////////////////////////////////////////////////////////// 44 | template< class Context > 45 | struct Default0 : InnermostDefault< 46 | Default0< Context >, typename Context::template orthogonal< 0 > > 47 | { 48 | typedef InnermostDefault< 49 | Default0, typename Context::template orthogonal< 0 > > base_type; 50 | typedef typename base_type::my_context my_context; 51 | 52 | Default0( my_context ctx ) : base_type( ctx ) {} 53 | }; 54 | 55 | ////////////////////////////////////////////////////////////////////////////// 56 | template< class Context > 57 | struct Default1 : InnermostDefault< 58 | Default1< Context >, typename Context::template orthogonal< 1 > > 59 | { 60 | typedef InnermostDefault< 61 | Default1, typename Context::template orthogonal< 1 > > base_type; 62 | typedef typename base_type::my_context my_context; 63 | 64 | Default1( my_context ctx ) : base_type( ctx ) {} 65 | }; 66 | 67 | ////////////////////////////////////////////////////////////////////////////// 68 | template< class Context > 69 | struct Default2 : InnermostDefault< 70 | Default2< Context >, typename Context::template orthogonal< 2 > > 71 | { 72 | typedef InnermostDefault< 73 | Default2, typename Context::template orthogonal< 2 > > base_type; 74 | typedef typename base_type::my_context my_context; 75 | 76 | Default2( my_context ctx ) : base_type( ctx ) {} 77 | }; 78 | 79 | 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /test/InvalidChartTest1.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2005-2006 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include 10 | #include 11 | 12 | 13 | 14 | namespace sc = boost::statechart; 15 | 16 | 17 | 18 | struct A; 19 | struct InvalidChartTest : sc::state_machine< InvalidChartTest, A > {}; 20 | 21 | struct A : sc::simple_state< A, InvalidChartTest > {}; 22 | 23 | // A does not have inner states 24 | struct B : sc::simple_state< B, A > {}; 25 | 26 | 27 | int main() 28 | { 29 | InvalidChartTest machine; 30 | machine.initiate(); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /test/InvalidChartTest1.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 27 | 30 | 33 | 36 | 39 | 42 | 60 | 63 | 66 | 69 | 81 | 84 | 87 | 90 | 93 | 96 | 99 | 102 | 103 | 111 | 114 | 117 | 120 | 123 | 126 | 141 | 144 | 147 | 150 | 163 | 166 | 169 | 172 | 175 | 178 | 181 | 184 | 185 | 186 | 187 | 188 | 189 | 194 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | -------------------------------------------------------------------------------- /test/InvalidChartTest2.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2005-2006 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include 10 | #include 11 | 12 | 13 | 14 | namespace sc = boost::statechart; 15 | 16 | 17 | 18 | struct A; 19 | struct InvalidChartTest : sc::state_machine< InvalidChartTest, A > {}; 20 | 21 | struct B; 22 | struct A : sc::simple_state< A, InvalidChartTest, B > {}; 23 | 24 | struct B : sc::simple_state< B, A > {}; 25 | 26 | // A does not have an orthogonal region with the number 1 27 | struct C : sc::simple_state< C, A::orthogonal< 1 > > {}; 28 | 29 | 30 | int main() 31 | { 32 | InvalidChartTest machine; 33 | machine.initiate(); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /test/InvalidChartTest2.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 27 | 30 | 33 | 36 | 39 | 42 | 60 | 63 | 66 | 69 | 81 | 84 | 87 | 90 | 93 | 96 | 99 | 102 | 103 | 111 | 114 | 117 | 120 | 123 | 126 | 141 | 144 | 147 | 150 | 163 | 166 | 169 | 172 | 175 | 178 | 181 | 184 | 185 | 186 | 187 | 188 | 189 | 194 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | -------------------------------------------------------------------------------- /test/InvalidChartTest3.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2005-2006 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | 15 | 16 | namespace sc = boost::statechart; 17 | namespace mpl = boost::mpl; 18 | 19 | 20 | 21 | struct A; 22 | struct InvalidChartTest : sc::state_machine< InvalidChartTest, A > {}; 23 | struct B; 24 | struct C; 25 | struct A : sc::simple_state< A, InvalidChartTest, mpl::list< B, C > > {}; 26 | 27 | // B resides in the 0th region not the 1st 28 | struct B : sc::simple_state< B, A::orthogonal< 1 > > {}; 29 | struct C : sc::simple_state< C, A::orthogonal< 1 > > {}; 30 | 31 | int main() 32 | { 33 | InvalidChartTest machine; 34 | machine.initiate(); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /test/InvalidChartTest3.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 27 | 30 | 33 | 36 | 39 | 42 | 60 | 63 | 66 | 69 | 81 | 84 | 87 | 90 | 93 | 96 | 99 | 102 | 103 | 111 | 114 | 117 | 120 | 123 | 126 | 141 | 144 | 147 | 150 | 163 | 166 | 169 | 172 | 175 | 178 | 181 | 184 | 185 | 186 | 187 | 188 | 189 | 194 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | -------------------------------------------------------------------------------- /test/InvalidResultAssignTest.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2005-2006 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | 18 | 19 | namespace sc = boost::statechart; 20 | 21 | 22 | 23 | struct E : sc::event< E > {}; 24 | 25 | struct A; 26 | struct InvalidResultAssignTest : 27 | sc::state_machine< InvalidResultAssignTest, A > {}; 28 | 29 | struct A : sc::simple_state< A, InvalidResultAssignTest > 30 | { 31 | typedef sc::custom_reaction< E > reactions; 32 | 33 | sc::result react( const E & ) 34 | { 35 | sc::result r( discard_event() ); 36 | // sc::result must not be assignmable 37 | r = discard_event(); 38 | return r; 39 | } 40 | }; 41 | 42 | 43 | 44 | int main() 45 | { 46 | InvalidResultAssignTest machine; 47 | machine.initiate(); 48 | 49 | #ifdef NDEBUG 50 | // Test only fails in DEBUG mode. Forcing failure... 51 | BOOST_STATIC_ASSERT( false ); 52 | #endif 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /test/InvalidResultAssignTest.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 27 | 30 | 33 | 36 | 39 | 42 | 60 | 63 | 66 | 69 | 81 | 84 | 87 | 90 | 93 | 96 | 99 | 102 | 103 | 111 | 114 | 117 | 120 | 123 | 126 | 141 | 144 | 147 | 150 | 163 | 166 | 169 | 172 | 175 | 178 | 181 | 184 | 185 | 186 | 187 | 188 | 189 | 194 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | -------------------------------------------------------------------------------- /test/InvalidResultCopyTest.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2005-2006 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include "ThrowingBoostAssert.hpp" 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | 18 | #include // std::logic_error 19 | 20 | namespace sc = boost::statechart; 21 | 22 | 23 | 24 | struct E : sc::event< E > {}; 25 | 26 | struct A; 27 | struct InvalidResultCopyTest : 28 | sc::state_machine< InvalidResultCopyTest, A > {}; 29 | 30 | struct A : sc::simple_state< A, InvalidResultCopyTest > 31 | { 32 | typedef sc::custom_reaction< E > reactions; 33 | 34 | sc::result react( const E & ) 35 | { 36 | sc::result r( discard_event() ); 37 | sc::result rCopy1( r ); 38 | // Ensure the copy is consumed so that we're not accidentally tripping 39 | // the assert in the sc::result dtor 40 | sc::detail::result_utility::get_result( rCopy1 ); 41 | 42 | // We must not make more than one copy of a result value 43 | sc::result rCopy2( r ); 44 | return rCopy2; 45 | } 46 | }; 47 | 48 | 49 | 50 | int test_main( int, char* [] ) 51 | { 52 | InvalidResultCopyTest machine; 53 | machine.initiate(); 54 | 55 | #ifdef NDEBUG 56 | BOOST_REQUIRE_NO_THROW( machine.process_event( E() ) ); 57 | #else 58 | BOOST_REQUIRE_THROW( machine.process_event( E() ), std::logic_error ); 59 | #endif 60 | 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /test/InvalidResultDefCtorTest.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2005-2006 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include 10 | 11 | #include 12 | 13 | 14 | 15 | namespace sc = boost::statechart; 16 | 17 | 18 | 19 | int main() 20 | { 21 | // sc::result has no default ctor 22 | sc::result r; 23 | 24 | #ifdef NDEBUG 25 | // Test only fails in DEBUG mode. Forcing failure... 26 | BOOST_STATIC_ASSERT( false ); 27 | #endif 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /test/InvalidTransitionTest1.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2004-2006 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | 17 | 18 | namespace sc = boost::statechart; 19 | namespace mpl = boost::mpl; 20 | 21 | 22 | 23 | struct EvX : sc::event< EvX > {}; 24 | 25 | struct Active; 26 | struct InvalidTransitionTest : sc::state_machine< 27 | InvalidTransitionTest, Active > {}; 28 | 29 | struct Idle0; 30 | struct Idle1; 31 | struct Active : sc::simple_state< 32 | Active, InvalidTransitionTest, mpl::list< Idle0, Idle1 > > {}; 33 | 34 | // Invalid transition between different orthogonal regions. 35 | struct Idle0 : sc::simple_state< Idle0, Active::orthogonal< 0 > > 36 | { 37 | typedef sc::transition< EvX, Idle1 > reactions; 38 | }; 39 | 40 | struct Idle1 : sc::simple_state< Idle1, Active::orthogonal< 1 > > {}; 41 | 42 | 43 | int main() 44 | { 45 | InvalidTransitionTest machine; 46 | machine.initiate(); 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /test/InvalidTransitionTest1.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 27 | 30 | 33 | 36 | 39 | 42 | 60 | 63 | 66 | 69 | 81 | 84 | 87 | 90 | 93 | 96 | 99 | 102 | 103 | 111 | 114 | 117 | 120 | 123 | 126 | 141 | 144 | 147 | 150 | 163 | 166 | 169 | 172 | 175 | 178 | 181 | 184 | 185 | 186 | 187 | 188 | 189 | 194 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | -------------------------------------------------------------------------------- /test/InvalidTransitionTest2.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2004-2006 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | 17 | 18 | namespace sc = boost::statechart; 19 | namespace mpl = boost::mpl; 20 | 21 | 22 | 23 | struct EvX : sc::event< EvX > {}; 24 | 25 | struct Active; 26 | struct InvalidTransitionTest : sc::state_machine< 27 | InvalidTransitionTest, Active > {}; 28 | 29 | struct Idle0; 30 | struct Idle1; 31 | struct Active : sc::simple_state< 32 | Active, InvalidTransitionTest, mpl::list< Idle0, Idle1 > > {}; 33 | 34 | struct Idle00; 35 | struct Idle0 : sc::simple_state< 36 | Idle0, Active::orthogonal< 0 >, Idle00 > {}; 37 | 38 | struct Idle00 : sc::simple_state< Idle00, Idle0 > {}; 39 | 40 | struct Idle10; 41 | struct Idle1 : sc::simple_state< 42 | Idle1, Active::orthogonal< 1 >, Idle10 > {}; 43 | 44 | // Invalid transition between different orthogonal regions. 45 | struct Idle10 : sc::simple_state< Idle10, Idle1 > 46 | { 47 | typedef sc::transition< EvX, Idle00 > reactions; 48 | }; 49 | 50 | 51 | int main() 52 | { 53 | InvalidTransitionTest machine; 54 | machine.initiate(); 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /test/InvalidTransitionTest2.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 27 | 30 | 33 | 36 | 39 | 42 | 60 | 63 | 66 | 69 | 81 | 84 | 87 | 90 | 93 | 96 | 99 | 102 | 103 | 111 | 114 | 117 | 120 | 123 | 126 | 141 | 144 | 147 | 150 | 163 | 166 | 169 | 172 | 175 | 178 | 181 | 184 | 185 | 186 | 187 | 188 | 189 | 194 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | -------------------------------------------------------------------------------- /test/OuterOrthogonal.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_TEST_OUTER_ORTHOGONAL_HPP_INCLUDED 2 | #define BOOST_STATECHART_TEST_OUTER_ORTHOGONAL_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2004-2006 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | #include 13 | 14 | #include "InnermostDefault.hpp" 15 | 16 | 17 | 18 | namespace sc = boost::statechart; 19 | namespace mpl = boost::mpl; 20 | 21 | 22 | 23 | ////////////////////////////////////////////////////////////////////////////// 24 | template< class MostDerived, class Context, class InitialState0 > 25 | struct Orthogonal0 : sc::state< MostDerived, Context, 26 | mpl::list< 27 | InitialState0, 28 | Default1< MostDerived >, 29 | Default2< MostDerived > > > 30 | { 31 | typedef sc::state< 32 | MostDerived, Context, mpl::list< InitialState0, 33 | Default1< MostDerived >, Default2< MostDerived > > > base_type; 34 | typedef typename base_type::my_context my_context; 35 | typedef Orthogonal0 my_base; 36 | 37 | Orthogonal0( my_context ctx ) : base_type( ctx ) 38 | { 39 | this->outermost_context().template ActualEntry< MostDerived >(); 40 | } 41 | 42 | ~Orthogonal0() 43 | { 44 | this->outermost_context().template ActualDestructor< MostDerived >(); 45 | } 46 | 47 | void exit() 48 | { 49 | this->outermost_context().template ActualExitFunction< MostDerived >(); 50 | } 51 | }; 52 | 53 | ////////////////////////////////////////////////////////////////////////////// 54 | template< class MostDerived, class Context, class InitialState1 > 55 | struct Orthogonal1 : sc::state< MostDerived, Context, 56 | mpl::list< 57 | Default0< MostDerived >, 58 | InitialState1, 59 | Default2< MostDerived > > > 60 | { 61 | typedef sc::state< 62 | MostDerived, Context, mpl::list< Default0< MostDerived >, 63 | InitialState1, Default2< MostDerived > > > base_type; 64 | typedef typename base_type::my_context my_context; 65 | typedef Orthogonal1 my_base; 66 | 67 | Orthogonal1( my_context ctx ) : base_type( ctx ) 68 | { 69 | this->outermost_context().template ActualEntry< MostDerived >(); 70 | } 71 | 72 | ~Orthogonal1() 73 | { 74 | this->outermost_context().template ActualDestructor< MostDerived >(); 75 | } 76 | 77 | void exit() 78 | { 79 | this->outermost_context().template ActualExitFunction< MostDerived >(); 80 | } 81 | }; 82 | 83 | ////////////////////////////////////////////////////////////////////////////// 84 | template< class MostDerived, class Context, class InitialState2 > 85 | struct Orthogonal2 : sc::state< MostDerived, Context, 86 | mpl::list< 87 | Default0< MostDerived >, 88 | Default1< MostDerived >, 89 | InitialState2 > > 90 | { 91 | typedef sc::state< 92 | MostDerived, Context, mpl::list< Default0< MostDerived >, 93 | Default1< MostDerived >, InitialState2 > > base_type; 94 | typedef typename base_type::my_context my_context; 95 | typedef Orthogonal2 my_base; 96 | 97 | Orthogonal2( my_context ctx ) : base_type( ctx ) 98 | { 99 | this->outermost_context().template ActualEntry< MostDerived >(); 100 | } 101 | 102 | ~Orthogonal2() 103 | { 104 | this->outermost_context().template ActualDestructor< MostDerived >(); 105 | } 106 | 107 | void exit() 108 | { 109 | this->outermost_context().template ActualExitFunction< MostDerived >(); 110 | } 111 | }; 112 | 113 | 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /test/StateIterationTest.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2005-2006 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | 23 | 24 | namespace sc = boost::statechart; 25 | namespace mpl = boost::mpl; 26 | 27 | 28 | 29 | struct EvToA : sc::event< EvToA > {}; 30 | struct EvToB : sc::event< EvToB > {}; 31 | struct EvToD : sc::event< EvToD > {}; 32 | struct EvToE : sc::event< EvToE > {}; 33 | 34 | struct A; 35 | struct StateIterationTest : sc::state_machine< StateIterationTest, A > 36 | { 37 | public: 38 | ////////////////////////////////////////////////////////////////////////// 39 | StateIterationTest(); 40 | 41 | void AssertInState( const std::string & stateNames ) const 42 | { 43 | stateNamesCache_.clear(); 44 | 45 | for ( state_iterator currentState = state_begin(); 46 | currentState != state_end(); ++currentState ) 47 | { 48 | const StateNamesMap::const_iterator found = 49 | stateNamesMap_.find( currentState->dynamic_type() ); 50 | BOOST_REQUIRE( found != stateNamesMap_.end() ); 51 | stateNamesCache_.insert( found->second ); 52 | } 53 | 54 | std::string::const_iterator expectedName = stateNames.begin(); 55 | 56 | BOOST_REQUIRE( stateNames.size() == stateNamesCache_.size() ); 57 | 58 | for ( StateNamesCache::const_iterator actualName = 59 | stateNamesCache_.begin(); 60 | actualName != stateNamesCache_.end(); ++actualName, ++expectedName ) 61 | { 62 | BOOST_REQUIRE( ( *actualName )[ 0 ] == *expectedName ); 63 | } 64 | } 65 | 66 | private: 67 | ////////////////////////////////////////////////////////////////////////// 68 | typedef std::map< state_base_type::id_type, std::string > StateNamesMap; 69 | typedef std::set< std::string > StateNamesCache; 70 | 71 | StateNamesMap stateNamesMap_; 72 | mutable StateNamesCache stateNamesCache_; 73 | }; 74 | 75 | struct C; 76 | struct D; 77 | struct B : sc::simple_state< B, StateIterationTest, mpl::list< C, D > > 78 | { 79 | typedef sc::transition< EvToA, A > reactions; 80 | }; 81 | 82 | struct A : sc::simple_state< A, StateIterationTest > 83 | { 84 | typedef sc::transition< EvToB, B > reactions; 85 | }; 86 | 87 | struct F; 88 | struct G; 89 | struct E : sc::simple_state< E, B::orthogonal< 1 >, mpl::list< F, G > > 90 | { 91 | typedef sc::transition< EvToD, D > reactions; 92 | }; 93 | 94 | struct F : sc::simple_state< F, E::orthogonal< 0 > > {}; 95 | struct G : sc::simple_state< G, E::orthogonal< 1 > > {}; 96 | 97 | struct C : sc::simple_state< C, B::orthogonal< 0 > > {}; 98 | struct D : sc::simple_state< D, B::orthogonal< 1 > > 99 | { 100 | typedef sc::transition< EvToE, E > reactions; 101 | }; 102 | 103 | StateIterationTest::StateIterationTest() 104 | { 105 | // We're not using custom type information to make this test work even when 106 | // BOOST_STATECHART_USE_NATIVE_RTTI is defined 107 | stateNamesMap_[ A::static_type() ] = "A"; 108 | stateNamesMap_[ B::static_type() ] = "B"; 109 | stateNamesMap_[ C::static_type() ] = "C"; 110 | stateNamesMap_[ D::static_type() ] = "D"; 111 | stateNamesMap_[ E::static_type() ] = "E"; 112 | stateNamesMap_[ F::static_type() ] = "F"; 113 | stateNamesMap_[ G::static_type() ] = "G"; 114 | } 115 | 116 | 117 | int test_main( int, char* [] ) 118 | { 119 | StateIterationTest machine; 120 | machine.AssertInState( "" ); 121 | 122 | machine.initiate(); 123 | machine.AssertInState( "A" ); 124 | 125 | machine.process_event( EvToB() ); 126 | machine.AssertInState( "CD" ); 127 | 128 | machine.process_event( EvToA() ); 129 | machine.AssertInState( "A" ); 130 | 131 | machine.process_event( EvToB() ); 132 | machine.AssertInState( "CD" ); 133 | 134 | machine.process_event( EvToE() ); 135 | machine.AssertInState( "CFG" ); 136 | 137 | machine.process_event( EvToD() ); 138 | machine.AssertInState( "CD" ); 139 | 140 | machine.process_event( EvToE() ); 141 | machine.AssertInState( "CFG" ); 142 | 143 | machine.process_event( EvToA() ); 144 | machine.AssertInState( "A" ); 145 | 146 | machine.terminate(); 147 | machine.AssertInState( "" ); 148 | 149 | return 0; 150 | } 151 | -------------------------------------------------------------------------------- /test/ThrowingBoostAssert.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_TEST_THROWING_BOOST_ASSERT_HPP_INCLUDED 2 | #define BOOST_STATECHART_TEST_THROWING_BOOST_ASSERT_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2005-2006 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | #include 13 | 14 | 15 | 16 | #define BOOST_ENABLE_ASSERT_HANDLER 17 | 18 | 19 | 20 | namespace boost 21 | { 22 | 23 | 24 | void assertion_failed( 25 | char const * expr, char const * func, char const * file, long ) 26 | { 27 | throw std::logic_error( 28 | std::string( "\nAssertion failed: \"" ) + expr + "\"\n" + 29 | "File: \"" + file + "\"\n" + 30 | "Function: \"" + func + "\"\n" ); 31 | } 32 | 33 | 34 | 35 | } // namespace boost 36 | 37 | 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /test/TriggeringEventTest.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2009 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | 18 | #include 19 | 20 | #include // std::allocator 21 | 22 | 23 | 24 | namespace sc = boost::statechart; 25 | namespace mpl = boost::mpl; 26 | 27 | 28 | 29 | struct EvGoToB : sc::event< EvGoToB > {}; 30 | struct EvDoIt : sc::event< EvDoIt > {}; 31 | 32 | struct A; 33 | struct TriggringEventTest : sc::state_machine< 34 | TriggringEventTest, A, 35 | std::allocator< sc::none >, sc::exception_translator<> > 36 | { 37 | void Transit(const EvGoToB &) 38 | { 39 | BOOST_REQUIRE(dynamic_cast(triggering_event()) != 0); 40 | } 41 | }; 42 | 43 | struct B : sc::state< B, TriggringEventTest > 44 | { 45 | B( my_context ctx ) : my_base( ctx ) 46 | { 47 | BOOST_REQUIRE(dynamic_cast(triggering_event()) != 0); 48 | } 49 | 50 | ~B() 51 | { 52 | BOOST_REQUIRE(triggering_event() == 0); 53 | } 54 | 55 | void DoIt( const EvDoIt & ) 56 | { 57 | BOOST_REQUIRE(dynamic_cast(triggering_event()) != 0); 58 | throw std::exception(); 59 | } 60 | 61 | void HandleException( const sc::exception_thrown & ) 62 | { 63 | BOOST_REQUIRE(dynamic_cast(triggering_event()) != 0); 64 | } 65 | 66 | typedef mpl::list< 67 | sc::in_state_reaction< EvDoIt, B, &B::DoIt >, 68 | sc::in_state_reaction< sc::exception_thrown, B, &B::HandleException > 69 | > reactions; 70 | }; 71 | 72 | struct A : sc::state< A, TriggringEventTest > 73 | { 74 | typedef sc::transition< 75 | EvGoToB, B, TriggringEventTest, &TriggringEventTest::Transit 76 | > reactions; 77 | 78 | A( my_context ctx ) : my_base( ctx ) 79 | { 80 | BOOST_REQUIRE(triggering_event() == 0); 81 | } 82 | 83 | ~A() 84 | { 85 | BOOST_REQUIRE(dynamic_cast(triggering_event()) != 0); 86 | } 87 | }; 88 | 89 | 90 | int test_main( int, char* [] ) 91 | { 92 | TriggringEventTest machine; 93 | machine.initiate(); 94 | machine.process_event(EvGoToB()); 95 | machine.process_event(EvDoIt()); 96 | machine.terminate(); 97 | return 0; 98 | } 99 | -------------------------------------------------------------------------------- /test/TuTest.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2005-2008 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include "TuTest.hpp" 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | 17 | 18 | struct Initial : sc::simple_state< Initial, TuTest > 19 | { 20 | void Whatever( const EvX & ) {} 21 | 22 | typedef sc::in_state_reaction< EvX, Initial, &Initial::Whatever > reactions; 23 | }; 24 | 25 | 26 | 27 | void TuTest::initiate() 28 | { 29 | sc::state_machine< TuTest, Initial >::initiate(); 30 | } 31 | 32 | void TuTest::unconsumed_event( const sc::event_base & ) 33 | { 34 | throw std::runtime_error( "Event was not consumed!" ); 35 | } 36 | -------------------------------------------------------------------------------- /test/TuTest.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_STATECHART_TEST_TU_TEST_HPP_INCLUDED 2 | #define BOOST_STATECHART_TEST_TU_TEST_HPP_INCLUDED 3 | ////////////////////////////////////////////////////////////////////////////// 4 | // Copyright 2005-2006 Andreas Huber Doenni 5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | ////////////////////////////////////////////////////////////////////////////// 8 | 9 | 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | #ifdef BOOST_STATECHART_TEST_DYNAMIC_LINK 17 | #ifdef BOOST_STATECHART_TEST_DLL_EXPORT 18 | #define BOOST_STATECHART_DECL BOOST_SYMBOL_EXPORT 19 | #else 20 | #define BOOST_STATECHART_DECL BOOST_SYMBOL_IMPORT 21 | #endif 22 | #endif 23 | 24 | #ifndef BOOST_STATECHART_DECL 25 | #define BOOST_STATECHART_DECL 26 | #endif 27 | 28 | 29 | 30 | namespace sc = boost::statechart; 31 | 32 | #ifdef BOOST_MSVC 33 | # pragma warning( push ) 34 | // class X needs to have dll-interface to be used by clients of class Y 35 | # pragma warning( disable: 4251 ) 36 | // non dll-interface class X used as base for dll-interface class 37 | # pragma warning( disable: 4275 ) 38 | #endif 39 | 40 | struct BOOST_STATECHART_DECL EvX : sc::event< EvX > {}; 41 | struct BOOST_STATECHART_DECL EvY : sc::event< EvY > {}; 42 | 43 | struct Initial; 44 | struct BOOST_STATECHART_DECL TuTest : sc::state_machine< TuTest, Initial > 45 | { 46 | void initiate(); 47 | void unconsumed_event( const sc::event_base & ); 48 | }; 49 | 50 | #ifdef BOOST_MSVC 51 | # pragma warning( pop ) 52 | #endif 53 | 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /test/TuTestMain.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2005-2006 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include "TuTest.hpp" 10 | 11 | #include 12 | 13 | #include 14 | 15 | 16 | 17 | int test_main( int, char* [] ) 18 | { 19 | TuTest machine; 20 | machine.initiate(); 21 | // unconsumed_event sanity check 22 | BOOST_REQUIRE_THROW( machine.process_event( EvY() ), std::runtime_error ); 23 | machine.process_event( EvX() ); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /test/TypeInfoTest.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2005-2006 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | 15 | 16 | namespace sc = boost::statechart; 17 | 18 | 19 | 20 | struct A; 21 | struct TypeInfoTest : sc::state_machine< TypeInfoTest, A > {}; 22 | 23 | struct B; 24 | struct A : sc::simple_state< A, TypeInfoTest, B > {}; 25 | 26 | struct B : sc::simple_state< B, A > {}; 27 | 28 | 29 | int test_main( int, char* [] ) 30 | { 31 | TypeInfoTest machine; 32 | machine.initiate(); 33 | 34 | const TypeInfoTest::state_base_type & activeState = 35 | *machine.state_begin(); 36 | const TypeInfoTest::state_base_type::id_type bType = 37 | activeState.dynamic_type(); 38 | const TypeInfoTest::state_base_type::id_type aType = 39 | activeState.outer_state_ptr()->dynamic_type(); 40 | 41 | BOOST_REQUIRE( bType == B::static_type() ); 42 | BOOST_REQUIRE( bType != A::static_type() ); 43 | BOOST_REQUIRE( aType == A::static_type() ); 44 | BOOST_REQUIRE( aType != B::static_type() ); 45 | 46 | #ifndef BOOST_STATECHART_USE_NATIVE_RTTI 47 | // Ensure that a null custom type id pointer can be of any type 48 | BOOST_REQUIRE( activeState.custom_dynamic_type_ptr< void >() == 0 ); 49 | BOOST_REQUIRE( activeState.custom_dynamic_type_ptr< char >() == 0 ); 50 | BOOST_REQUIRE( activeState.custom_dynamic_type_ptr< bool >() == 0 ); 51 | BOOST_REQUIRE( 52 | activeState.outer_state_ptr()->custom_dynamic_type_ptr< void >() == 0 ); 53 | BOOST_REQUIRE( 54 | activeState.outer_state_ptr()->custom_dynamic_type_ptr< char >() == 0 ); 55 | BOOST_REQUIRE( 56 | activeState.outer_state_ptr()->custom_dynamic_type_ptr< bool >() == 0 ); 57 | 58 | const char * bCustomType = "B"; 59 | const char * aCustomType = "A"; 60 | B::custom_static_type_ptr( bCustomType ); 61 | A::custom_static_type_ptr( aCustomType ); 62 | BOOST_REQUIRE( B::custom_static_type_ptr< char >() == bCustomType ); 63 | BOOST_REQUIRE( A::custom_static_type_ptr< char >() == aCustomType ); 64 | BOOST_REQUIRE( 65 | activeState.custom_dynamic_type_ptr< char >() == bCustomType ); 66 | BOOST_REQUIRE( 67 | activeState.outer_state_ptr()->custom_dynamic_type_ptr< char >() == 68 | aCustomType ); 69 | 70 | // Ensure that a null custom type id pointer can be of any type 71 | bool * pNull = 0; 72 | B::custom_static_type_ptr( pNull ); 73 | A::custom_static_type_ptr( pNull ); 74 | BOOST_REQUIRE( activeState.custom_dynamic_type_ptr< char >() == 0 ); 75 | BOOST_REQUIRE( 76 | activeState.outer_state_ptr()->custom_dynamic_type_ptr< char >() == 0 ); 77 | #endif 78 | 79 | return 0; 80 | } 81 | -------------------------------------------------------------------------------- /test/UnconsumedResultTest.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2005-2006 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #define BOOST_ENABLE_ASSERT_HANDLER 10 | 11 | static int s_failed_assertions = 0; 12 | 13 | namespace boost 14 | { 15 | 16 | void assertion_failed( 17 | char const *, char const *, char const *, long ) 18 | { 19 | ++s_failed_assertions; 20 | } 21 | 22 | } // namespace boost 23 | 24 | 25 | #include 26 | #include 27 | 28 | 29 | namespace sc = boost::statechart; 30 | 31 | 32 | void make_unconsumed_result() 33 | { 34 | // We cannot test sc::result in its natural environment here because a 35 | // failing assert triggers a stack unwind, what will lead to another 36 | // failing assert... 37 | 38 | // Creates a temp sc::result value which is destroyed immediately 39 | sc::detail::result_utility::make_result( sc::detail::do_discard_event ); 40 | } 41 | 42 | int test_main( int, char* [] ) 43 | { 44 | make_unconsumed_result(); 45 | 46 | #ifdef NDEBUG 47 | BOOST_TEST( s_failed_assertions == 0 ); 48 | #else 49 | BOOST_TEST( s_failed_assertions == 1 ); 50 | #endif 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /test/UnsuppDeepHistoryTest.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2005-2006 Andreas Huber Doenni 3 | // Distributed under the Boost Software License, Version 1.0. (See accompany- 4 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | ////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | 16 | 17 | namespace sc = boost::statechart; 18 | namespace mpl = boost::mpl; 19 | 20 | 21 | 22 | struct A; 23 | struct UnsupportedDeepHistoryTest : sc::state_machine< 24 | UnsupportedDeepHistoryTest, A > {}; 25 | 26 | struct B; 27 | struct A : sc::simple_state< 28 | A, UnsupportedDeepHistoryTest, B, sc::has_deep_history > {}; 29 | 30 | struct C; 31 | struct D; 32 | struct B : sc::simple_state< B, A, mpl::list< C, D > > {}; 33 | 34 | struct C : sc::simple_state< C, B::orthogonal< 0 > > {}; 35 | struct D : sc::simple_state< D, B::orthogonal< 1 > > {}; 36 | 37 | 38 | int main() 39 | { 40 | UnsupportedDeepHistoryTest machine; 41 | machine.initiate(); 42 | return 0; 43 | } 44 | --------------------------------------------------------------------------------