]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | <html><head> |
2 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | |
3 | <title>Chapter 1. Founding idea</title><link rel="stylesheet" href="boostbook.css" type="text/css"><meta name="generator" content="DocBook XSL-NS Stylesheets V1.75.2"><link rel="home" href="index.html" title="Meta State Machine (MSM)"><link rel="up" href="pt01.html" title="Part I. User' guide"><link rel="prev" href="pt01.html" title="Part I. User' guide"><link rel="next" href="ch02.html" title="Chapter 2. UML Short Guide"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 1. Founding idea</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="pt01.html">Prev</a> </td><th width="60%" align="center">Part I. User' guide</th><td width="20%" align="right"> <a accesskey="n" href="ch02.html">Next</a></td></tr></table><hr></div><div class="chapter" title="Chapter 1. Founding idea"><div class="titlepage"><div><div><h2 class="title"><a name="d0e99"></a>Chapter 1. Founding idea</h2></div></div></div><p>Let's start with an example taken from the C++ Template Metaprogramming | |
4 | book:</p><pre class="programlisting">class player : public state_machine<player> | |
5 | { | |
6 | // The list of FSM states enum states { Empty, Open, Stopped, Playing, Paused , initial_state = Empty }; | |
7 | ||
8 | // transition actions | |
9 | void start_playback(play const&) { std::cout << "player::start_playback\n"; } | |
10 | void open_drawer(open_close const&) { std::cout << "player::open_drawer\n"; } | |
11 | // more transition actions | |
12 | ... | |
13 | typedef player p; // makes transition table cleaner | |
14 | struct transition_table : mpl::vector11< | |
15 | // Start Event Target Action | |
16 | // +---------+------------+-----------+---------------------------+ | |
17 | row< Stopped , play , Playing , &p::start_playback >, | |
18 | row< Stopped , open_close , Open , &::open_drawer >, | |
19 | // +---------+------------+-----------+---------------------------+ | |
20 | row< Open , open_close , Empty , &p::close_drawer >, | |
21 | // +---------+------------+-----------+---------------------------+ | |
22 | row< Empty , open_close , Open , &p::open_drawer >, | |
23 | row< Empty , cd_detected, Stopped , &p::store_cd_info >, | |
24 | // +---------+------------+-----------+---------------------------+ | |
25 | row< Playing , stop , Stopped , &p::stop_playback >, | |
26 | row< Playing , pause , Paused , &p::pause_playback >, | |
27 | row< Playing , open_close , Open , &p::stop_and_open >, | |
28 | // +---------+------------+-----------+---------------------------+ | |
29 | row< Paused , play , Playing , &p::resume_playback >, | |
30 | row< Paused , stop , Stopped , &p::stop_playback >, | |
31 | row< Paused , open_close , Open , &p::stop_and_open > | |
32 | // +---------+------------+-----------+---------------------------+ | |
33 | > {}; | |
34 | // Replaces the default no-transition response. | |
35 | template <class Event> | |
36 | int no_transition(int state, Event const& e) | |
37 | { | |
38 | std::cout << "no transition from state " << state << " on event " << typeid(e).name() << std::endl; | |
39 | return state; | |
40 | } | |
41 | }; </pre><p>This example is the foundation for the idea driving MSM: a descriptive and | |
42 | expressive language based on a transition table with as little syntactic noise as | |
43 | possible, all this while offering as many features from the UML 2.0 standard as | |
44 | possible. MSM also offers several expressive state machine definition syntaxes with | |
45 | different trade-offs.</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="pt01.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="pt01.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Part I. User' guide </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 2. UML Short Guide</td></tr></table></div></body></html> |