]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/msm/doc/src/msm.xml
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / msm / doc / src / msm.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <?oxygen RNGSchema="http://www.oasis-open.org/docbook/xml/5.0/rng/docbook.rng" type="xml"?>
3 <book xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0">
4 <info>
5 <title>Meta State Machine (MSM)</title>
6 <author>
7 <personname>Christophe Henry</personname>
8 <email>christophe.j.henry@googlemail.com</email>
9 </author>
10 <copyright>
11 <year>2008-2010</year>
12 <holder>
13 <phrase> Distributed under the Boost Software License, Version 1.0. (See
14 accompanying file LICENSE_1_0.txt or copy at <link
15 xlink:href="http://www.boost.org/LICENSE_1_0.txt"
16 >http://www.boost.org/LICENSE_1_0.txt</link> ) </phrase>
17 </holder>
18 </copyright>
19 </info>
20 <preface>
21 <title>Preface</title>
22 <para>MSM is a library allowing you to easily and quickly define state machines of very high
23 performance. From this point, two main questions usually quickly arise, so please allow
24 me to try answering them upfront.</para>
25 <para>
26 <itemizedlist>
27 <listitem>
28 <para>When do I need a state machine?</para>
29 <para>More often that you think. Very often, one defined a state machine
30 informally without even noticing it. For example, one declares inside a
31 class some boolean attribute, say to remember that a task has been
32 completed. Later the boolean actually needs a third value, so it becomes an
33 int. A few weeks, a second attribute is needed. Then a third. Soon, you find
34 yourself writing:</para>
35 <para><code>void incoming_data(data)</code></para>
36 <para><code>{</code></para>
37 <para><code> if (data == packet_3 &amp;&amp; flag1 == work_done &amp;&amp; flag2
38 > step3)...</code></para>
39 <para><code>}</code></para>
40 <para>This starts to look like event processing (contained inside data) if some
41 stage of the object life has been achieved (but is ugly).</para>
42 <para>This could be a protocol definition and it is a common use case for state
43 machines. Another common one is a user interface. The stage of the user's
44 interaction defines if some button is active, a functionality is available,
45 etc.</para>
46 <para>But there are many more use cases if you start looking. Actually, a whole
47 model-driven development method, Executable UML
48 (http://en.wikipedia.org/wiki/Executable_UML) specifies its complete dynamic
49 behavior using state machines. Class diagram, state machine diagrams, and an
50 action language are all you absolutely need in the Executable UML
51 world.</para>
52 </listitem>
53 <listitem>
54 <para>Another state machine library? What for?</para>
55 <para>True, there are many state machine libraries. This should already be an
56 indication that if you're not using any of them, you might be missing
57 something. Why should you use this one? Unfortunately, when looking for a
58 good state machine library, you usually pretty fast hit one or several of
59 the following snags:<itemizedlist>
60 <listitem>
61 <para>speed: "state machines are slow" is usually the first
62 criticism you might hear. While it is often an excuse not to use
63 any and instead resort to dirty, hand-written implementations (I
64 mean, no, yours are not dirty of course, I'm talking about other
65 developers). MSM removes this often feeble excuse because it is
66 blazingly fast. Most hand-written implementations will be beaten
67 by MSM.</para>
68 </listitem>
69 <listitem>
70 <para>ease of use: good argument. If you used another library, you
71 are probably right. Many state machine definitions will look
72 similar to:</para>
73 <para><code>state s1 = new State; // a state</code></para>
74 <para><code>state s2 = new State; // another state</code></para>
75 <para><code>event e = new Event; // event</code></para>
76 <para><code>s1->addTransition(e,s2); // transition s1 ->
77 s2</code></para>
78 <para>The more transitions you have, the less readable it is. A long
79 time ago, there was not so much Java yet, and many electronic
80 systems were built with a state machine defined by a simple
81 transition table. You could easily see the whole structure and
82 immediately see if you forgot some transitions. Thanks to our
83 new OO techniques, this ease of use was gone. MSM gives you back
84 the transition table and reduces the noise to the
85 minimum.</para>
86 </listitem>
87 <listitem>
88 <para>expressiveness: MSM offers several front-ends and constantly
89 tries to improve state machine definition techniques. For
90 example, you can define a transition with eUML (one of MSM's
91 front-ends) as:</para>
92 <para><code>state1 == state2 + event [condition] /
93 action</code></para>
94 <para>This is not simply syntactic sugar. Such a formalized,
95 readable structure allows easy communication with domain experts
96 of a software to be constructed. Having domain experts
97 understand your code will greatly reduce the number of
98 bugs.</para>
99 </listitem>
100 <listitem>
101 <para>model-driven-development: a common difficulty of a
102 model-driven development is the complexity of making a
103 round-trip (generating code from model and then model from
104 code). This is due to the fact that if a state machine structure
105 is hard for you to read, chances are that your parsing tool will
106 also have a hard time. MSM's syntax will hopefully help tool
107 writers.</para>
108 </listitem>
109 <listitem>
110 <para>features: most developers use only 20% of the richly defined
111 UML standard. Unfortunately, these are never the same 20% for
112 all. And so, very likely, one will need something from the
113 standard which is not implemented. MSM offers a very large part
114 of the standard, with more on the way.</para>
115 </listitem>
116 </itemizedlist></para>
117 <para>Let us not wait any longer, I hope you will enjoy MSM and have fun with
118 it!</para>
119 </listitem>
120 </itemizedlist>
121 </para>
122 </preface>
123 <part>
124 <title>User' guide</title>
125 <chapter>
126 <title>Founding idea</title>
127 <para>Let's start with an example taken from the C++ Template Metaprogramming
128 book:</para>
129 <programlisting>class player : public state_machine&lt;player>
130 {
131 // The list of FSM states enum states { Empty, Open, Stopped, Playing, Paused , initial_state = Empty };
132
133 // transition actions
134 void start_playback(play const&amp;) { std::cout &lt;&lt; "player::start_playback\n"; }
135 void open_drawer(open_close const&amp;) { std::cout &lt;&lt; "player::open_drawer\n"; }
136 // more transition actions
137 ...
138 typedef player p; // makes transition table cleaner
139 struct transition_table : mpl::vector11&lt;
140 // Start Event Target Action
141 // +---------+------------+-----------+---------------------------+
142 row&lt; Stopped , play , Playing , &amp;p::start_playback >,
143 row&lt; Stopped , open_close , Open , &amp;::open_drawer >,
144 // +---------+------------+-----------+---------------------------+
145 row&lt; Open , open_close , Empty , &amp;p::close_drawer >,
146 // +---------+------------+-----------+---------------------------+
147 row&lt; Empty , open_close , Open , &amp;p::open_drawer >,
148 row&lt; Empty , cd_detected, Stopped , &amp;p::store_cd_info >,
149 // +---------+------------+-----------+---------------------------+
150 row&lt; Playing , stop , Stopped , &amp;p::stop_playback >,
151 row&lt; Playing , pause , Paused , &amp;p::pause_playback >,
152 row&lt; Playing , open_close , Open , &amp;p::stop_and_open >,
153 // +---------+------------+-----------+---------------------------+
154 row&lt; Paused , play , Playing , &amp;p::resume_playback >,
155 row&lt; Paused , stop , Stopped , &amp;p::stop_playback >,
156 row&lt; Paused , open_close , Open , &amp;p::stop_and_open >
157 // +---------+------------+-----------+---------------------------+
158 > {};
159 // Replaces the default no-transition response.
160 template &lt;class Event>
161 int no_transition(int state, Event const&amp; e)
162 {
163 std::cout &lt;&lt; "no transition from state " &lt;&lt; state &lt;&lt; " on event " &lt;&lt; typeid(e).name() &lt;&lt; std::endl;
164 return state;
165 }
166 }; </programlisting>
167 <para>This example is the foundation for the idea driving MSM: a descriptive and
168 expressive language based on a transition table with as little syntactic noise as
169 possible, all this while offering as many features from the UML 2.0 standard as
170 possible. MSM also offers several expressive state machine definition syntaxes with
171 different trade-offs.</para>
172 </chapter>
173 <chapter>
174 <title>UML Short Guide</title>
175 <sect1>
176 <title>What are state machines?</title>
177 <para>State machines are the description of a thing's lifeline. They describe the
178 different stages of the lifeline, the events influencing it, and what it does
179 when a particular event is detected at a particular stage. They offer the
180 complete specification of the dynamic behavior of the thing.</para>
181 </sect1>
182 <sect1>
183 <title>Concepts</title>
184 <para>Thinking in terms of state machines is a bit surprising at first, so let us
185 have a quick glance at the concepts.</para>
186 <sect2>
187 <title>State machine, state, transition, event </title>
188 <para>A state machine is a concrete model describing the behavior of a system.
189 It is composed of a finite number of states and transitions.</para>
190 <para>
191 <inlinemediaobject>
192 <imageobject>
193 <imagedata fileref="images/sm.gif"/>
194 </imageobject>
195 </inlinemediaobject></para>
196 <para>A simple state has no sub states. It can have data, entry and exit
197 behaviors and deferred events. One can provide entry and exit behaviors
198 (also called actions) to states (or state machines), which are executed
199 whenever a state is entered or left, no matter how. A state can also have
200 internal transitions which cause no entry or exit behavior to be called. A
201 state can mark events as deferred. This means the event cannot be processed
202 if this state is active, but it must be retained. Next time a state not
203 deferring this event is active, the event will be processed, as if it had
204 just been fired. </para>
205 <para><inlinemediaobject>
206 <imageobject>
207 <imagedata fileref="images/state.gif"/>
208 </imageobject>
209 </inlinemediaobject></para>
210 <para>A transition is the switching between active states, triggered by an
211 event. Actions and guard conditions can be attached to the transition. The
212 action executes when the transition fires, the guard is a Boolean operation
213 executed first and which can prevent the transition from firing by returning
214 false.</para>
215 <para>
216 <inlinemediaobject>
217 <imageobject>
218 <imagedata fileref="images/transition.jpg"/>
219 </imageobject>
220 </inlinemediaobject></para>
221 <para>An initial state marks the first active state of a state machine. It has
222 no real existence and neither has the transition originating from it.</para>
223 <para>
224 <inlinemediaobject>
225 <imageobject>
226 <imagedata fileref="images/init_state.gif"/>
227 </imageobject>
228 </inlinemediaobject></para>
229 </sect2>
230 <sect2>
231 <title>Submachines, orthogonal regions, pseudostates </title>
232 <para>A composite state is a state containing a region or decomposed in two or
233 more regions. A composite state contains its own set of states and regions. </para>
234 <para>A submachine is a state machine inserted as a state in another state
235 machine. The same submachine can be inserted more than once. </para>
236 <para>Orthogonal regions are parts of a composite state or submachine, each
237 having its own set of mutually exclusive set of states and transitions. </para>
238 <para><inlinemediaobject>
239 <imageobject>
240 <imagedata fileref="images/regions.gif" width="60%" scalefit="1"/>
241 </imageobject>
242 </inlinemediaobject></para>
243 <para>UML also defines a number of pseudo states, which are considered important
244 concepts to model, but not enough to make them first-class citizens. The
245 terminate pseudo state terminates the execution of a state machine (MSM
246 handles this slightly differently. The state machine is not destroyed but no
247 further event processing occurs.). </para>
248 <para><inlinemediaobject>
249 <imageobject>
250 <imagedata fileref="images/terminate.gif"/>
251 </imageobject>
252 </inlinemediaobject></para>
253 <para>An exit point pseudo state exits a composite state or a submachine and
254 forces termination of execution in all contained regions.</para>
255 <para><inlinemediaobject>
256 <imageobject>
257 <imagedata fileref="images/exit.gif" width="60%" scalefit="1"/>
258 </imageobject>
259 </inlinemediaobject></para>
260 <para>An entry point pseudo state allows a kind of controlled entry inside a
261 composite. Precisely, it connects a transition outside the composite to a
262 transition inside the composite. An important point is that this mechanism
263 only allows a single region to be entered. In the above diagram, in region1,
264 the initial state would become active. </para>
265 <para><inlinemediaobject>
266 <imageobject>
267 <imagedata fileref="images/entry_point.gif"/>
268 </imageobject>
269 </inlinemediaobject></para>
270 <para>There are also two more ways to enter a submachine (apart the obvious and
271 more common case of a transition terminating on the submachine as shown in
272 the region case). An explicit entry means that an inside state is the target
273 of a transition. Unlike with direct entry, no tentative encapsulation is
274 made, and only one transition is executed. An explicit exit is a transition
275 from an inner state to a state outside the submachine (not supported by
276 MSM). I would not recommend using explicit entry or exit. </para>
277 <para><inlinemediaobject>
278 <imageobject>
279 <imagedata fileref="images/explicit.gif"/>
280 </imageobject>
281 </inlinemediaobject></para>
282 <para>The last entry possibility is using fork. A fork is an explicit entry into
283 one or more regions. Other regions are again activated using their initial
284 state. </para>
285 <para><inlinemediaobject>
286 <imageobject>
287 <imagedata fileref="images/fork.gif" width="70%" scalefit="1"/>
288 </imageobject>
289 </inlinemediaobject></para>
290 </sect2>
291 <sect2>
292 <title>
293 <command xml:id="uml-history"/>History </title>
294 <para>UML defines two kinds of history, shallow history and deep history.
295 Shallow history is a pseudo state representing the most recent substate of a
296 submachine. A submachine can have at most one shallow history. A transition
297 with a history pseudo state as target is equivalent to a transition with the
298 most recent substate as target. And very importantly, only one transition
299 may originate from the history. Deep history is a shallow history
300 recursively reactivating the substates of the most recent substate. It is
301 represented like the shallow history with a star (H* inside a
302 circle).</para>
303 <para>
304 <inlinemediaobject>
305 <imageobject>
306 <imagedata fileref="images/history.gif" width="60%" scalefit="1"/>
307 </imageobject>
308 </inlinemediaobject></para>
309 <para>History is not a completely satisfying concept. First of all, there can be
310 just one history pseudo state and only one transition may originate from it.
311 So they do not mix well with orthogonal regions as only one region can be
312 “remembered”. Deep history is even worse and looks like a last-minute
313 addition. History has to be activated by a transition and only one
314 transition originates from it, so how to model the transition originating
315 from the deep history pseudo state and pointing to the most recent substate
316 of the substate? As a bonus, it is also inflexible and does not accept new
317 types of histories. Let's face it, history sounds great and is useful in
318 theory, but the UML version is not quite making the cut. And therefore, MSM
319 provides a different version of this useful concept. </para>
320 </sect2>
321 <sect2>
322 <title><command xml:id="uml-anonymous"/>Completion transitions / anonymous
323 transitions</title>
324 <para>Completion events (or transitions), also called anonymous transitions, are
325 defined as transitions having no defined event triggering them. This means
326 that such transitions will immediately fire when a state being the source of
327 an anonymous transition becomes active, provided that a guard allows it.
328 They are useful in modeling algorithms as an activity diagram would normally
329 do. In the real-time world, they have the advantage of making it easier to
330 estimate how long a periodically executed action will last. For example,
331 consider the following diagram. </para>
332 <para><inlinemediaobject>
333 <imageobject>
334 <imagedata fileref="images/completion.gif"/>
335 </imageobject>
336 </inlinemediaobject></para>
337 <para>The designer now knows at any time that he will need a maximum of 4
338 transitions. Being able to estimate how long a transition takes, he can
339 estimate how much of a time frame he will need to require (real-time tasks
340 are often executed at regular intervals). If he can also estimate the
341 duration of actions, he can even use graph algorithms to better estimate his
342 timing requirements. </para>
343 </sect2>
344 <sect2>
345 <title><command xml:id="UML-internal-transition"/> Internal transitions </title>
346 <para>Internal transitions are transitions executing in the scope of the active
347 state, being a simple state or a submachine. One can see them as a
348 self-transition of this state, without an entry or exit action
349 called.</para>
350 </sect2>
351 <sect2>
352 <title>
353 <command xml:id="transition-conflict"/>Conflicting transitions </title>
354 <para>If, for a given event, several transitions are enabled, they are said to
355 be in conflict. There are two kinds of conflicts: <itemizedlist>
356 <listitem>
357 <para>For a given source state, several transitions are defined,
358 triggered by the same event. Normally, the guard condition in
359 each transition defines which one is fired.</para>
360 </listitem>
361 <listitem>
362 <para>The source state is a submachine or simple state and the
363 conflict is between a transition internal to this state and a
364 transition triggered by the same event and having as target
365 another state.</para>
366 </listitem>
367 </itemizedlist>The first one is simple; one only needs to define two or more
368 rows in the transition table, with the same source and trigger, with a
369 different guard condition. Beware, however, that the UML standard wants
370 these conditions to be not overlapping. If they do, the standard says
371 nothing except that this is incorrect, so the implementer is free to
372 implement it the way he sees fit. In the case of MSM, the transition
373 appearing last in the transition table gets selected first, if it returns
374 false (meaning disabled), the library tries with the previous one, and so
375 on.</para>
376 <para>
377 <inlinemediaobject>
378 <imageobject>
379 <imagedata fileref="images/conflict1.gif"/>
380 </imageobject>
381 </inlinemediaobject></para>
382 <para>In the second case, UML defines that the most inner transition gets
383 selected first, which makes sense, otherwise no exit point pseudo state
384 would be possible (the inner transition brings us to the exit point, from
385 where the containing state machine can take over). </para>
386 <para><inlinemediaobject>
387 <imageobject>
388 <imagedata fileref="images/conflict2.gif" width="60%" scalefit="1"/>
389 </imageobject>
390 </inlinemediaobject></para>
391 <para>MSM handles both cases itself, so the designer needs only concentrate on
392 its state machine and the UML subtleties (not overlapping conditions), not
393 on implementing this behavior himself. </para>
394 </sect2>
395 </sect1>
396 <sect1>
397 <title>Added concepts</title>
398 <itemizedlist>
399 <listitem>
400 <para>Interrupt states: a terminate state which can be exited if a defined
401 event is triggered.</para>
402 </listitem>
403 <listitem>
404 <para>Kleene (any) event: a transition with a kleene event will accept any
405 event as trigger. Unlike a completion transition, an event must be
406 triggered and the original event is kept accessible in the kleene
407 event.</para>
408 </listitem>
409 </itemizedlist>
410 </sect1>
411 <sect1>
412 <title>State machine glossary</title>
413 <para>
414 <itemizedlist>
415 <listitem>
416 <para>state machine: the life cycle of a thing. It is made of states,
417 regions, transitions and processes incoming events.</para>
418 </listitem>
419 <listitem>
420 <para>state: a stage in the life cycle of a state machine. A state (like
421 a submachine) can have an entry and exit behaviors.</para>
422 </listitem>
423 <listitem>
424 <para>event: an incident provoking (or not) a reaction of the state
425 machine</para>
426 </listitem>
427 <listitem>
428 <para>transition: a specification of how a state machine reacts to an
429 event. It specifies a source state, the event triggering the
430 transition, the target state (which will become the newly active
431 state if the transition is triggered), guard and actions.</para>
432 </listitem>
433 <listitem>
434 <para>action: an operation executed during the triggering of the
435 transition.</para>
436 </listitem>
437 <listitem>
438 <para>guard: a boolean operation being able to prevent the triggering of
439 a transition which would otherwise fire.</para>
440 </listitem>
441 <listitem>
442 <para>transition table: representation of a state machine. A state
443 machine diagram is a graphical, but incomplete representation of the
444 same model. A transition table, on the other hand, is a complete
445 representation.</para>
446 </listitem>
447 <listitem>
448 <para>initial state: The state in which the state machine starts. Having
449 several orthogonal regions means having as many initial
450 states.</para>
451 </listitem>
452 <listitem>
453 <para>submachine: A submachine is a state machine inserted as a state in
454 another state machine and can be found several times in a same state
455 machine.</para>
456 </listitem>
457 <listitem>
458 <para>orthogonal regions: (logical) parallel flow of execution of a
459 state machine. Every region of a state machine gets a chance to
460 process an incoming event.</para>
461 </listitem>
462 <listitem>
463 <para>terminate pseudo-state: when this state becomes active, it
464 terminates the execution of the whole state machine. MSM does not
465 destroy the state machine as required by the UML standard, however,
466 which lets you keep all the state machine's data.</para>
467 </listitem>
468 <listitem>
469 <para>entry/exit pseudo state: defined for submachines and are defined
470 as a connection between a transition outside of the submachine and a
471 transition inside the submachine. It is a way to enter or leave a
472 submachine through a predefined point.</para>
473 </listitem>
474 <listitem>
475 <para>fork: a fork allows explicit entry into several orthogonal regions
476 of a submachine.</para>
477 </listitem>
478 <listitem>
479 <para>history: a history is a way to remember the active state of a
480 submachine so that the submachine can proceed in its last active
481 state next time it becomes active.</para>
482 </listitem>
483 <listitem>
484 <para>completion events (also called completion/anonymous transitions):
485 when a transition has no named event triggering it, it automatically
486 fires when the source state is active, unless a guard forbids
487 it.</para>
488 </listitem>
489 <listitem>
490 <para>transition conflict: a conflict is present if for a given source
491 state and incoming event, several transitions are possible. UML
492 specifies that guard conditions have to solve the conflict.</para>
493 </listitem>
494 <listitem>
495 <para>internal transitions: transition from a state to itself without
496 having exit and entry actions being called.</para>
497 </listitem>
498 </itemizedlist>
499 </para>
500 </sect1>
501 </chapter>
502 <chapter>
503 <title>Tutorial</title>
504 <sect1>
505 <title>Design</title>
506 <para>MSM is divided between front–ends and back-ends. At the moment, there is just
507 one back-end. On the front-end side, you will find three of them which are as
508 many state machine description languages, with many more possible. For potential
509 language writers, this document contains a <link
510 xlink:href="#internals-front-back-interface">description of the interface
511 between front-end and back-end</link>.</para>
512 <para>The first front-end is an adaptation of the example provided in the <link
513 xlink:href="http://boostpro.com/mplbook">MPL book</link> with actions
514 defined as pointers to state or state machine methods. The second one is based
515 on functors. The third, eUML (embedded UML) is an experimental language based on
516 Boost.Proto and Boost.Typeof and hiding most of the metaprogramming to increase
517 readability. Both eUML and the functor front-end also offer a functional library
518 (a bit like Boost.Phoenix) for use as action language (UML defining
519 none).</para>
520 </sect1>
521 <sect1>
522 <title><command xml:id="basic-front-end"/>Basic front-end</title>
523 <para>This is the historical front-end, inherited from the MPL book. It provides a
524 transition table made of rows of different names and functionality. Actions and
525 guards are defined as methods and referenced through a pointer in the
526 transition. This front-end provides a simple interface making easy state
527 machines easy to define, but more complex state machines a bit harder.</para>
528 <sect2>
529 <title>A simple example</title>
530 <para>Let us have a look at a state machine diagram of the founding
531 example:</para>
532 <para><inlinemediaobject>
533 <imageobject>
534 <imagedata fileref="images/SimpleTutorial.jpg" width="60%"
535 scalefit="1"/>
536 </imageobject>
537 </inlinemediaobject></para>
538 <para>We are now going to build it with MSM's basic front-end. An <link
539 xlink:href="examples/SimpleTutorial.cpp">implementation</link> is also
540 provided.</para>
541 </sect2>
542 <sect2>
543 <title>Transition table</title>
544 <para>As previously stated, MSM is based on the transition table, so let us
545 define one:</para>
546 <programlisting>
547 struct transition_table : mpl::vector&lt;
548 // Start Event Target Action Guard
549 // +---------+------------+-----------+---------------------------+----------------------------+
550 a_row&lt; Stopped , play , Playing , &amp;player_::start_playback >,
551 a_row&lt; Stopped , open_close , Open , &amp;player_::open_drawer >,
552 _row&lt; Stopped , stop , Stopped >,
553 // +---------+------------+-----------+---------------------------+----------------------------+
554 a_row&lt; Open , open_close , Empty , &amp;player_::close_drawer >,
555 // +---------+------------+-----------+---------------------------+----------------------------+
556 a_row&lt; Empty , open_close , Open , &amp;player_::open_drawer >,
557 row&lt; Empty , cd_detected, Stopped , &amp;player_::store_cd_info , &amp;player_::good_disk_format >,
558 row&lt; Empty , cd_detected, Playing , &amp;player_::store_cd_info , &amp;player_::auto_start >,
559 // +---------+------------+-----------+---------------------------+----------------------------+
560 a_row&lt; Playing , stop , Stopped , &amp;player_::stop_playback >,
561 a_row&lt; Playing , pause , Paused , &amp;player_::pause_playback >,
562 a_row&lt; Playing , open_close , Open , &amp;player_::stop_and_open >,
563 // +---------+------------+-----------+---------------------------+----------------------------+
564 a_row&lt; Paused , end_pause , Playing , &amp;player_::resume_playback >,
565 a_row&lt; Paused , stop , Stopped , &amp;player_::stop_playback >,
566 a_row&lt; Paused , open_close , Open , &amp;player_::stop_and_open >
567 // +---------+------------+-----------+---------------------------+----------------------------+
568 > {};
569 </programlisting>
570 <para>You will notice that this is almost exactly our founding example. The only
571 change in the transition table is the different types of transitions (rows).
572 The founding example forces one to define an action method and offers no
573 guards. You have 4 basic row types:<itemizedlist>
574 <listitem>
575 <para><code>row</code> takes 5 arguments: start state, event, target
576 state, action and guard.</para>
577 </listitem>
578 <listitem>
579 <para><code>a_row</code> (“a” for action) allows defining only the
580 action and omit the guard condition.</para>
581 </listitem>
582 <listitem>
583 <para><code>g_row</code> (“g” for guard) allows omitting the action
584 behavior and defining only the guard.</para>
585 </listitem>
586 <listitem>
587 <para><code>_row</code> allows omitting action and guard.</para>
588 </listitem>
589 </itemizedlist></para>
590 <para>The signature for an action methods is void method_name (event
591 const&amp;), for example:</para>
592 <programlisting>void stop_playback(stop const&amp;)</programlisting>
593 <para>Action methods return nothing and take the argument as const reference. Of
594 course nothing forbids you from using the same action for several
595 events:</para>
596 <programlisting>template &lt;class Event> void stop_playback(Eventconst&amp;)</programlisting>
597 <para>Guards have as only difference the return value, which is a
598 boolean:</para>
599 <programlisting>bool good_disk_format(cd_detected const&amp; evt)</programlisting>
600 <para>The transition table is actually a MPL vector (or list), which brings the
601 limitation that the default maximum size of the table is 20. If you need
602 more transitions, overriding this default behavior is necessary, so you need
603 to add before any header:</para>
604 <programlisting>#define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
605 #define BOOST_MPL_LIMIT_VECTOR_SIZE 30 //or whatever you need
606 #define BOOST_MPL_LIMIT_MAP_SIZE 30 //or whatever you need </programlisting>
607 <para>The other limitation is that the MPL types are defined only up to 50
608 entries. For the moment, the only solution to achieve more is to add headers
609 to the MPL (luckily, this is not very complicated).</para>
610 </sect2>
611 <sect2>
612 <title>Defining states with entry/exit actions</title>
613 <para>While states were enums in the MPL book, they now are classes, which
614 allows them to hold data, provide entry, exit behaviors and be reusable (as
615 they do not know anything about the containing state machine). To define a
616 state, inherit from the desired state type. You will mainly use simple
617 states:</para>
618 <para>struct Empty : public msm::front::state&lt;> {};</para>
619 <para>They can optionally provide entry and exit behaviors:</para>
620 <programlisting language="C++">
621 struct Empty : public msm::front::state&lt;>
622 {
623 template &lt;class Event, class Fsm>
624 void on_entry(Event const&amp;, Fsm&amp; )
625 {std::cout &lt;&lt;"entering: Empty" &lt;&lt; std::endl;}
626 template &lt;class Event, class Fsm>
627 void on_exit(Event const&amp;, Fsm&amp; )
628 {std::cout &lt;&lt;"leaving: Empty" &lt;&lt; std::endl;}
629 };
630 </programlisting>
631 <para>Notice how the entry and exit behaviors are templatized on the event and
632 state machine. Being generic facilitates reuse. There are more state types
633 (terminate, interrupt, pseudo states, etc.) corresponding to the UML
634 standard state types. These will be described in details in the next
635 sections.</para>
636 </sect2>
637 <sect2>
638 <title>What do you actually do inside actions / guards?</title>
639 <para>State machines define a structure and important parts of the complete
640 behavior, but not all. For example if you need to send a rocket to Alpha
641 Centauri, you can have a transition to a state "SendRocketToAlphaCentauri"
642 but no code actually sending the rocket. This is where you need actions. So
643 a simple action could be:</para>
644 <programlisting>template &lt;class Fire> void send_rocket(Fire const&amp;)
645 {
646 fire_rocket();
647 }</programlisting>
648 <para>Ok, this was simple. Now, we might want to give a direction. Let us suppose
649 this information is externally given when needed, it makes sense do use the
650 event for this:</para>
651 <programlisting>// Event
652 struct Fire {Direction direction;};
653 template &lt;class Fire> void send_rocket(Fire const&amp; evt)
654 {
655 fire_rocket(evt.direction);
656 }</programlisting>
657 <para>We might want to calculate the direction based not only on external data
658 but also on data accumulated during previous work. In this case, you might
659 want to have this data in the state machine itself. As transition actions
660 are members of the front-end, you can directly access the data:</para>
661 <programlisting>// Event
662 struct Fire {Direction direction;};
663 //front-end definition, see down
664 struct launcher_ : public msm::front::state_machine_def&lt;launcher_>{
665 Data current_calculation;
666 template &lt;class Fire> void send_rocket(Fire const&amp; evt)
667 {
668 fire_rocket(evt.direction, current_calculation);
669 }
670 ...
671 };</programlisting>
672 <para>Entry and exit actions represent a behavior common to a state, no matter
673 through which transition it is entered or left. States being reusable, it
674 might make sense to locate your data there instead of in the state machine,
675 to maximize reuse and make code more readable. Entry and exit actions have
676 access to the state data (being state members) but also to the event and
677 state machine, like transition actions. This happens through the Event and
678 Fsm template parameters:</para>
679 <programlisting>struct Launching : public msm::front::state&lt;>
680 {
681 template &lt;class Event, class Fsm>
682 void on_entry(Event const&amp; evt, Fsm&amp; fsm)
683 {
684 fire_rocket(evt.direction, fsm.current_calculation);
685 }
686 };</programlisting>
687 <para>Exit actions are also ideal for clanup when the state becomes
688 inactive.</para>
689 <para>Another possible use of the entry action is to pass data to substates /
690 submachines. Launching is a substate containing a <code>data</code> attribute:</para>
691 <programlisting>struct launcher_ : public msm::front::state_machine_def&lt;launcher_>{
692 Data current_calculation;
693 // state machines also have entry/exit actions
694 template &lt;class Event, class Fsm>
695 void on_entry(Event const&amp; evt, Fsm&amp; fsm)
696 {
697 launcher_::Launching&amp; s = fsm.get_state&lt;launcher_::Launching&amp;>();
698 s.data = fsm.current_calculation;
699 }
700 ...
701 };</programlisting>
702 <para>The <command xlink:href="#backend-fsm-constructor-args">set_states</command> back-end method allows you to replace a complete
703 state.</para>
704 <para>The <command xlink:href="#functor-front-end-actions">functor</command> front-end and eUML offer more capabilities.</para>
705 <para>However, this basic front-end also has special capabilities using the row2
706 / irow2 transitions.<command xlink:href="#basic-row2">_row2, a_row2, row2,
707 g_row2, a_irow2, irow2, g_irow2</command> let you call an action located
708 in any state of the current fsm or in the front-end itself, thus letting you
709 place useful data anywhere you see fit.</para>
710 <para>It is sometimes desirable to generate new events for the state machine
711 inside actions. Since the process_event method belongs to the back end, you
712 first need to gain a reference to it. The back end derives from the front
713 end, so one way of doing this is to use a cast:</para>
714 <programlisting>struct launcher_ : public msm::front::state_machine_def&lt;launcher_>{
715 template &lt;class Fire> void send_rocket(Fire const&amp; evt)
716 {
717 fire_rocket();
718 msm::back::state_machine&lt;launcher_> &amp;fsm = static_cast&lt;msm::back::state_machine&lt;launcher_> &amp;>(*this);
719 fsm.process_event(rocket_launched());
720 }
721 ...
722 };</programlisting>
723 <para>The same can be implemented inside entry/exit actions. Admittedly, this is
724 a bit awkward. A more natural mechanism is available using the <command
725 xlink:href="#functor-front-end-actions">functor</command>
726 front-end.</para>
727 </sect2>
728 <sect2>
729 <title>Defining a simple state machine</title>
730 <para>Declaring a state machine is straightforward and is done with a high
731 signal / noise ratio. In our player example, we declare the state machine
732 as:</para>
733 <programlisting>struct player_ : public msm::front::state_machine_def&lt;player_>{
734 /* see below */}</programlisting>
735 <para>This declares a state machine using the basic front-end. We now declare
736 inside the state machine structure the initial state:</para>
737 <para>
738 <programlisting>typedef Empty initial_state;</programlisting>
739 </para>
740 <para>And that is about all of what is absolutely needed. In the example, the
741 states are declared inside the state machine for readability but this is not
742 a requirements, states can be declared wherever you like.</para>
743 <para>All what is left to do is to pick a back-end (which is quite simple as
744 there is only one at the moment):</para>
745 <para>
746 <programlisting>typedef msm::back::state_machine&lt;player_> player;</programlisting>
747 </para>
748 <para>You now have a ready-to-use state machine with entry/exit actions, guards,
749 transition actions, a message queue so that processing an event can generate
750 another event. The state machine also adapted itself to your need and
751 removed almost all features we didn't use in this simple example. Note that
752 this is not per default the fastest possible state machine. See the section
753 "getting more speed" to know how to get the maximum speed. In a nutshell,
754 MSM cannot know about your usage of some features so you will have to
755 explicitly tell it.</para>
756 <para>State objects are built automatically with the state machine. They will
757 exist until state machine destruction. MSM is using Boost.Fusion behind the
758 hood. This unfortunately means that if you define more than 10 states, you
759 will need to extend the default:</para>
760 <para>
761 <programlisting>#define FUSION_MAX_VECTOR_SIZE 20 // or whatever you need
762 </programlisting>
763 </para>
764 <para>When an unexpected event is fired, the <code>no_transition(event, state
765 machine, state id)</code> method of the state machine is called . By
766 default, this method simply asserts when called. It is possible to overwrite
767 the <code>no_transition</code> method to define a different handling:</para>
768 <para>
769 <programlisting>template &lt;class Fsm,class Event>
770 void no_transition(Event const&amp; e, Fsm&amp; ,int state){...}</programlisting>
771 </para>
772 <para><emphasis role="underline">Note</emphasis>: you might have noticed that
773 the tutorial calls <code>start()</code> on the state machine just after
774 creation. The start method will initiate the state machine, meaning it will
775 activate the initial state, which means in turn that the initial state's
776 entry behavior will be called. The reason why we need this will be explained
777 in the <link xlink:href="#backend-start">back-end part</link>. After a call
778 to start, the state machine is ready to process events. The same way,
779 calling <code>stop()</code> will cause the last exit actions to be called.</para>
780 </sect2>
781 <sect2>
782 <title>Defining a submachine</title>
783 <para>We now want to extend our last state machine by making the Playing state a
784 state machine itself (a submachine).</para>
785 <para><inlinemediaobject>
786 <imageobject>
787 <imagedata fileref="images/CompositeTutorial.jpg" width="60%"
788 scalefit="1"/>
789 </imageobject>
790 </inlinemediaobject></para>
791 <para>Again, an <link xlink:href="examples/CompositeTutorial.cpp">example</link>
792 is also provided.</para>
793 <para>A submachine really is a state machine itself, so we declare Playing as
794 such, choosing a front-end and a back-end:</para>
795 <para>
796 <programlisting>struct Playing_ : public msm::front::state_machine_def&lt;Playing_>{...}
797 typedef msm::back::state_machine&lt;Playing_> Playing;</programlisting>
798 </para>
799 <para>Like for any state machine, one also needs a transition table and an
800 initial state:</para>
801 <para>
802 <programlisting>
803 struct transition_table : mpl::vector&lt;
804 // Start Event Target Action Guard
805 // +--------+---------+--------+---------------------------+------+
806 a_row&lt; Song1 , NextSong, Song2 , &amp;Playing_::start_next_song >,
807 a_row&lt; Song2 , NextSong, Song1 , &amp;Playing_::start_prev_song >,
808 a_row&lt; Song2 , NextSong, Song3 , &amp;Playing_::start_next_song >,
809 a_row&lt; Song3 , NextSong, Song2 , &amp;Playing_::start_prev_song >
810 // +--------+---------+--------+---------------------------+------+
811 > {};
812 </programlisting>
813 </para>
814 <para>
815 <programlisting>typedef Song1 initial_state; </programlisting>
816 </para>
817 <para>This is about all you need to do. MSM will now automatically recognize
818 Playing as a submachine and all events handled by Playing (NextSong and
819 PreviousSong) will now be automatically forwarded to Playing whenever this
820 state is active. All other state machine features described later are also
821 available. You can even decide to use a state machine sometimes as
822 submachine or sometimes as an independent state machine.</para>
823 <para><command xml:id="limitation-submachine"/>There is, however, a limitation for submachines. If a submachine's
824 substate has an entry action which requires a special event property (like a
825 given method), the compiler will require all events entering this submachine
826 to support this property. As this is not practicable, we will need to use
827 <code>boost::enable_if</code> / <code>boost::disable_if</code> to help,
828 for example consider:</para>
829 <programlisting>// define a property for use with enable_if
830 BOOST_MPL_HAS_XXX_TRAIT_DEF(some_event_property)
831
832 // this event supports some_event_property and a corresponding required method
833 struct event1
834 {
835 // the property
836 typedef int some_event_property;
837 // the method required by this property
838 void some_property(){...}
839 };
840 // this event does not supports some_event_property
841 struct event2
842 {
843 };
844 struct some_state : public msm::front::state&lt;>
845 {
846 template &lt;class Event,class Fsm>
847 // enable this version for events supporting some_event_property
848 typename boost::enable_if&lt;typename has_some_event_property&lt;Event>::type,void>::type
849 on_entry(Event const&amp; evt,Fsm&amp; fsm)
850 {
851 evt.some_property();
852 }
853 // for events not supporting some_event_property
854 template &lt;class Event,class Fsm>
855 typename boost::disable_if&lt;typename has_some_event_property&lt;Event>::type,void>::type
856 on_entry(Event const&amp; ,Fsm&amp; )
857 { }
858 }; </programlisting>
859 <para>Now this state can be used in your submachine.</para>
860 </sect2>
861 <sect2>
862 <title>Orthogonal regions, terminate state, event deferring</title>
863 <para>It is a very common problem in many state machines to have to handle
864 errors. It usually involves defining a transition from all the states to a
865 special error state. Translation: not fun. It is also not practical to find
866 from which state the error originated. The following diagram shows an
867 example of what clearly becomes not very readable:</para>
868 <para><inlinemediaobject>
869 <imageobject>
870 <imagedata fileref="images/error_no_regions.jpg" width="60%"
871 scalefit="1"/>
872 </imageobject>
873 </inlinemediaobject></para>
874 <para>This is neither very readable nor beautiful. And we do not even have any
875 action on the transitions yet to make it even less readable.</para>
876 <para>Luckily, UML provides a helpful concept, orthogonal regions. See them as
877 lightweight state machines running at the same time inside a common state
878 machine and having the capability to influence one another. The effect is
879 that you have several active states at any time. We can therefore keep our
880 state machine from the previous example and just define a new region made of
881 two states, AllOk and ErrorMode. AllOk is most of the time active. But the
882 error_found error event makes the second region move to the new active state
883 ErrorMode. This event does not interest the main region so it will simply be
884 ignored. "<code>no_transition</code>" will be called only if no region at
885 all handles the event. Also, as UML mandates, every region gets a chance of
886 handling the event, in the order as declared by the
887 <code>initial_state</code> type.</para>
888 <para>Adding an orthogonal region is easy, one only needs to declare more states
889 in the <code>initial_state</code> typedef. So, adding a new region with
890 AllOk as the region's initial state is:</para>
891 <para>
892 <programlisting>typedef mpl::vector&lt;Empty,AllOk> initial_state;</programlisting>
893 </para>
894 <para><inlinemediaobject>
895 <imageobject>
896 <imagedata fileref="images/Orthogonal-deferred.jpg" width="60%"
897 scalefit="1"/>
898 </imageobject>
899 </inlinemediaobject></para>
900 <para>Furthermore, when you detect an error, you usually do not want events to
901 be further processed. To achieve this, we use another UML feature, terminate
902 states. When any region moves to a terminate state, the state machine
903 “terminates” (the state machine and all its states stay alive) and all
904 events are ignored. This is of course not mandatory, one can use orthogonal
905 regions without terminate states. MSM also provides a small extension to
906 UML, interrupt states. If you declare ErrorMode (or a Boost.MPL sequence of
907 events, like boost::mpl::vector&lt;ErrorMode, AnotherEvent>) as interrupt
908 state instead of terminate state, the state machine will not handle any
909 event other than the one which ends the interrupt. So it's like a terminate
910 state, with the difference that you are allowed to resume the state machine
911 when a condition (like handling of the original error) is met. </para>
912 <para><command xml:id="basic-defer"/>Last but not least, this example also shows
913 here the handling of event deferring. Let's say someone puts a disc and
914 immediately presses play. The event cannot be handled, yet you'd want it to
915 be handled at a later point and not force the user to press play again. The
916 solution is to define it as deferred in the Empty and Open states and get it
917 handled in the first state where the event is not to be deferred. It can
918 then be handled or rejected. In this example, when Stopped becomes active,
919 the event will be handled because only Empty and Open defer the
920 event.</para>
921 <para>UML defines event deferring as a state property. To accommodate this, MSM
922 lets you specify this in states by providing a <code>deferred_events</code>
923 type:</para>
924 <programlisting>struct Empty : public msm::front::state&lt;>
925 {
926 // if the play event is fired while in this state, defer it until a state
927 // handles or rejects it
928 typedef mpl::vector&lt;play> deferred_events;
929 ...
930 }; </programlisting>
931 <para>Please have a look at the <link
932 xlink:href="examples/Orthogonal-deferred.cpp">complete
933 example</link>.</para>
934 <para>While this is wanted by UML and is simple, it is not always practical
935 because one could wish to defer only in certain conditions. One could also
936 want to make this be part of a transition action with the added bonus of a
937 guard for more sophisticated behaviors. It would also be conform to the MSM
938 philosophy to get as much as possible in the transition table, where you
939 have the whole state machine structure. This is also possible but not
940 practical with this front-end so we will need to pick a different row from
941 the functor front-end. For a complete description of the <code>Row</code>
942 type, please have a look at the <command xlink:href="#functor-front-end"
943 >functor front-end.</command></para>
944 <para>First, as there is no state where MSM can automatically find out the usage
945 of this feature, we need to require deferred events capability explicitly,
946 by adding a type in the state machine definition:</para>
947 <programlisting>struct player_ : public msm::front::state_machine_def&lt;player_>
948 {
949 typedef int activate_deferred_events;
950 ...
951 }; </programlisting>
952 <para>We can now defer an event in any transition of the transition table by
953 using as action the predefined <code>msm::front::Defer</code> functor, for
954 example:</para>
955 <para>
956 <programlisting>Row &lt; Empty , play , none , Defer , none ></programlisting>
957 </para>
958 <para>This is an internal transition row(see <command
959 xlink:href="#internal-transitions">internal transitions</command>) but
960 you can ignore this for the moment. It just means that we are not leaving
961 the Empty state. What matters is that we use Defer as action. This is
962 roughly equivalent to the previous syntax but has the advantage of giving
963 you all the information in the transition table with the added power of
964 transition behavior.</para>
965 <para>The second difference is that as we now have a transition defined, this
966 transition can play in the resolution of <command
967 xlink:href="#transition-conflict">transition conflicts</command>. For
968 example, we could model an "if (condition2) move to Playing else if
969 (condition1) defer play event":</para>
970 <para>
971 <programlisting>Row &lt; Empty , play , none , Defer , condition1 >,
972 g_row &lt; Empty , play , Playing , &amp;player_::condition2 ></programlisting>
973 </para>
974 <para>Please have a look at <link xlink:href="examples/Orthogonal-deferred2.cpp"
975 >this possible implementation</link>.</para>
976 </sect2>
977 <sect2>
978 <title>History</title>
979 <para>UML defines two types of history, Shallow History and Deep History. In the
980 previous examples, if the player was playing the second song and the user
981 pressed pause, leaving Playing, at the next press on the play button, the
982 Playing state would become active and the first song would play again. Soon
983 would the first client complaints follow. They'd of course demand, that if
984 the player was paused, then it should remember which song was playing. But
985 it the player was stopped, then it should restart from the first song. How
986 can it be done? Of course, you could add a bit of programming logic and
987 generate extra events to make the second song start if coming from Pause.
988 Something like: </para>
989 <para>
990 <programlisting>if (Event == end_pause)
991 {
992 for (int i=0;i&lt; song number;++i) {player.process_event(NextSong()); }
993 } </programlisting>
994 </para>
995 <para>Not much to like in this example, isn't it? To solve this problem, you
996 define what is called a shallow or a deep history. A shallow history
997 reactivates the last active substate of a submachine when this submachine
998 becomes active again. The deep history does the same recursively, so if this
999 last active substate of the submachine was itself a submachine, its last
1000 active substate would become active and this will continue recursively until
1001 an active state is a normal state. For example, let us have a look at the
1002 following UML diagram: </para>
1003 <para><inlinemediaobject>
1004 <imageobject>
1005 <imagedata fileref="images/HistoryTutorial.jpg" width="60%"
1006 scalefit="1"/>
1007 </imageobject>
1008 </inlinemediaobject></para>
1009 <para>Notice that the main difference compared to previous diagrams is that the
1010 initial state is gone and replaced by a History symbol (the H inside a
1011 circle).</para>
1012 <para>As explained in the <command xlink:href="#uml-history">small UML
1013 tutorial</command>, History is a good concept with a not completely
1014 satisfying specification. MSM kept the concept but not the specification and
1015 goes another way by making this a policy and you can add your own history
1016 types (the <link xlink:href="#history-interface">reference</link> explains
1017 what needs to be done). Furthermore, History is a backend policy. This
1018 allows you to reuse the same state machine definition with different history
1019 policies in different contexts.</para>
1020 <para>Concretely, your frontend stays unchanged:</para>
1021 <para>
1022 <programlisting>struct Playing_ : public msm::front::state_machine_def&lt;Playing_></programlisting>
1023 </para>
1024 <para>You then add the policy to the backend as second parameter:</para>
1025 <para>
1026 <programlisting>typedef msm::back::state_machine&lt;Playing_,
1027 msm::back::ShallowHistory&lt;mpl::vector&lt;end_pause> > > Playing;</programlisting>
1028 </para>
1029 <para>This states that a shallow history must be activated if the Playing state
1030 machine gets activated by the end_pause event and only this one (or any
1031 other event added to the mpl::vector). If the state machine was in the
1032 Stopped state and the event play was generated, the history would not be
1033 activated and the normal initial state would become active. By default,
1034 history is disabled. For your convenience the library provides in addition
1035 to ShallowHistory a non-UML standard AlwaysHistory policy (likely to be your
1036 main choice) which always activates history, whatever event triggers the
1037 submachine activation. Deep history is not available as a policy (but could
1038 be added). The reason is that it would conflict with policies which
1039 submachines could define. Of course, if for example, Song1 were a state
1040 machine itself, it could use the ShallowHistory policy itself thus creating
1041 Deep History for itself. An <link xlink:href="examples/History.cpp"
1042 >example</link> is also provided.</para>
1043 </sect2>
1044 <sect2>
1045 <title>Completion (anonymous) transitions</title>
1046 <para><command xml:id="anonymous-transitions"/>The following diagram shows an
1047 example making use of this feature:</para>
1048 <para><inlinemediaobject>
1049 <imageobject>
1050 <imagedata fileref="images/Anonymous.jpg" width="60%" scalefit="1"/>
1051 </imageobject>
1052 </inlinemediaobject></para>
1053 <para>Anonymous transitions are transitions without a named event. This means
1054 that the transition automatically fires when the predecessor state is
1055 entered (to be exact, after the entry action). Otherwise it is a normal
1056 transition with actions and guards. Why would you need something like that?
1057 A possible case would be if a part of your state machine implements some
1058 algorithm, where states are steps of the algorithm implementation. Then,
1059 using several anonymous transitions with different guard conditions, you are
1060 actually implementing some if/else statement. Another possible use would be
1061 a real-time system called at regular intervals and always doing the same
1062 thing, meaning implementing the same algorithm. The advantage is that once
1063 you know how long a transition takes to execute on the system, by
1064 calculating the longest path (the number of transitions from start to end),
1065 you can pretty much know how long your algorithm will take in the worst
1066 case, which in turns tells you how much of a time frame you are to request
1067 from a scheduler. </para>
1068 <para>If you are using Executable UML (a good book describing it is "Executable
1069 UML, a foundation for Model-Driven Architecture"), you will notice that it
1070 is common for a state machine to generate an event to itself only to force
1071 leaving a state. Anonymous transitions free you from this constraint.</para>
1072 <para>If you do not use this feature in a concrete state machine, MSM will
1073 deactivate it and you will not pay for it. If you use it, there is however a
1074 small performance penalty as MSM will try to fire a compound event (the
1075 other UML name for anonymous transitions) after every taken transition. This
1076 will therefore double the event processing cost, which is not as bad as it
1077 sounds as MSM’s execution speed is very high anyway.</para>
1078 <para>To define such a transition, use “none” as event in the transition table,
1079 for example:</para>
1080 <para>
1081 <programlisting>row &lt; State3 , none , State4 , &amp;p::State3ToState4 , &amp;p::always_true ></programlisting>
1082 </para>
1083 <para><link xlink:href="examples/AnonymousTutorial.cpp">An implementation</link>
1084 of the state machine diagram is also provided.</para>
1085 </sect2>
1086 <sect2>
1087 <title><command xml:id="internal-transitions"/>Internal transitions</title>
1088 <para>Internal transitions are transitions executing in the scope of the active
1089 state, a simple state or a submachine. One can see them as a self-transition
1090 of this state, without an entry or exit action called. This is useful when
1091 all you want is to execute some code for a given event in a given
1092 state.</para>
1093 <para>Internal transitions are specified as having a higher priority than normal
1094 transitions. While it makes sense for a submachine with exit points, it is
1095 surprising for a simple state. MSM lets you define the transition priority
1096 by setting the transition’s position inside the transition table (see
1097 <command xlink:href="#run-to-completion">internals</command> ). The
1098 difference between "normal" and internal transitions is that internal
1099 transitions have no target state, therefore we need new row types. We had
1100 a_row, g_row, _row and row, we now add a_irow, g_irow, _irow and irow which
1101 are like normal transitions but define no target state. For, example an
1102 internal transition with a guard condition could be:</para>
1103 <para>
1104 <programlisting>g_irow &lt; Empty /*state*/,cd_detected/*event*/,&amp;p::internal_guard/* guard */></programlisting>
1105 </para>
1106 <para>These new row types can be placed anywhere in the transition table so that
1107 you can still have your state machine structure grouped together. The only
1108 difference of behavior with the UML standard is the missing notion of higher
1109 priority for internal transitions. Please have a look at <link
1110 xlink:href="examples/SimpleTutorialInternal.cpp">the
1111 example</link>.</para>
1112 <para>It is also possible to do it the UML-conform way by declaring a transition
1113 table called <code>internal transition_table</code> inside the state itself
1114 and using internal row types. For example:</para>
1115 <programlisting>struct Empty : public msm::front::state&lt;>
1116 {
1117 struct internal_transition_table : mpl::vector&lt;
1118 a_internal &lt; cd_detected , Empty, &amp;Empty::internal_action >
1119 > {};
1120 };</programlisting>
1121 <para>This declares an internal transition table called
1122 internal_transition_table and reacting on the event cd_detected by calling
1123 internal_action on Empty. Let us note a few points:<itemizedlist>
1124 <listitem>
1125 <para>internal tables are NOT called transition_table but
1126 internal_transition_table</para>
1127 </listitem>
1128 <listitem>
1129 <para>they use different but similar row types: a_internal,
1130 g_internal, _internal and internal.</para>
1131 </listitem>
1132 <listitem>
1133 <para>These types take as first template argument the triggering
1134 event and then the action and guard method. Note that the only
1135 real difference to classical rows is the extra argument before
1136 the function pointer. This is the type on which the function
1137 will be called.</para>
1138 </listitem>
1139 <listitem>
1140 <para>This also allows you, if you wish, to use actions and guards
1141 from another state of the state machine or in the state machine
1142 itself.</para>
1143 </listitem>
1144 <listitem>
1145 <para>submachines can have an internal transition table and a
1146 classical transition table.</para>
1147 </listitem>
1148 </itemizedlist></para>
1149 <para>The <link xlink:href="examples/TestInternal.cpp">following example</link>
1150 makes use of an a_internal. It also uses functor-based internal transitions
1151 which will be explained in <command
1152 xlink:href="#functor-internal-transitions">the functor
1153 front-end</command>, please ignore them for the moment. Also note that
1154 the state-defined internal transitions, having the highest priority (as
1155 mandated by the UML standard), are tried before those defined inside the
1156 state machine transition table.</para>
1157 <para>Which method should you use? It depends on what you need:<itemizedlist>
1158 <listitem>
1159 <para>the first version (using irow) is simpler and likely to
1160 compile faster. It also lets you choose the priority of your
1161 internal transition.</para>
1162 </listitem>
1163 <listitem>
1164 <para>the second version is more logical from a UML perspective and
1165 lets you make states more useful and reusable. It also allows
1166 you to call actions and guards on any state of the state
1167 machine.</para>
1168 </listitem>
1169 </itemizedlist>
1170 <command xml:id="internal-transitions-note"/><emphasis role="underline"
1171 ><emphasis role="bold">Note</emphasis></emphasis>: There is an added
1172 possibility coming from this feature. The
1173 <code>internal_transition_table</code> transitions being added directly
1174 inside the main state machine's transition table, it is possible, if it is
1175 more to your state, to distribute your state machine definition a bit like
1176 Boost.Statechart, leaving to the state machine itself the only task of
1177 declaring the states it wants to use using the
1178 <code>explicit_creation</code> type definition. While this is not the
1179 author's favorite way, it is still possible. A simplified example using only
1180 two states will show this possibility:<itemizedlist>
1181 <listitem>
1182 <para><link
1183 xlink:href="examples/distributed_table/DistributedTable.cpp"
1184 >state machine definition</link></para>
1185 </listitem>
1186 <listitem>
1187 <para>Empty <link xlink:href="examples/distributed_table/Empty.hpp"
1188 >header</link> and <link
1189 xlink:href="examples/distributed_table/Empty.cpp"
1190 >cpp</link></para>
1191 </listitem>
1192 <listitem>
1193 <para>Open <link xlink:href="examples/distributed_table/Open.hpp"
1194 >header</link> and <link
1195 xlink:href="examples/distributed_table/Open.cpp"
1196 >cpp</link></para>
1197 </listitem>
1198 <listitem>
1199 <para><link xlink:href="examples/distributed_table/Events.hpp"
1200 >events definition</link></para>
1201 </listitem>
1202 </itemizedlist></para>
1203 <para>There is an added bonus offered for submachines, which can have both the
1204 standard transition_table and an internal_transition_table (which has a
1205 higher priority). This makes it easier if you decide to make a full
1206 submachine from a state. It is also slightly faster than the standard
1207 alternative, adding orthogonal regions, because event dispatching will, if
1208 accepted by the internal table, not continue to the subregions. This gives
1209 you a O(1) dispatch instead of O(number of regions). While the example is
1210 with eUML, the same is also possible with any front-end.</para>
1211 </sect2>
1212 <sect2>
1213 <title><command xml:id="basic-row2"/>more row types</title>
1214 <para>It is also possible to write transitions using actions and guards not just
1215 from the state machine but also from its contained states. In this case, one
1216 must specify not just a method pointer but also the object on which to call
1217 it. This transition row is called, not very originally, <code>row2</code>.
1218 They come, like normal transitions in four flavors: <code>a_row2, g_row2,
1219 _row2 and row2</code>. For example, a transition calling an action from
1220 the state Empty could be:</para>
1221 <para>
1222 <programlisting>a_row2&lt;Stopped,open_close,Open,Empty
1223 /*action source*/,&amp;Empty::open_drawer/*action*/></programlisting>
1224 </para>
1225 <para>The same capabilities are also available for internal transitions so that
1226 we have: <code>a_irow2, g_irow2, _irow2 and row2</code>. For transitions
1227 defined as part of the <code>internal_transition_table</code>, you can use
1228 the <command xlink:href="#internal-transitions">a_internal, g_internal,
1229 _internal, internal</command> row types from the previous
1230 sections.</para>
1231 <para>These row types allow us to distribute the state machine code among
1232 states, making them reusable and more useful. Using transition tables inside
1233 states also contributes to this possibility. An <link
1234 xlink:href="examples/SimpleTutorial2.cpp">example</link> of these new
1235 rows is also provided.</para>
1236 </sect2>
1237 <sect2>
1238 <title>Explicit entry / entry and exit pseudo-state / fork</title>
1239 <para>MSM (almost) fully supports these features, described in the <command
1240 xlink:href="#uml-history">small UML tutorial</command>. Almost because
1241 there are currently two limitations: <itemizedlist>
1242 <listitem>
1243 <para>it is only possible to explicitly enter a sub- state of the
1244 target but not a sub-sub state.</para>
1245 </listitem>
1246 <listitem>
1247 <para>it is not possible to explicitly exit. Exit points must be
1248 used.</para>
1249 </listitem>
1250 </itemizedlist></para>
1251 <para>Let us see a concrete example:</para>
1252 <para><inlinemediaobject>
1253 <imageobject>
1254 <imagedata fileref="images/entrytutorial.jpg" width="60%"
1255 scalefit="1"/>
1256 </imageobject>
1257 </inlinemediaobject></para>
1258 <para>We find in this diagram:<itemizedlist>
1259 <listitem>
1260 <para>A “normal” activation of SubFsm2, triggered by event1. In each
1261 region, the initial state is activated, i.e. SubState1 and
1262 SubState1b.</para>
1263 </listitem>
1264 <listitem>
1265 <para>An explicit entry into SubFsm2::SubState2 for region “1” with
1266 event2 as trigger, meaning that in region “2” the initial state,
1267 SubState1b, activated.</para>
1268 </listitem>
1269 <listitem>
1270 <para>A fork into regions “1” and “2” to the explicit entries
1271 SubState2 and SubState2b, triggered by event3. Both states
1272 become active so no region is default activated (if we had a
1273 third one, it would be).</para>
1274 </listitem>
1275 <listitem>
1276 <para>A connection of two transitions through an entry pseudo state,
1277 SubFsm2::PseudoEntry1, triggered by event4 and triggering also
1278 the second transition on the same event (both transitions must
1279 be triggered by the same event). Region “2” is default-activated
1280 and SubState1b becomes active.</para>
1281 </listitem>
1282 <listitem>
1283 <para>An exit from SubFsm2 using an exit pseudo-state, PseudoExit1,
1284 triggered by event5 and connecting two transitions using the
1285 same event. Again, the event is forwarded to the second
1286 transition and both regions are exited, as SubFsm2 becomes
1287 inactive. Note that if no transition is defined from
1288 PseudoExit1, an error (as defined in the UML standard) will be
1289 detected and no_transition called.</para>
1290 </listitem>
1291 </itemizedlist></para>
1292 <para>The example is also <link xlink:href="examples/DirectEntryTutorial.cpp"
1293 >fully implemented</link>.</para>
1294 <para>This sounds complicated but the syntax is simple.</para>
1295 <sect3>
1296 <title>Explicit entry</title>
1297 <para>First, to define that a state is an explicit entry, you have to make
1298 it a state and mark it as explicit, giving as template parameters the
1299 region id (the region id starts with 0 and corresponds to the first
1300 initial state of the initial_state type sequence).</para>
1301 <para>
1302 <programlisting>struct SubFsm2_ : public msm::front::state_machine_def&lt;SubFsm2_>
1303 {
1304 struct SubState2 : public msm::front::state&lt;> ,
1305 public msm::front::explicit_entry&lt;0>
1306 {...};
1307 ...
1308 };</programlisting>
1309 </para>
1310 <para>And define the submachine as:</para>
1311 <para>
1312 <programlisting>typedef msm::back::state_machine&lt;SubFsm2_> SubFsm2;</programlisting>
1313 </para>
1314 <para>You can then use it as target in a transition with State1 as
1315 source:</para>
1316 <para>
1317 <programlisting>_row &lt; State1, Event2, SubFsm2::direct&lt; SubFsm2_::SubState2> > //SubFsm2_::SubState2: complete name of SubState2 (defined within SubFsm2_)</programlisting>
1318 </para>
1319 <para>The syntax deserves some explanation. SubFsm2_ is a front end.
1320 SubState2 is a nested state, therefore the SubFsm2_::SubState2 syntax.
1321 The containing machine (containing State1 and SubFsm2) refers to the
1322 backend instance (SubFsm2). SubFsm2::direct states that an explicit
1323 entry is desired.</para>
1324 <para><command xml:id="explicit-entry-no-region-id"/>Thanks to the <command xlink:href="#backend-compile-time-analysis"
1325 >mpl_graph</command> library you can also omit to provide the region
1326 index and let MSM find out for you. The are however two points to note:<itemizedlist>
1327 <listitem>
1328 <para>MSM can only find out the region index if the explicit
1329 entry state is somehow connected to an initial state through
1330 a transition, no matter the direction.</para>
1331 </listitem>
1332 <listitem>
1333 <para>There is a compile-time cost for this feature.</para>
1334 </listitem>
1335 </itemizedlist></para>
1336 <para><emphasis role="underline">Note (also valid for forks)</emphasis>: in
1337 order to make compile time more bearable for the more standard cases,
1338 and unlike initial states, explicit entry states which are also not
1339 found in the transition table of the entered submachine (a rare case) do
1340 NOT get automatically created. To explicitly create such states, you
1341 need to add in the state machine containing the explicit states a simple
1342 typedef giving a sequence of states to be explicitly created
1343 like:</para>
1344 <para>
1345 <programlisting>typedef mpl::vector&lt;SubState2,SubState2b> explicit_creation;</programlisting>
1346 </para>
1347 <para><emphasis role="underline">Note (also valid for forks)</emphasis>: At
1348 the moment, it is not possible to use a submachine as the target of an
1349 explicit entry. Please use entry pseudo states for an almost identical
1350 effect.</para>
1351 </sect3>
1352 <sect3>
1353 <title>Fork</title>
1354 <para>Need a fork instead of an explicit entry? As a fork is an explicit
1355 entry into states of different regions, we do not change the state
1356 definition compared to the explicit entry and specify as target a list
1357 of explicit entry states:</para>
1358 <para>
1359 <programlisting>_row &lt; State1, Event3,
1360 mpl::vector&lt;SubFsm2::direct&lt;SubFsm2_::SubState2>,
1361 SubFsm2::direct &lt;SubFsm2_::SubState2b>
1362 ></programlisting>
1363 </para>
1364 <para>With SubState2 defined as before and SubState2b defined as being in
1365 the second region (Caution: MSM does not check that the region is
1366 correct):</para>
1367 <para>
1368 <programlisting>struct SubState2b : public msm::front::state&lt;> ,
1369 public msm::front::explicit_entry&lt;1></programlisting>
1370 </para>
1371 </sect3>
1372 <sect3>
1373 <title>Entry pseudo states</title>
1374 <para> To define an entry pseudo state, you need derive from the
1375 corresponding class and give the region id:</para>
1376 <para>
1377 <programlisting>struct PseudoEntry1 : public msm::front::entry_pseudo_state&lt;0></programlisting>
1378 </para>
1379 <para>And add the corresponding transition in the top-level state machine's
1380 transition table:</para>
1381 <para>
1382 <programlisting>_row &lt; State1, Event4, SubFsm2::entry_pt&lt;SubFsm2_::PseudoEntry1> ></programlisting>
1383 </para>
1384 <para>And another in the SubFsm2_ submachine definition (remember that UML
1385 defines an entry point as a connection between two transitions), for
1386 example this time with an action method:</para>
1387 <para>
1388 <programlisting>_row &lt; PseudoEntry1, Event4, SubState3,&amp;SubFsm2_::entry_action ></programlisting>
1389 </para>
1390 </sect3>
1391 <sect3>
1392 <title> Exit pseudo states </title>
1393 <para>And finally, exit pseudo states are to be used almost the same way,
1394 but defined differently: it takes as template argument the event to be
1395 forwarded (no region id is necessary):</para>
1396 <para>
1397 <programlisting>struct PseudoExit1 : public exit_pseudo_state&lt;event6></programlisting>
1398 </para>
1399 <para>And you need, like for entry pseudo states, two transitions, one in
1400 the submachine:</para>
1401 <para>
1402 <programlisting>_row &lt; SubState3, Event5, PseudoExit1 ></programlisting>
1403 </para>
1404 <para>And one in the containing state machine:</para>
1405 <para>
1406 <programlisting>_row &lt; SubFsm2::exit_pt&lt;SubFsm2_::PseudoExit1>, Event6,State2 ></programlisting>
1407 </para>
1408 <para><emphasis role="underline">Important note 1:</emphasis> UML defines
1409 transiting to an entry pseudo state and having either no second
1410 transition or one with a guard as an error but defines no error
1411 handling. MSM will tolerate this behavior; the entry pseudo state will
1412 simply be the newly active state.</para>
1413 <para><emphasis role="underline">Important note 2</emphasis>: UML defines
1414 transiting to an exit pseudo state and having no second transition as an
1415 error, and also defines no error handling. Therefore, it was decided to
1416 implement exit pseudo state as terminate states and the containing
1417 composite not properly exited will stay terminated as it was technically
1418 “exited”.</para>
1419 <para><emphasis role="underline">Important note 3:</emphasis> UML states
1420 that for the exit point, the same event must be used in both
1421 transitions. MSM relaxes this rule and only wants the event on the
1422 inside transition to be convertible to the one of the outside
1423 transition. In our case, event6 is convertible from event5. Notice that
1424 the forwarded event must be named in the exit point definition. For
1425 example, we could define event6 as simply as:</para>
1426 <para>
1427 <programlisting>struct event
1428 {
1429 event(){}
1430 template &lt;class Event>
1431 event(Event const&amp;){}
1432 }; //convertible from any event</programlisting>
1433 <emphasis role="underline">Note</emphasis>: There is a current
1434 limitation if you need not only convert but also get some data from the
1435 original event. Consider:</para>
1436 <programlisting>struct event1
1437 {
1438 event1(int val_):val(val_) {}
1439 int val;
1440 }; // forwarded from exit point
1441 struct event2
1442 {
1443 template &lt;class Event>
1444 event2(Event const&amp; e):val(e.val){} // compiler will complain about another event not having any val
1445 int val;
1446 }; // what the higher-level fsm wants to get</programlisting>
1447 <para>The solution is to provide two constructors:</para>
1448 <programlisting>struct event2
1449 {
1450 template &lt;class Event>
1451 event2(Event const&amp; ):val(0){} // will not be used
1452 event2(event1 const&amp; e)):val(e.val){} // the conversion constructor
1453 int val;
1454 }; // what the higher-level fsm wants to get</programlisting>
1455 </sect3>
1456 </sect2>
1457 <sect2>
1458 <title>Flags</title>
1459 <para>This <link xlink:href="examples/Flags.cpp">tutorial</link> is devoted to a
1460 concept not defined in UML: flags. It has been added into MSM after proving
1461 itself useful on many occasions. Please, do not be frightened as we are not
1462 talking about ugly shortcuts made of an improbable collusion of
1463 Booleans.</para>
1464 <para>If you look into the Boost.Statechart documentation you'll find this
1465 code:</para>
1466 <programlisting>if ( ( state_downcast&lt; const NumLockOff * >() != 0 ) &amp;&amp;
1467 ( state_downcast&lt; const CapsLockOff * >() != 0 ) &amp;&amp;
1468 ( state_downcast&lt; const ScrollLockOff * >() != 0 ) )
1469 </programlisting>
1470 <para>While correct and found in many UML books, this can be error-prone and a
1471 potential time-bomb when your state machine grows and you add new states or
1472 orthogonal regions.</para>
1473 <para>And most of all, it hides the real question, which would be “does my state
1474 machine's current state define a special property”? In this special case
1475 “are my keys in a lock state”? So let's apply the Fundamental Theorem of
1476 Software Engineering and move one level of abstraction higher.</para>
1477 <para>In our player example, let's say we need to know if the player has a
1478 loaded CD. We could do the same:</para>
1479 <programlisting>if ( ( state_downcast&lt; const Stopped * >() != 0 ) &amp;&amp;
1480 ( state_downcast&lt; const Open * >() != 0 ) &amp;&amp;
1481 ( state_downcast&lt; const Paused * >() != 0 ) &amp;&amp;
1482 ( state_downcast&lt; const Playing * >() != 0 )) </programlisting>
1483 <para>Or flag these 4 states as CDLoaded-able. You add a flag_list type into
1484 each flagged state:</para>
1485 <para>
1486 <programlisting>typedef mpl::vector1&lt;CDLoaded> flag_list;</programlisting>
1487 </para>
1488 <para>You can even define a list of flags, for example in Playing:</para>
1489 <para>
1490 <programlisting>typedef mpl::vector2&lt;PlayingPaused,CDLoaded> flag_list;</programlisting>
1491 </para>
1492 <para>This means that Playing supports both properties. To check if your player
1493 has a loaded CD, check if your flag is active in the current state:</para>
1494 <para>
1495 <programlisting>player p; if (p.is_flag_active&lt;CDLoaded>()) ... </programlisting>
1496 </para>
1497 <para>And what if you have orthogonal regions? How to decide if a state machine
1498 is in a flagged state? By default, you keep the same code and the current
1499 states will be OR'ed, meaning if one of the active states has the flag, then
1500 is_flag_active returns true. Of course, in some cases, you might want that
1501 all of the active states are flagged for the state to be active. You can
1502 also AND the active states:</para>
1503 <para>
1504 <programlisting>if (p.is_flag_active&lt;CDLoaded,player::Flag_AND>()) ...</programlisting>
1505 </para>
1506 <para> Note. Due to arcane C++ rules, when called inside an action, the correct
1507 call is:
1508 <programlisting>if (p.<emphasis role="bold">template</emphasis> is_flag_active&lt;CDLoaded>()) ...</programlisting>
1509 </para>
1510 <para>The following diagram displays the flag situation in the tutorial.</para>
1511 <para><inlinemediaobject>
1512 <imageobject>
1513 <imagedata fileref="images/FlagsTutorial.jpg" width="60%"
1514 scalefit="1"/>
1515 </imageobject>
1516 </inlinemediaobject></para>
1517 </sect2>
1518 <sect2>
1519 <title><command xml:id="event-hierarchy"/>Event Hierarchy</title>
1520 <para>There are cases where one needs transitions based on categories of events.
1521 An example is text parsing. Let's say you want to parse a string and use a
1522 state machine to manage your parsing state. You want to parse 4 digits and
1523 decide to use a state for every matched digit. Your state machine could look
1524 like:</para>
1525 <para><inlinemediaobject>
1526 <imageobject>
1527 <imagedata fileref="images/ParsingDigits.jpg" width="30%"
1528 scalefit="1"/>
1529 </imageobject>
1530 </inlinemediaobject></para>
1531 <para>But how to detect the digit event? We would like to avoid defining 10
1532 transitions on char_0, char_1... between two states as it would force us to
1533 write 4 x 10 transitions and the compile-time would suffer. To solve this
1534 problem, MSM supports the triggering of a transition on a subclass event.
1535 For example, if we define digits as: </para>
1536 <programlisting>struct digit {};
1537 struct char_0 : public digit {}; </programlisting>
1538 <para>And to the same for other digits, we can now fire char_0, char_1 events
1539 and this will cause a transition with "digit" as trigger to be taken.</para>
1540 <para>An <link xlink:href="examples/ParsingDigits.cpp">example</link> with
1541 performance measurement, taken from the documentation of Boost.Xpressive
1542 illustrates this example. You might notice that the performance is actually
1543 very good (in this case even better).</para>
1544 </sect2>
1545 <sect2>
1546 <title>Customizing a state machine / Getting more speed</title>
1547 <para>MSM is offering many UML features at a high-speed, but sometimes, you just
1548 need more speed and are ready to give up some features in exchange. A
1549 process_event is handling several tasks: <itemizedlist>
1550 <listitem>
1551 <para>checking for terminate/interrupt states</para>
1552 </listitem>
1553 <listitem>
1554 <para>handling the message queue (for entry/exit/transition actions
1555 generating themselves events)</para>
1556 </listitem>
1557 <listitem>
1558 <para>handling deferred events</para>
1559 </listitem>
1560 <listitem>
1561 <para>catching exceptions (or not)</para>
1562 </listitem>
1563 <listitem>
1564 <para>handling the state switching and action calls</para>
1565 </listitem>
1566 </itemizedlist>Of these tasks, only the last one is absolutely necessary to
1567 a state machine (its core job), the other ones are nice-to-haves which cost
1568 CPU time. In many cases, it is not so important, but in embedded systems,
1569 this can lead to ad-hoc state machine implementations. MSM detects by itself
1570 if a concrete state machine makes use of terminate/interrupt states and
1571 deferred events and deactivates them if not used. For the other two, if you
1572 do not need them, you need to help by indicating it in your implementation.
1573 This is done with two simple typedefs:<itemizedlist>
1574 <listitem>
1575 <para><code>no_exception_thrown</code> indicates that behaviors will
1576 never throw and MSM does not need to catch anything</para>
1577 </listitem>
1578 <listitem>
1579 <para><code>no_message_queue</code> indicates that no action will
1580 itself generate a new event and MSM can save us the message
1581 queue.</para>
1582 </listitem>
1583 </itemizedlist>The third configuration possibility, explained <link
1584 xlink:href="#basic-defer">here</link>, is to manually activate deferred
1585 events, using <code>activate_deferred_events</code>. For example, the
1586 following state machine sets all three configuration types:</para>
1587 <programlisting>struct player_ : public msm::front::state_machine_def&lt;player_>
1588 {
1589 // no need for exception handling or message queue
1590 typedef int no_exception_thrown;
1591 typedef int no_message_queue;
1592 // also manually enable deferred events
1593 typedef int activate_deferred_events
1594 ...// rest of implementation
1595 };</programlisting>
1596 <para><emphasis role="underline">Important note</emphasis>: As exit pseudo
1597 states are using the message queue to forward events out of a submachine,
1598 the <code>no_message_queue</code> option cannot be used with state machines
1599 containing an exit pseudo state.</para>
1600 </sect2>
1601 <sect2>
1602 <title>Choosing the initial event</title>
1603 <para>A state machine is started using the <code>start</code> method. This
1604 causes the initial state's entry behavior to be executed. Like every entry
1605 behavior, it becomes as parameter the event causing the state to be entered.
1606 But when the machine starts, there was no event triggered. In this case, MSM
1607 sends <code>msm::back::state_machine&lt;...>::InitEvent</code>, which might
1608 not be the default you'd want. For this special case, MSM provides a
1609 configuration mechanism in the form of a typedef. If the state machine's
1610 front-end definition provides an initial_event typedef set to another event,
1611 this event will be used. For example:</para>
1612 <programlisting>struct my_initial_event{};
1613 struct player_ : public msm::front::state_machine_def&lt;player_>{
1614 ...
1615 typedef my_initial_event initial_event;
1616 };</programlisting>
1617 </sect2>
1618 <sect2>
1619 <title> Containing state machine (deprecated)</title>
1620 <para>This feature is still supported in MSM for backward compatibility but made
1621 obsolete by the fact that every guard/action/entry action/exit action get
1622 the state machine passed as argument and might be removed at a later
1623 time.</para>
1624 <para>All of the states defined in the state machine are created upon state
1625 machine construction. This has the huge advantage of a reduced syntactic
1626 noise. The cost is a small loss of control for the user on the state
1627 creation and access. But sometimes you needed a way for a state to get
1628 access to its containing state machine. Basically, a state needs to change
1629 its declaration to:</para>
1630 <programlisting>struct Stopped : public msm::front::state&lt;sm_ptr></programlisting>
1631 <para>And to provide a set_sm_ptr function: <code>void set_sm_ptr(player*
1632 pl)</code></para>
1633 <para>to get a pointer to the containing state machine. The same applies to
1634 terminate_state / interrupt_state and entry_pseudo_state /
1635 exit_pseudo_state. </para>
1636 </sect2>
1637 </sect1>
1638 <sect1>
1639 <title><command xml:id="functor-front-end"/>Functor front-end</title>
1640 <para>The functor front-end is the preferred front-end at the moment. It is more
1641 powerful than the standard front-end and has a more readable transition table.
1642 It also makes it easier to reuse parts of state machines. Like <command
1643 xlink:href="#eUML-front-end">eUML</command>, it also comes with a good deal
1644 of predefined actions. Actually, eUML generates a functor front-end through
1645 Boost.Typeof and Boost.Proto so both offer the same functionality.</para>
1646 <para>The rows which MSM offered in the previous front-end come in different
1647 flavors. We saw the a_row, g_row, _row, row, not counting internal rows. This is
1648 already much to know, so why define new rows? These types have some
1649 disadvantages: <itemizedlist>
1650 <listitem>
1651 <para>They are more typing and information than we would wish. This
1652 means syntactic noise and more to learn.</para>
1653 </listitem>
1654 <listitem>
1655 <para>Function pointers are weird in C++.</para>
1656 </listitem>
1657 <listitem>
1658 <para>The action/guard signature is limited and does not allow for more
1659 variations of parameters (source state, target state, current state
1660 machine, etc.)</para>
1661 </listitem>
1662 <listitem>
1663 <para>It is not easy to reuse action code from a state machine to
1664 another.</para>
1665 </listitem>
1666 </itemizedlist></para>
1667 <sect2>
1668 <title> Transition table </title>
1669 <para>We can change the definition of the simple tutorial's transition table
1670 to:</para>
1671 <programlisting>
1672 struct transition_table : mpl::vector&lt;
1673 // Start Event Target Action Guard
1674 // +---------+------------+-----------+---------------------------+----------------------------+
1675 Row &lt; Stopped , play , Playing , start_playback , none >,
1676 Row &lt; Stopped , open_close , Open , open_drawer , none >,
1677 Row &lt; Stopped , stop , Stopped , none , none >,
1678 // +---------+------------+-----------+---------------------------+----------------------------+
1679 Row &lt; Open , open_close , Empty , close_drawer , none >,
1680 // +---------+------------+-----------+---------------------------+----------------------------+
1681 Row &lt; Empty , open_close , Open , open_drawer , none >,
1682 Row &lt; Empty , cd_detected, Stopped , store_cd_info , good_disk_format >,
1683 g_row&lt; Empty , cd_detected, Playing , &amp;player_::store_cd_info , &amp;player_::auto_start >,
1684 // +---------+------------+-----------+---------------------------+----------------------------+
1685 Row &lt; Playing , stop , Stopped , stop_playback , none >,
1686 Row &lt; Playing , pause , Paused , pause_playback , none >,
1687 Row &lt; Playing , open_close , Open , stop_and_open , none >,
1688 // +---------+------------+-----------+---------------------------+----------------------------+
1689 Row &lt; Paused , end_pause , Playing , resume_playback , none >,
1690 Row &lt; Paused , stop , Stopped , stop_playback , none >,
1691 Row &lt; Paused , open_close , Open , stop_and_open , none >
1692 // +---------+------------+-----------+---------------------------+----------------------------+
1693 > {};
1694 </programlisting>
1695 <para>Transitions are now of type "Row" with exactly 5 template arguments:
1696 source state, event, target state, action and guard. Wherever there is
1697 nothing (for example actions and guards), write "none". Actions and guards
1698 are no more methods but functors getting as arguments the detected event,
1699 the state machine, source and target state:</para>
1700 <programlisting>struct store_cd_info
1701 {
1702 template &lt;class Fsm,class Evt,class SourceState,class TargetState>
1703 void operator()(Evt const&amp;, Fsm&amp; fsm, SourceState&amp;,TargetState&amp; )
1704 {
1705 cout &lt;&lt; "player::store_cd_info" &lt;&lt; endl;
1706 fsm.process_event(play());
1707 }
1708 }; </programlisting>
1709 <para>The advantage of functors compared to functions are that functors are
1710 generic and reusable. They also allow passing more parameters than just
1711 events. The guard functors are the same but have an operator() returning a
1712 bool.</para>
1713 <para>It is also possible to mix rows from different front-ends. To show this, a
1714 g_row has been left in the transition table. <emphasis role="underline"
1715 >Note:</emphasis> in case the action functor is used in the transition
1716 table of a state machine contained inside a top-level state machine, the
1717 “fsm” parameter refers to the lowest-level state machine (referencing this
1718 action), not the top-level one.</para>
1719 <para>To illustrate the reusable point, MSM comes with a whole set of predefined
1720 functors. Please refer to eUML for the <link xlink:href="#Reference-begin"
1721 >full list</link>. For example, we are now going to replace the first
1722 action by an action sequence and the guard by a more complex functor.</para>
1723 <para>We decide we now want to execute two actions in the first transition
1724 (Stopped -> Playing). We only need to change the action start_playback to
1725 <programlisting>ActionSequence_&lt; mpl::vector&lt;some_action, start_playback> ></programlisting>and
1726 now will execute some_action and start_playback every time the transition is
1727 taken. ActionSequence_ is a functor calling each action of the mpl::vector
1728 in sequence.</para>
1729 <para>We also want to replace good_disk_format by a condition of the type:
1730 “good_disk_format &amp;&amp; (some_condition || some_other_condition)”. We
1731 can achieve this using And_ and Or_ functors:
1732 <programlisting>And_&lt;good_disk_format,Or_&lt; some_condition , some_other_condition> ></programlisting>It
1733 even starts looking like functional programming. MSM ships with functors for
1734 operators, state machine usage, STL algorithms or container methods.</para>
1735 </sect2>
1736 <sect2>
1737 <title>Defining states with entry/exit actions</title>
1738 <para>You probably noticed that we just showed a different transition table and
1739 that we even mixed rows from different front-ends. This means that you can
1740 do this and leave the definitions for states unchanged. Most examples are
1741 doing this as it is the simplest solution. You still enjoy the simplicity of
1742 the first front-end with the extended power of the new transition types.
1743 This <link xlink:href="examples/SimpleWithFunctors.cpp">tutorial</link>,
1744 adapted from the earlier example does just this.</para>
1745 <para>Of course, it is also possible to define states where entry and exit
1746 actions are also provided as functors as these are generated by eUML and
1747 both front-ends are equivalent. For example, we can define a state
1748 as:</para>
1749 <programlisting>struct Empty_Entry
1750 {
1751 template &lt;class Event,class Fsm,class State>
1752 void operator()(Event const&amp;,Fsm&amp;,State&amp;)
1753 {
1754 ...
1755 }
1756 }; // same for Empty_Exit
1757 struct Empty_tag {};
1758 struct Empty : public msm::front::euml::func_state&lt;Empty_tag,Empty_Entry,Empty_Exit>{};</programlisting>
1759 <para>This also means that you can, like in the transition table, write entry /
1760 exit actions made of more complicated action combinations. The previous
1761 example can therefore <link xlink:href="examples/SimpleWithFunctors2.cpp">be
1762 rewritten</link>.</para>
1763 <para>Usually, however, one will probably use the standard state definition as
1764 it provides the same capabilities as this front-end state definition, unless
1765 one needs some of the shipped predefined functors or is a fan of functional
1766 programming.</para>
1767 </sect2>
1768 <sect2>
1769 <title><command xml:id="functor-front-end-actions"/>What do you actually do inside actions / guards (Part 2)?</title>
1770 <para>Using the basic front-end, we saw how to pass data to actions through the
1771 event, that data common to all states could be stored in the state machine,
1772 state relevant data could be stored in the state and access as template
1773 parameter in the entry / exit actions. What was however missing was the
1774 capability to access relevant state data in the transition action. This is
1775 possible with this front-end. A transition's source and target state are
1776 also given as arguments. If the current calculation's state was to be found
1777 in the transition's source state (whatever it is), we could access
1778 it:</para>
1779 <programlisting>struct send_rocket
1780 {
1781 template &lt;class Fsm,class Evt,class SourceState,class TargetState>
1782 void operator()(Evt const&amp;, Fsm&amp; fsm, SourceState&amp; src,TargetState&amp; )
1783 {
1784 fire_rocket(evt.direction, src.current_calculation);
1785 }
1786 }; </programlisting>
1787 <para>It was a little awkward to generate new events inside actions with the basic
1788 front-end. With the functor front-end it is much cleaner:</para>
1789 <programlisting>struct send_rocket
1790 {
1791 template &lt;class Fsm,class Evt,class SourceState,class TargetState>
1792 void operator()(Evt const&amp; evt, Fsm&amp; fsm, SourceState&amp; src,TargetState&amp;)
1793 {
1794 fire_rocket(evt.direction, src.current_calculation);
1795 fsm.process_event(rocket_launched());
1796 }
1797 }; </programlisting>
1798 </sect2>
1799 <sect2>
1800 <title>Defining a simple state machine</title>
1801 <para>Like states, state machines can be defined using the previous front-end,
1802 as the previous example showed, or with the functor front-end, which allows
1803 you to define a state machine entry and exit functions as functors, as in
1804 <link xlink:href="examples/SimpleWithFunctors2.cpp">this
1805 example</link>.</para>
1806 </sect2>
1807 <sect2>
1808 <title>Anonymous transitions</title>
1809 <para>Anonymous (completion) transitions are transitions without a named event.
1810 We saw how this front-end uses <code>none</code> when no action or guard is
1811 required. We can also use <code>none</code> instead of an event to mark an
1812 anonymous transition. For example, the following transition makes an
1813 immediate transition from State1 to State2:</para>
1814 <programlisting>Row &lt; State1 , none , State2 ></programlisting>
1815 <para>The following transition does the same but calling an action in the
1816 process:</para>
1817 <programlisting>Row &lt; State1 , none , State2 , State1ToState2, none ></programlisting>
1818 <para>The following diagram shows an example and its <link
1819 xlink:href="examples/AnonymousTutorialWithFunctors.cpp"
1820 >implementation</link>:</para>
1821 <para><inlinemediaobject>
1822 <imageobject>
1823 <imagedata fileref="images/Anonymous.jpg" width="70%" scalefit="1"/>
1824 </imageobject>
1825 </inlinemediaobject></para>
1826 </sect2>
1827 <sect2>
1828 <title><command xml:id="functor-internal-transitions"/>Internal
1829 transitions</title>
1830 <para>The <link xlink:href="examples/SimpleTutorialInternalFunctors.cpp"
1831 >following example</link> uses internal transitions with the functor
1832 front-end. As for the simple standard front-end, both methods of defining
1833 internal transitions are supported:<itemizedlist>
1834 <listitem>
1835 <para>providing a <code>Row</code> in the state machine's transition
1836 table with <code>none</code> as target state defines an internal
1837 transition.</para>
1838 </listitem>
1839 <listitem>
1840 <para>providing an <code>internal_transition_table</code> made of
1841 <code>Internal</code> rows inside a state or submachine
1842 defines UML-conform internal transitions with higher
1843 priority.</para>
1844 </listitem>
1845 <listitem>
1846 <para>transitions defined inside
1847 <code>internal_transition_table</code> require no source or
1848 target state as the source state is known (<code>Internal</code>
1849 really are <code>Row</code> without a source or target state)
1850 .</para>
1851 </listitem>
1852 </itemizedlist>Like for the <command xlink:href="#internal-transitions-note"
1853 >standard front-end internal transitions</command>, internal transition
1854 tables are added into the main state machine's table, thus allowing you to
1855 distribute the transition table definition and reuse states.</para>
1856 <para>There is an added bonus offered for submachines, which can have both the
1857 standard transition_table and an internal_transition_table (which has higher
1858 priority). This makes it easier if you decide to make a full submachine from
1859 a state later. It is also slightly faster than the standard alternative,
1860 adding orthogonal regions, because event dispatching will, if accepted by
1861 the internal table, not continue to the subregions. This gives you a O(1)
1862 dispatch instead of O(number of regions). While the example is with eUML,
1863 the same is also possible with this front-end.</para>
1864 </sect2>
1865 <sect2>
1866 <title><command xml:id="any-event"/>Kleene (any) event</title>
1867 <para>Normally, MSM requires an event to fire a transition. But there are cases,
1868 where any event, no matter which one would do:<itemizedlist>
1869 <listitem>
1870 <para>If you want to reduce the number of transitions: any event
1871 would do, possibly will guards decide what happens</para>
1872 </listitem>
1873 <listitem>
1874 <para>Pseudo entry states do not necessarily want to know the event
1875 which caused their activation, or they might want to know only a
1876 property of it.</para>
1877 </listitem>
1878 </itemizedlist></para>
1879 <para>MSM supports a boost::any as an acceptable event. This event will match
1880 any event, meaning that if a transition with boost::any as event originates
1881 from the current state, this transition would fire (provided no guards or
1882 transition with a higher priority fires first). This event is named Kleene,
1883 as reference top the Kleene star used in a regex.</para>
1884 <para>For example, this transition on a state machine instance named fsm:</para>
1885 <programlisting>Row &lt; State1, boost::any, State2></programlisting>
1886 <para>will fire if State1 is active and an event is processed:</para>
1887 <programlisting>fsm.process_event(whatever_event());</programlisting>
1888 <para>At this point, you can use this <emphasis role="italic">any</emphasis>
1889 event in transition actions to get back to the original event by calling for
1890 example<emphasis role="italic"> boost::any::type()</emphasis>.</para>
1891 <para>It is also possible to support your own Kleene events by specializing
1892 boost::msm::is_kleene_event for a given event, for example:</para>
1893 <programlisting>namespace boost { namespace msm{
1894 template&lt;>
1895 struct is_kleene_event&lt; my_event >
1896 {
1897 typedef boost::mpl::true_ type;
1898 };
1899 }}</programlisting>
1900 <para>The only requirement is that this event must have a copy constructor from
1901 the event originally processed on the state machine.</para>
1902 </sect2>
1903 </sect1>
1904 <sect1>
1905 <title><command xml:id="eUML-front-end"/>eUML</title>
1906 <para><emphasis role="underline">Important note</emphasis>: eUML requires a compiler
1907 supporting Boost.Typeof. Full eUML has experimental status (but not if only the
1908 transition table is written using eUML) because some compilers will start
1909 crashing when a state machine becomes too big (usually when you write huge
1910 actions).</para>
1911 <para>The previous front-ends are simple to write but still force an amount of
1912 noise, mostly MPL types, so it would be nice to write code looking like C++
1913 (with a C++ action language) directly inside the transition table, like UML
1914 designers like to do on their state machine diagrams. If it were functional
1915 programming, it would be even better. This is what eUML is for.</para>
1916 <para>eUML is a Boost.Proto and Boost.Typeof-based compile-time domain specific
1917 embedded language. It provides grammars which allow the definition of
1918 actions/guards directly inside the transition table or entry/exit in the state
1919 definition. There are grammars for actions, guards, flags, attributes, deferred
1920 events, initial states.</para>
1921 <para>It also relies on Boost.Typeof as a wrapper around the new decltype C++0x
1922 feature to provide a compile-time evaluation of all the grammars. Unfortunately,
1923 all the underlying Boost libraries are not Typeof-enabled, so for the moment,
1924 you will need a compiler where Typeof is supported (like VC9-10, g++ >=
1925 4.3).</para>
1926 <para>Examples will be provided in the next paragraphs. You need to include eUML
1927 basic features: </para>
1928 <para>
1929 <programlisting>#include &lt;msm/front/euml/euml.hpp></programlisting>
1930 </para>
1931 <para>To add STL support (at possible cost of longer compilation times), include: </para>
1932 <para>
1933 <programlisting>#include &lt;msm/front/euml/stl.hpp></programlisting>
1934 </para>
1935 <para>eUML is defined in the namespace <code>msm::front::euml</code>.</para>
1936 <sect2>
1937 <title>Transition table</title>
1938 <para>A transition can be defined using eUML as: </para>
1939 <para>
1940 <programlisting>source + event [guard] / action == target</programlisting>
1941 </para>
1942 <para>or as</para>
1943 <para>
1944 <programlisting>target == source + event [guard] / action</programlisting>
1945 </para>
1946 <para>The first version looks like a drawn transition in a diagram, the second
1947 one seems natural to a C++ developer.</para>
1948 <para>The simple transition table written with the <command
1949 xlink:href="#functor-front-end">functor front-end</command> can now be
1950 written as:</para>
1951 <programlisting>BOOST_MSM_EUML_TRANSITION_TABLE((
1952 Stopped + play [some_guard] / (some_action , start_playback) == Playing ,
1953 Stopped + open_close/ open_drawer == Open ,
1954 Stopped + stop == Stopped ,
1955 Open + open_close / close_drawer == Empty ,
1956 Empty + open_close / open_drawer == Open ,
1957 Empty + cd_detected [good_disk_format] / store_cd_info == Stopped
1958 ),transition_table) </programlisting>
1959 <para>Or, using the alternative notation, it can be:</para>
1960 <programlisting>BOOST_MSM_EUML_TRANSITION_TABLE((
1961 Playing == Stopped + play [some_guard] / (some_action , start_playback) ,
1962 Open == Stopped + open_close/ open_drawer ,
1963 Stopped == Stopped + stop ,
1964 Empty == Open + open_close / close_drawer ,
1965 Open == Empty + open_close / open_drawer ,
1966 Stopped == Empty + cd_detected [good_disk_format] / store_cd_info
1967 ),transition_table) </programlisting>
1968 <para>The transition table now looks like a list of (readable) rules with little
1969 noise.</para>
1970 <para>UML defines guards between “[ ]” and actions after a “/”, so the chosen
1971 syntax is already more readable for UML designers. UML also allows designers
1972 to define several actions sequentially (our previous ActionSequence_)
1973 separated by a comma. The first transition does just this: two actions
1974 separated by a comma and enclosed inside parenthesis to respect C++ operator
1975 precedence.</para>
1976 <para>If this seems to you like it will cost you run-time performance, don't
1977 worry, eUML is based on typeof (or decltype) which only evaluates the
1978 parameters to BOOST_MSM_EUML_TRANSITION_TABLE and no run-time cost occurs.
1979 Actually, eUML is only a metaprogramming layer on top of "standard" MSM
1980 metaprogramming and this first layer generates the previously-introduced
1981 <command xlink:href="#functor-front-end">functor
1982 front-end</command>.</para>
1983 <para>UML also allows designers to define more complicated guards, like
1984 [good_disk_format &amp;&amp; (some_condition || some_other_condition)]. This
1985 was possible with our previously defined functors, but using a complicated
1986 template syntax. This syntax is now possible exactly as written, which means
1987 without any syntactic noise at all.</para>
1988 </sect2>
1989 <sect2>
1990 <title>A simple example: rewriting only our transition table </title>
1991 <para>As an introduction to eUML, we will rewrite our tutorial's transition
1992 table using eUML. This will require two or three changes, depending on the compiler:<itemizedlist>
1993 <listitem>
1994 <para>events must inherit from msm::front::euml::euml_event&lt;
1995 event_name ></para>
1996 </listitem>
1997 <listitem>
1998 <para>states must inherit from msm::front::euml::euml_state&lt;
1999 state_name ></para>
2000 </listitem>
2001 <listitem>
2002 <para>with VC, states must be declared before the front-end</para>
2003 </listitem>
2004 </itemizedlist></para>
2005 <para>We now can write the transition table like just shown, using
2006 BOOST_MSM_EUML_DECLARE_TRANSITION_TABLE instead of
2007 BOOST_MSM_EUML_TRANSITION_TABLE. The <link
2008 xlink:href="examples/SimpleTutorialWithEumlTable.cpp"
2009 >implementation</link> is pretty straightforward. The only required
2010 addition is the need to declare a variable for each state or add parenses (a
2011 default-constructor call) in the transition table.</para>
2012 <para>The <link xlink:href="examples/CompositeTutorialWithEumlTable.cpp">
2013 <command xml:id="eUML-composite-table">composite</command></link> implementation is also natural:</para>
2014 <programlisting>// front-end like always
2015 struct sub_front_end : public boost::msm::front::state_machine_def&lt;sub_front_end>
2016 {
2017 ...
2018 };
2019 // back-end like always
2020 typedef boost::msm::back::state_machine&lt;sub_front_end> sub_back_end;
2021
2022 sub_back_end const sub; // sub can be used in a transition table.</programlisting>
2023 <para>Unfortunately, there is a bug with VC, which appears from time to time and
2024 causes in a stack overflow. If you get a warning that the program is
2025 recursive on all paths, revert to either standard eUML or another front-end
2026 as Microsoft doesn't seem to intend to fix it.</para>
2027 <para>We now have a new, more readable transition table with few changes to our
2028 example. eUML can do much more so please follow the guide.</para>
2029 </sect2>
2030 <sect2>
2031 <title>Defining events, actions and states with entry/exit actions</title>
2032 <sect3>
2033 <title>Events</title>
2034 <para>Events must be proto-enabled. To achieve this, they must inherit from
2035 a proto terminal (euml_event&lt;event-name>). eUML also provides a macro
2036 to make this easier:</para>
2037 <para>
2038 <programlisting>BOOST_MSM_EUML_EVENT(play)</programlisting>
2039 </para>
2040 <para>This declares an event type and an instance of this type called
2041 <code>play</code>, which is now ready to use in state or transition
2042 behaviors.</para>
2043 <para>There is a second macro, BOOST_MSM_EUML_EVENT_WITH_ATTRIBUTES, which
2044 takes as second parameter the attributes an event will contain, using
2045 the <command xlink:href="#eUML-attributes">attribute
2046 syntax</command>.</para>
2047 <para><emphasis role="underline">Note</emphasis>: as we now have events
2048 defined as instances instead of just types, can we still process an
2049 event by creating one on the fly, like:
2050 <code>fsm.process_event(play());</code> or do we have to write:
2051 <code>fsm.process_event(play);</code></para>
2052 <para>The answer is you can do both. The second one is easier but unlike
2053 other front-ends, the second uses a defined operator(), which creates an
2054 event on the fly.</para>
2055 </sect3>
2056 <sect3>
2057 <title>Actions</title>
2058 <para>Actions (returning void) and guards (returning a bool) are defined
2059 like previous functors, with the difference that they also must be
2060 proto-enabled. This can be done by inheriting from euml_action&lt;
2061 functor-name >. eUML also provides a macro:</para>
2062 <programlisting>BOOST_MSM_EUML_ACTION(some_condition)
2063 {
2064 template &lt;class Fsm,class Evt,class SourceState,class TargetState>
2065 bool operator()(Evt const&amp; ,Fsm&amp; ,SourceState&amp;,TargetState&amp; )
2066 { return true; }
2067 }; </programlisting>
2068 <para>Like for events, this macro declares a functor type and an instance
2069 for use in transition or state behaviors.</para>
2070 <para>It is possible to use the same action grammar from the transition
2071 table to define state entry and exit behaviors. So
2072 <code>(action1,action2)</code> is a valid entry or exit behavior
2073 executing both actions in turn.</para>
2074 <para>The state functors have a slightly different signature as there is no
2075 source and target state but only a current state (entry/exit actions are
2076 transition-independent), for example:</para>
2077 <programlisting>BOOST_MSM_EUML_ACTION(Empty_Entry)
2078 {
2079 template &lt;class Evt,class Fsm,class State>
2080 void operator()(Evt const&amp; ,Fsm&amp; ,State&amp; ) { ... }
2081 }; </programlisting>
2082 <para><command xml:id="eUML-reuse-functor"/>It is also possible to reuse the functors from the functor front-end.
2083 The syntax is however slightly less comfortable as we need to pretend
2084 creating one on the fly for typeof. For example:</para>
2085 <programlisting>struct start_playback
2086 {
2087 template &lt;class Fsm,class Evt,class SourceState,class TargetState>
2088 void operator()(Evt const&amp; ,Fsm&amp;,SourceState&amp; ,TargetState&amp; )
2089 {
2090 ...
2091 }
2092 };
2093 BOOST_MSM_EUML_TRANSITION_TABLE((
2094 Playing == Stopped + play / start_playback() ,
2095 ...
2096 ),transition_table)</programlisting>
2097 </sect3>
2098 <sect3>
2099 <title>States</title>
2100 <para>There is also a macro for states. This macro has 2 arguments, first
2101 the expression defining the state, then the state (instance)
2102 name:</para>
2103 <programlisting>BOOST_MSM_EUML_STATE((),Paused)</programlisting>
2104 <para>This defines a simple state without entry or exit action. You can
2105 provide in the expression parameter the state behaviors (entry and exit)
2106 using the action grammar, like in the transition table:</para>
2107 <programlisting>BOOST_MSM_EUML_STATE(((Empty_Entry,Dummy_Entry)/*2 entryactions*/,
2108 Empty_Exit/*1 exit action*/ ),
2109 Empty)</programlisting>
2110 <para>This means that Empty is defined as a state with an entry action made
2111 of two sub-actions, Empty_Entry and Dummy_Entry (enclosed inside
2112 parenthesis), and an exit action, Empty_Exit.</para>
2113 <para>There are several possibilitites for the <command
2114 xml:id="eUML-build-state"/> expression syntax:<itemizedlist>
2115 <listitem>
2116 <para>(): state without entry or exit action.</para>
2117 </listitem>
2118 <listitem>
2119 <para>(Expr1): state with entry but no exit action.</para>
2120 </listitem>
2121 <listitem>
2122 <para>(Expr1,Expr2): state with entry and exit action.</para>
2123 </listitem>
2124 <listitem>
2125 <para>(Expr1,Expr2,Attributes): state with entry and exit
2126 action, defining some attributes (read further on).</para>
2127 </listitem>
2128 <listitem>
2129 <para>(Expr1,Expr2,Attributes,Configure): state with entry and
2130 exit action, defining some attributes (read further on) and
2131 flags (standard MSM flags) or deferred events (standard MSM
2132 deferred events).</para>
2133 </listitem>
2134 <listitem>
2135 <para>(Expr1,Expr2,Attributes,Configure,Base): state with entry
2136 and exit action, defining some attributes (read further on),
2137 flags and deferred events (plain msm deferred events) and a
2138 non-default base state (as defined in standard MSM).</para>
2139 </listitem>
2140 </itemizedlist></para>
2141 <para>no_action is also defined, which does, well, nothing except being a
2142 placeholder (needed for example as entry action if we have no entry but
2143 an exit). Expr1 and Expr2 are a sequence of actions, obeying the same
2144 action grammar as in the transition table (following the “/”
2145 symbol).</para>
2146 <para>The BOOST_MSM_EUML_STATE macro will allow you to define most common
2147 states, but sometimes you will need more, for example provide in your
2148 states some special behavior. In this case, you will have to do the
2149 macro's job by hand, which is not very complicated. The state will need
2150 to inherit from <code>msm::front::state&lt;></code>, like any state, and
2151 from <code>euml_state&lt;state-name></code> to be proto-enabled. You
2152 will then need to declare an instance for use in the transition table.
2153 For example:</para>
2154 <programlisting>struct Empty_impl : public msm::front::state&lt;> , public euml_state&lt;Empty_impl>
2155 {
2156 void activate_empty() {std::cout &lt;&lt; "switching to Empty " &lt;&lt; std::endl;}
2157 template &lt;class Event,class Fsm>
2158 void on_entry(Event const&amp; evt,Fsm&amp;fsm){...}
2159 template &lt;class Event,class Fsm>
2160 void on_exit(Event const&amp; evt,Fsm&amp;fsm){...}
2161 };
2162 //instance for use in the transition table
2163 Empty_impl const Empty;</programlisting>
2164 <para>Notice also that we defined a method named activate_empty. We would
2165 like to call it inside a behavior. This can be done using the
2166 BOOST_MSM_EUML_METHOD macro. </para>
2167 <programlisting>BOOST_MSM_EUML_METHOD(ActivateEmpty_,activate_empty,activate_empty_,void,void)</programlisting>
2168 <para>The first parameter is the name of the underlying functor, which you
2169 could use with the functor front-end, the second is the state method
2170 name, the third is the eUML-generated function, the fourth and fifth the
2171 return value when used inside a transition or a state behavior. You can
2172 now use this inside a transition:</para>
2173 <programlisting>Empty == Open + open_close / (close_drawer,activate_empty_(target_))</programlisting>
2174 </sect3>
2175 </sect2>
2176 <sect2>
2177 <title>Wrapping up a simple state machine and first complete examples</title>
2178 <para>You can reuse the state machine definition method from the standard
2179 front-end and simply replace the transition table by this new one. You can
2180 also use eUML to define a state machine "on the fly" (if, for example, you
2181 need to provide an on_entry/on_exit for this state machine as a functor).
2182 For this, there is also a macro, <command xml:id="eUML-build-sm"
2183 />BOOST_MSM_EUML_DECLARE_STATE_MACHINE, which has 2 arguments, an expression
2184 describing the state machine and the state machine name. The expression has
2185 up to 8 arguments:<itemizedlist>
2186 <listitem>
2187 <para>(Stt, Init): simplest state machine where only the transition
2188 table and initial state(s) are defined.</para>
2189 </listitem>
2190 <listitem>
2191 <para>(Stt, Init, Expr1): state machine where the transition table,
2192 initial state and entry action are defined.</para>
2193 </listitem>
2194 <listitem>
2195 <para>(Stt, Init, Expr1, Expr2): state machine where the transition
2196 table, initial state, entry and exit actions are defined.</para>
2197 </listitem>
2198 <listitem>
2199 <para>(Stt, Init, Expr1, Expr2, Attributes): state machine where the
2200 transition table, initial state, entry and exit actions are
2201 defined. Furthermore, some attributes are added (read further
2202 on).</para>
2203 </listitem>
2204 <listitem>
2205 <para>(Stt, Init, Expr1, Expr2, Attributes, Configure): state
2206 machine where the transition table, initial state, entry and
2207 exit actions are defined. Furthermore, some attributes (read
2208 further on), flags, deferred events and <link
2209 xlink:href="#eUML-Configuration">configuration
2210 capabilities</link> (no message queue / no exception
2211 catching) are added.</para>
2212 </listitem>
2213 <listitem>
2214 <para>(Stt, Init, Expr1, Expr2, Attributes, Flags, Deferred , Base):
2215 state machine where the transition table, initial state, entry
2216 and exit actions are defined. Furthermore, attributes (read
2217 further on), flags , deferred events and configuration
2218 capabilities (no message queue / no exception catching) are
2219 added and a non-default base state (see the <link
2220 xlink:href="#backend-base-state">back-end
2221 description</link>) is defined.</para>
2222 </listitem>
2223 </itemizedlist>For example, a minimum state machine could be defined
2224 as:</para>
2225 <programlisting>BOOST_MSM_EUML_TRANSITION_TABLE((
2226 ),transition_table) </programlisting>
2227 <programlisting>BOOST_MSM_EUML_DECLARE_STATE_MACHINE((transition_table,init_ &lt;&lt; Empty ),
2228 player_)</programlisting>
2229 <para>Please have a look at the player tutorial written using eUML's <link
2230 xlink:href="examples/SimpleTutorialEuml2.cpp">first syntax</link> and
2231 <link xlink:href="examples/SimpleTutorialEuml.cpp">second syntax</link>.
2232 The BOOST_MSM_EUML_DECLARE_ATTRIBUTE macro, to which we will get back
2233 shortly, declares attributes given to an eUML type (state or event) using
2234 the <command xlink:href="#eUML-attributes">attribute
2235 syntax</command>.</para>
2236 </sect2>
2237 <sect2>
2238 <title>Defining a submachine</title>
2239 <para>Defining a submachine (see <link
2240 xlink:href="examples/CompositeTutorialEuml.cpp">tutorial</link>) with
2241 other front-ends simply means using a state which is a state machine in the
2242 transition table of another state machine. This is the same with eUML. One
2243 only needs define a second state machine and reference it in the transition
2244 table of the containing state machine.</para>
2245 <para>Unlike the state or event definition macros,
2246 BOOST_MSM_EUML_DECLARE_STATE_MACHINE defines a type, not an instance because
2247 a type is what the back-end requires. This means that you will need to
2248 declare yourself an instance to reference your submachine into another state
2249 machine, for example:</para>
2250 <programlisting>BOOST_MSM_EUML_DECLARE_STATE_MACHINE(...,Playing_)
2251 typedef msm::back::state_machine&lt;Playing_> Playing_type;
2252 Playing_type const Playing;</programlisting>
2253 <para>We can now use this instance inside the transition table of the containing
2254 state machine:</para>
2255 <programlisting>Paused == Playing + pause / pause_playback</programlisting>
2256 </sect2>
2257 <sect2>
2258 <title>
2259 <command xml:id="eUML-attributes"/>Attributes / Function call</title>
2260 <para>We now want to make our grammar more useful. Very often, one needs only
2261 very simple action methods, for example ++Counter or Counter > 5 where
2262 Counter is usually defined as some attribute of the class containing the
2263 state machine. It seems like a waste to write a functor for such a simple
2264 action. Furthermore, states within MSM are also classes so they can have
2265 attributes, and we would also like to provide them with attributes. </para>
2266 <para>If you look back at our examples using the <link
2267 xlink:href="examples/SimpleTutorialEuml2.cpp">first</link> and <link
2268 xlink:href="examples/SimpleTutorialEuml.cpp">second</link> syntaxes, you
2269 will find a BOOST_MSM_EUML_DECLARE_ATTRIBUTE and a BOOST_MSM_EUML_ATTRIBUTES
2270 macro. The first one declares possible attributes:</para>
2271 <programlisting>BOOST_MSM_EUML_DECLARE_ATTRIBUTE(std::string,cd_name)
2272 BOOST_MSM_EUML_DECLARE_ATTRIBUTE(DiskTypeEnum,cd_type)</programlisting>
2273 <para>This declares two attributes: cd_name of type std::string and cd_type of
2274 type DiskTypeEnum. These attributes are not part of any event or state in
2275 particular, we just declared a name and a type. Now, we can add attributes
2276 to our cd_detected event using the second one:</para>
2277 <programlisting>BOOST_MSM_EUML_ATTRIBUTES((attributes_ &lt;&lt; cd_name &lt;&lt; cd_type ),
2278 cd_detected_attributes)</programlisting>
2279 <para>This declares an attribute list which is not linked to anything in
2280 particular yet. It can be attached to a state or an event. For example, if
2281 we want the event cd_detected to have these defined attributes we
2282 write:</para>
2283 <programlisting>BOOST_MSM_EUML_EVENT_WITH_ATTRIBUTES(cd_detected,cd_detected_attributes)</programlisting>
2284 <para>For states, we use the BOOST_MSM_EUML_STATE macro, which has an expression
2285 form where one can provide attributes. For example:</para>
2286 <programlisting>BOOST_MSM_EUML_STATE((no_action /*entry*/,no_action/*exit*/,
2287 attributes_ &lt;&lt; cd_detected_attributes),
2288 some_state)</programlisting>
2289 <para>OK, great, we now have a way to add attributes to a class, which we could
2290 have done more easily, so what is the point? The point is that we can now
2291 reference these attributes directly, at compile-time, in the transition
2292 table. For example, in the example, you will find this transition:</para>
2293 <programlisting>Stopped==Empty+cd_detected[good_disk_format&amp;&amp;(event_(cd_type)==Int_&lt;DISK_CD>())] </programlisting>
2294 <para>Read event_(cd_type) as event_->cd_type with event_ a type generic for
2295 events, whatever the concrete event is (in this particular case, it happens
2296 to be a cd_detected as the transition shows).</para>
2297 <para>The main advantage of this feature is that you do not need to define a new
2298 functor and you do not need to look inside the functor to know what it does,
2299 you have all at hand.</para>
2300 <para>MSM provides more generic objects for state machine types:<itemizedlist>
2301 <listitem>
2302 <para>event_ : used inside any action, the event triggering the
2303 transition</para>
2304 </listitem>
2305 <listitem>
2306 <para>state_: used inside entry and exit actions, the entered /
2307 exited state</para>
2308 </listitem>
2309 <listitem>
2310 <para>source_: used inside a transition action, the source
2311 state</para>
2312 </listitem>
2313 <listitem>
2314 <para>target_: used inside a transition action, the target
2315 state</para>
2316 </listitem>
2317 <listitem>
2318 <para>fsm_: used inside any action, the (lowest-level) state machine
2319 processing the transition</para>
2320 </listitem>
2321 <listitem>
2322 <para>Int_&lt;int value>: a functor representing an int</para>
2323 </listitem>
2324 <listitem>
2325 <para>Char_&lt;value>: a functor representing a char</para>
2326 </listitem>
2327 <listitem>
2328 <para>Size_t_&lt;value>: a functor representing a size_t</para>
2329 </listitem>
2330 <listitem>
2331 <para>String_&lt;mpl::string> (boost >= 1.40): a functor
2332 representing a string.</para>
2333 </listitem>
2334 </itemizedlist></para>
2335 <para>These helpers can be used in two different ways:<itemizedlist>
2336 <listitem>
2337 <para>helper(attribute_name) returns the attribute with name
2338 attribute_name</para>
2339 </listitem>
2340 <listitem>
2341 <para>helper returns the state / event type itself.</para>
2342 </listitem>
2343 </itemizedlist></para>
2344 <para>The second form is helpful if you want to provide your states with their
2345 own methods, which you also want to use inside the transition table. In the
2346 <link xlink:href="examples/SimpleTutorialEuml.cpp">above
2347 tutorial</link>, we provide Empty with an activate_empty method. We would
2348 like to create a eUML functor and call it from inside the transition table.
2349 This is done using the MSM_EUML_METHOD / MSM_EUML_FUNCTION macros. The first
2350 creates a functor to a method, the second to a free function. In the
2351 tutorial, we write:</para>
2352 <programlisting>MSM_EUML_METHOD(ActivateEmpty_,activate_empty,activate_empty_,void,void)</programlisting>
2353 <para>The first parameter is the functor name, for use with the functor
2354 front-end. The second is the name of the method to call. The third is the
2355 function name for use with eUML, the fourth is the return type of the
2356 function if used in the context of a transition action, the fifth is the
2357 result type if used in the context of a state entry / exit action (usually
2358 fourth and fifth are the same). We now have a new eUML function calling a
2359 method of "something", and this "something" is one of the five previously
2360 shown generic helpers. We can now use this in a transition, for
2361 example:</para>
2362 <programlisting>Empty == Open + open_close / (close_drawer,activate_empty_(target_))</programlisting>
2363 <para>The action is now defined as a sequence of two actions: close_drawer and
2364 activate_empty, which is called on the target itself. The target being Empty
2365 (the state defined left), this really will call Empty::activate_empty().
2366 This method could also have an (or several) argument(s), for example the
2367 event, we could then call activate_empty_(target_ , event_).</para>
2368 <para>More examples can be found in the <link
2369 xlink:href="examples/CompilerStressTestEuml.cpp">terrible compiler
2370 stress test</link>, the <link xlink:href="examples/SimpleTimer.cpp"
2371 >timer example</link> or in the <link
2372 xlink:href="examples/iPodSearchEuml.cpp">iPodSearch with eUML</link>
2373 (for String_ and more).</para>
2374 </sect2>
2375 <sect2>
2376 <title>Orthogonal regions, flags, event deferring</title>
2377 <para>Defining orthogonal regions really means providing more initial states. To
2378 add more initial states, “shift left” some, for example, if we had another
2379 initial state named AllOk :</para>
2380 <programlisting>BOOST_MSM_EUML_DECLARE_STATE_MACHINE((transition_table,
2381 init_ &lt;&lt; Empty &lt;&lt; AllOk ),
2382 player_)</programlisting>
2383 <para>You remember from the <command xlink:href="#eUML-build-state"
2384 >BOOST_MSM_EUML_STATE </command> and <command
2385 xlink:href="#eUML-build-sm"
2386 >BOOST_MSM_EUML_DECLARE_STATE_MACHINE</command> signatures that just
2387 after attributes, we can define flags, like in the basic MSM front-end. To
2388 do this, we have another "shift-left" grammar, for example:</para>
2389 <programlisting>BOOST_MSM_EUML_STATE((no_action,no_action, attributes_ &lt;&lt;no_attributes_,
2390 /* flags */ configure_&lt;&lt; PlayingPaused &lt;&lt; CDLoaded),
2391 Paused)</programlisting>
2392 <para>We now defined that Paused will get two flags, PlayingPaused and CDLoaded,
2393 defined, with another macro:</para>
2394 <programlisting>BOOST_MSM_EUML_FLAG(CDLoaded)</programlisting>
2395 <para>This corresponds to the following basic front-end definition of
2396 Paused:</para>
2397 <programlisting>struct Paused : public msm::front::state&lt;>
2398 {
2399 typedef mpl::vector2&lt;PlayingPaused,CDLoaded> flag_list;
2400 };</programlisting>
2401 <para>Under the hood, what you get really is a mpl::vector2.</para>
2402 <para><emphasis role="underline">Note</emphasis>: As we use the version of
2403 BOOST_MSM_EUML_STATE's expression with 4 arguments, we need to tell eUML
2404 that we need no attributes. Similarly to a <code>cout &lt;&lt; endl</code>,
2405 we need a <code>attributes_ &lt;&lt; no_attributes_</code> syntax.</para>
2406 <para>You can use the flag with the is_flag_active method of a state machine.
2407 You can also use the provided helper function is_flag_ (returning a bool)
2408 for state and transition behaviors. For example, in the <link
2409 xlink:href="examples/iPodEuml.cpp">iPod implementation with eUML</link>,
2410 you find the following transition:</para>
2411 <programlisting>ForwardPressed == NoForward + EastPressed[!is_flag_(NoFastFwd)]</programlisting>
2412 <para>The function also has an optional second parameter which is the state
2413 machine on which the function is called. By default, fsm_ is used (the
2414 current state machine) but you could provide a functor returning a reference
2415 to another state machine.</para>
2416 <para>eUML also supports defining deferred events in the state (state machine)
2417 definition. To this aim, we can reuse the flag grammar. For example:</para>
2418 <programlisting>BOOST_MSM_EUML_STATE((Empty_Entry,Empty_Exit, attributes_ &lt;&lt; no_attributes_,
2419 /* deferred */ configure_&lt;&lt; play ),Empty) </programlisting>
2420 <para>The configure_ left shift is also responsible for deferring events. Shift
2421 inside configure_ a flag and the state will get a flag, shift an event and
2422 it will get a deferred event. This replaces the basic front-end
2423 definition:</para>
2424 <programlisting>typedef mpl::vector&lt;play> deferred_events;</programlisting>
2425 <para>In <link xlink:href="examples/OrthogonalDeferredEuml.cpp">this
2426 tutorial</link>, player is defining a second orthogonal region with
2427 AllOk as initial state. The <code>Empty</code> and <code>Open</code> states
2428 also defer the event <code>play</code>. <code>Open</code>,
2429 <code>Stopped</code> and <code>Pause</code> also support the flag
2430 <code>CDLoaded</code> using the same left shift into
2431 <code>configure_</code>.</para>
2432 <para>In the functor front-end, we also had the possibility to defer an event
2433 inside a transition, which makes possible conditional deferring. This is
2434 also possible with eUML through the use of the defer_ order, as shown in
2435 <link xlink:href="examples/OrthogonalDeferredEuml.cpp">this
2436 tutorial</link>. You will find the following transition:</para>
2437 <programlisting>Open + play / defer_</programlisting>
2438 <para>This is an <command xlink:href="#eUML-internal">internal
2439 transition</command>. Ignore it for the moment. Interesting is, that
2440 when the event <code>play</code> is fired and <code>Open</code> is active,
2441 the event will be deferred. Now add a guard and you can conditionally defer
2442 the event, for example:</para>
2443 <programlisting>Open + play [ some_condition ] / defer_</programlisting>
2444 <para>This is similar to what we did with the functor front-end. This means that
2445 we have the same constraints. Using defer_ instead of a state declaration,
2446 we need to tell MSM that we have deferred events in this state machine. We
2447 do this (again) using a configure_ declaration in the state machine
2448 definition in which we shift the deferred_events configuration flag:</para>
2449 <programlisting>BOOST_MSM_EUML_DECLARE_STATE_MACHINE((transition_table,
2450 init_ &lt;&lt; Empty &lt;&lt; AllOk,
2451 Entry_Action,
2452 Exit_Action,
2453 attributes_ &lt;&lt; no_attributes_,
2454 configure_&lt;&lt; deferred_events ),
2455 player_)</programlisting>
2456 <para>A <link xlink:href="examples/OrthogonalDeferredEuml2.cpp">tutorial</link>
2457 illustrates this possibility.</para>
2458 </sect2>
2459 <sect2>
2460 <title>
2461 <command xml:id="eUML-Configuration"/>Customizing a state machine / Getting
2462 more speed</title>
2463 <para>We just saw how to use configure_ to define deferred events or flags. We
2464 can also use it to configure our state machine like we did with the other front-ends:<itemizedlist>
2465 <listitem>
2466 <para><code>configure_ &lt;&lt; no_exception</code>: disables
2467 exception handling</para>
2468 </listitem>
2469 <listitem>
2470 <para><code>configure_ &lt;&lt; no_msg_queue</code> deactivates the
2471 message queue</para>
2472 </listitem>
2473 <listitem>
2474 <para><code>configure_ &lt;&lt; deferred_events</code> manually
2475 enables event deferring</para>
2476 </listitem>
2477 </itemizedlist></para>
2478 <para>Deactivating the first two features and not activating the third if not
2479 needed greatly improves the event dispatching speed of your state machine.
2480 Our <link xlink:href="examples/EumlSimple.cpp">speed testing</link> example
2481 with eUML does this for the best performance.</para>
2482 <para><emphasis role="underline">Important note</emphasis>: As exit pseudo
2483 states are using the message queue to forward events out of a submachine,
2484 the <code>no_message_queue</code> option cannot be used with state machines
2485 containing an exit pseudo state.</para>
2486 </sect2>
2487 <sect2>
2488 <title>Completion / Anonymous transitions</title>
2489 <para>Anonymous transitions (See <command xlink:href="#uml-anonymous">UML
2490 tutorial</command>) are transitions without a named event, which are
2491 therefore triggered immediately when the source state becomes active,
2492 provided a guard allows it. As there is no event, to define such a
2493 transition, simply omit the “+” part of the transition (the event), for
2494 example: </para>
2495 <programlisting>State3 == State4 [always_true] / State3ToState4
2496 State4 [always_true] / State3ToState4 == State3</programlisting>
2497 <para>Please have a look at <link
2498 xlink:href="examples/AnonymousTutorialEuml.cpp">this example</link>,
2499 which implements the <command xlink:href="#anonymous-transitions">previously
2500 defined</command> state machine with eUML.</para>
2501 </sect2>
2502 <sect2>
2503 <title><command xml:id="eUML-internal"/>Internal transitions</title>
2504 <para>Like both other front-ends, eUML supports two ways of defining internal transitions:<itemizedlist>
2505 <listitem>
2506 <para>in the state machine's transition table. In this case, you
2507 need to specify a source state, event, actions and guards but no
2508 target state, which eUML will interpret as an internal
2509 transition, for example this defines a transition internal to
2510 Open, on the event open_close:</para>
2511 <programlisting>Open + open_close [internal_guard1] / internal_action1</programlisting>
2512 <para><link xlink:href="examples/EumlInternal.cpp">A full
2513 example</link> is also provided.</para>
2514 </listitem>
2515 <listitem>
2516 <para>in a state's <code>internal_transition_table</code>. For
2517 example:</para>
2518 <programlisting>BOOST_MSM_EUML_DECLARE_STATE((Open_Entry,Open_Exit),Open_def)
2519 struct Open_impl : public Open_def
2520 {
2521 BOOST_MSM_EUML_DECLARE_INTERNAL_TRANSITION_TABLE((
2522 open_close [internal_guard1] / internal_action1
2523 ))
2524 };</programlisting>
2525 <para>Notice how we do not need to repeat that the transition
2526 originates from Open as we already are in Open's context. </para>
2527 <para>The <link xlink:href="examples/EumlInternalDistributed.cpp"
2528 >implementation</link> also shows the added bonus offered
2529 for submachines, which can have both the standard
2530 transition_table and an internal_transition_table (which has
2531 higher priority). This makes it easier if you decide to make a
2532 full submachine from a state. It is also slightly faster than
2533 the standard alternative, adding orthogonal regions, because
2534 event dispatching will, if accepted by the internal table, not
2535 continue to the subregions. This gives you a O(1) dispatch
2536 instead of O(number of regions).</para>
2537 </listitem>
2538 </itemizedlist></para>
2539 </sect2>
2540 <sect2>
2541 <title><command xml:id="kleene-event"/>Kleene(any) event)</title>
2542 <para>As for the functor front-end, eUML supports the concept of an <emphasis
2543 role="italic"><command xlink:href="#any-event">any</command></emphasis>
2544 event, but boost::any is not an acceptable eUML terminal. If you need an
2545 <emphasis role="italic">any</emphasis> event, use
2546 msm::front::euml::kleene, which inherits boost::any. The same transition as
2547 with boost:any would be: </para>
2548 <programlisting>State1 + kleene == State2</programlisting>
2549 </sect2>
2550 <sect2>
2551 <title>Other state types</title>
2552 <para>We saw the <command xlink:href="#eUML-build-state">build_state</command>
2553 function, which creates a simple state. Likewise, eUML provides other
2554 state-building macros for other types of states:<itemizedlist>
2555 <listitem>
2556 <para>BOOST_MSM_EUML_TERMINATE_STATE takes the same arguments as
2557 BOOST_MSM_EUML_STATE and defines, well, a terminate
2558 state.</para>
2559 </listitem>
2560 <listitem>
2561 <para>BOOST_MSM_EUML_INTERRUPT_STATE takes the same arguments as
2562 BOOST_MSM_EUML_STATE and defines an interrupt state. However,
2563 the expression argument must contain as first element the event
2564 ending the interruption, for example:
2565 <code>BOOST_MSM_EUML_INTERRUPT_STATE(( end_error /*end
2566 interrupt event*/,ErrorMode_Entry,ErrorMode_Exit
2567 ),ErrorMode)</code></para>
2568 </listitem>
2569 <listitem>
2570 <para>BOOST_MSM_EUML_EXIT_STATE takes the same arguments as
2571 BOOST_MSM_EUML_STATE and defines an exit pseudo state. However,
2572 the expression argument must contain as first element the event
2573 propagated from the exit point:
2574 <code>BOOST_MSM_EUML_EXIT_STATE(( event6 /*propagated
2575 event*/,PseudoExit1_Entry,PseudoExit1_Exit
2576 ),PseudoExit1)</code></para>
2577 </listitem>
2578 <listitem>
2579 <para>BOOST_MSM_EUML_EXPLICIT_ENTRY_STATE defines an entry pseudo
2580 state. It takes 3 parameters: the region index to be entered is
2581 defined as an int argument, followed by the configuration
2582 expression like BOOST_MSM_EUML_STATE and the state name, so that
2583 <code>BOOST_MSM_EUML_EXPLICIT_ENTRY_STATE(0 /*region
2584 index*/,( SubState2_Entry,SubState2_Exit ),SubState2)</code>
2585 defines an entry state into the first region of a
2586 submachine.</para>
2587 </listitem>
2588 <listitem>
2589 <para>BOOST_MSM_EUML_ENTRY_STATE defines an entry pseudo state. It
2590 takes 3 parameters: the region index to be entered is defined as
2591 an int argument, followed by the configuration expression like
2592 BOOST_MSM_EUML_STATE and the state name, so that
2593 <code>BOOST_MSM_EUML_ENTRY_STATE(0,(
2594 PseudoEntry1_Entry,PseudoEntry1_Exit ),PseudoEntry1)</code>
2595 defines a pseudo entry state into the first region of a
2596 submachine.</para>
2597 </listitem>
2598 </itemizedlist></para>
2599 <para>To use these states in the transition table, eUML offers the functions
2600 <code>explicit_</code>, <code>exit_pt_</code> and
2601 <code>entry_pt_</code>. For example, a direct entry into the substate
2602 SubState2 from SubFsm2 could be:</para>
2603 <programlisting>explicit_(SubFsm2,SubState2) == State1 + event2</programlisting>
2604 <para>Forks being a list on direct entries, eUML supports a logical syntax
2605 (state1, state2, ...), for example:</para>
2606 <programlisting>(explicit_(SubFsm2,SubState2),
2607 explicit_(SubFsm2,SubState2b),
2608 explicit_(SubFsm2,SubState2c)) == State1 + event3 </programlisting>
2609 <para>An entry point is entered using the same syntax as explicit entries:
2610 <programlisting>entry_pt_(SubFsm2,PseudoEntry1) == State1 + event4</programlisting></para>
2611 <para>For exit points, it is again the same syntax except that exit points are
2612 used as source of the transition:
2613 <programlisting>State2 == exit_pt_(SubFsm2,PseudoExit1) + event6 </programlisting></para>
2614 <para>The <link xlink:href="examples/DirectEntryEuml.cpp">entry tutorial</link>
2615 is also available with eUML.</para>
2616 </sect2>
2617 <sect2>
2618 <title>Helper functions</title>
2619 <para>We saw a few helpers but there are more, so let us have a more complete description:<itemizedlist>
2620 <listitem>
2621 <para>event_ : used inside any action, the event triggering the
2622 transition</para>
2623 </listitem>
2624 <listitem>
2625 <para>state_: used inside entry and exit actions, the entered /
2626 exited state</para>
2627 </listitem>
2628 <listitem>
2629 <para>source_: used inside a transition action, the source
2630 state</para>
2631 </listitem>
2632 <listitem>
2633 <para>target_: used inside a transition action, the target
2634 state</para>
2635 </listitem>
2636 <listitem>
2637 <para>fsm_: used inside any action, the (deepest-level) state
2638 machine processing the transition</para>
2639 </listitem>
2640 <listitem>
2641 <para>These objects can also be used as a function and return an
2642 attribute, for example event_(cd_name)</para>
2643 </listitem>
2644 <listitem>
2645 <para>Int_&lt;int value>: a functor representing an int</para>
2646 </listitem>
2647 <listitem>
2648 <para>Char_&lt;value>: a functor representing a char</para>
2649 </listitem>
2650 <listitem>
2651 <para>Size_t_&lt;value>: a functor representing a size_t</para>
2652 </listitem>
2653 <listitem>
2654 <para>True_ and False_ functors returning true and false
2655 respectively</para>
2656 </listitem>
2657 <listitem>
2658 <para>String_&lt;mpl::string> (boost >= 1.40): a functor
2659 representing a string.</para>
2660 </listitem>
2661 <listitem>
2662 <para>if_then_else_(guard, action, action) where action can be an
2663 action sequence</para>
2664 </listitem>
2665 <listitem>
2666 <para>if_then_(guard, action) where action can be an action
2667 sequence</para>
2668 </listitem>
2669 <listitem>
2670 <para>while_(guard, action) where action can be an action
2671 sequence</para>
2672 </listitem>
2673 <listitem>
2674 <para>do_while_(guard, action) where action can be an action
2675 sequence</para>
2676 </listitem>
2677 <listitem>
2678 <para>for_(action, guard, action, action) where action can be an
2679 action sequence</para>
2680 </listitem>
2681 <listitem>
2682 <para>process_(some_event [, some state machine] [, some state
2683 machine] [, some state machine] [, some state machine]) will
2684 call process_event (some_event) on the current state machine or
2685 on the one(s) passed as 2nd , 3rd, 4th, 5th argument. This allow
2686 sending events to several external machines</para>
2687 </listitem>
2688 <listitem>
2689 <para>process_(event_): reprocesses the event which triggered the
2690 transition</para>
2691 </listitem>
2692 <listitem>
2693 <para>reprocess_(): same as above but shorter to write</para>
2694 </listitem>
2695 <listitem>
2696 <para>process2_(some_event,Value [, some state machine] [, some
2697 state machine] [, some state machine]) will call process_event
2698 (some_event(Value)) on the current state machine or on the
2699 one(s) passed as 3rd, 4th, 5th argument</para>
2700 </listitem>
2701 <listitem>
2702 <para>is_ flag_(some_flag[, some state machine]) will call
2703 is_flag_active on the current state machine or on the one passed
2704 as 2nd argument</para>
2705 </listitem>
2706 <listitem>
2707 <para>Predicate_&lt;some predicate>: Used in STL algorithms. Wraps
2708 unary/binary functions to make them eUML-compatible so that they
2709 can be used in STL algorithms</para>
2710 </listitem>
2711 </itemizedlist></para>
2712 <para>This can be quite fun. For example, </para>
2713 <programlisting>/( if_then_else_(--fsm_(m_SongIndex) > Int_&lt;0>(),/*if clause*/
2714 show_playing_song, /*then clause*/
2715 (fsm_(m_SongIndex)=Int_&lt;1>(),process_(EndPlay))/*else clause*/
2716 )
2717 )</programlisting>
2718 <para>means: if (fsm.SongIndex > 0, call show_playing_song else
2719 {fsm.SongIndex=1; process EndPlay on fsm;}</para>
2720 <para>A few examples are using these features:<itemizedlist>
2721 <listitem>
2722 <para>the iPod example introduced at the BoostCon09 <link
2723 xlink:href="examples/iPodEuml.cpp">has been rewritten</link>
2724 with eUML (weak compilers please move on...)</para>
2725 </listitem>
2726 <listitem>
2727 <para>the iPodSearch example also introduced at the BoostCon09 <link
2728 xlink:href="examples/iPodSearchEuml.cpp">has been
2729 rewritten</link> with eUML. In this example, you will also
2730 find some examples of STL functor usage.</para>
2731 </listitem>
2732 <listitem>
2733 <para><link xlink:href="examples/SimpleTimer.cpp">A simpler
2734 timer</link> example is a good starting point. </para>
2735 </listitem>
2736 </itemizedlist></para>
2737 <para>There is unfortunately a small catch. Defining a functor using
2738 MSM_EUML_METHOD or MSM_EUML_FUNCTION will create a correct functor. Your own
2739 eUML functors written as described at the beginning of this section will
2740 also work well, <emphasis role="underline">except</emphasis>, for the
2741 moment, with the while_, if_then_, if_then_else_ functions.</para>
2742 </sect2>
2743 <sect2>
2744 <title>Phoenix-like STL support</title>
2745 <para>eUML supports most C++ operators (except address-of). For example it is
2746 possible to write event_(some_attribute)++ or [source_(some_bool) &amp;&amp;
2747 fsm_(some_other_bool)]. But a programmer needs more than operators in his
2748 daily programming. The STL is clearly a must have. Therefore, eUML comes in
2749 with a lot of functors to further reduce the need for your own functors for
2750 the transition table. For almost every algorithm or container method of the
2751 STL, a corresponding eUML function is defined. Like Boost.Phoenix, “.” And
2752 “->” of call on objects are replaced by a functional programming paradigm,
2753 for example:<itemizedlist>
2754 <listitem>
2755 <para>begin_(container), end_(container): return iterators of a
2756 container.</para>
2757 </listitem>
2758 <listitem>
2759 <para>empty_(container): returns container.empty()</para>
2760 </listitem>
2761 <listitem>
2762 <para>clear_(container): container.clear()</para>
2763 </listitem>
2764 <listitem>
2765 <para>transform_ : std::transform</para>
2766 </listitem>
2767 </itemizedlist></para>
2768 <para>In a nutshell, almost every STL method or algorithm is matched by a
2769 corresponding functor, which can then be used in the transition table or
2770 state actions. The <link xlink:href="#Reference-begin">reference</link>
2771 lists all eUML functions and the underlying functor (so that this
2772 possibility is not reserved to eUML but also to the functor-based
2773 front-end). The file structure of this Phoenix-like library matches the one
2774 of Boost.Phoenix. All functors for STL algorithms are to be found in:</para>
2775 <programlisting>#include &lt;msm/front/euml/algorithm.hpp></programlisting>
2776 <para>The algorithms are also divided into sub-headers, matching the phoenix
2777 structure for simplicity:</para>
2778 <programlisting>#include &lt; msm/front/euml/iteration.hpp>
2779 #include &lt; msm/front/euml/transformation.hpp>
2780 #include &lt; msm/front/euml/querying.hpp> </programlisting>
2781 <para>Container methods can be found in:</para>
2782 <programlisting>#include &lt; msm/front/euml/container.hpp></programlisting>
2783 <para>Or one can simply include the whole STL support (you will also need to
2784 include euml.hpp):</para>
2785 <programlisting>#include &lt; msm/front/euml/stl.hpp></programlisting>
2786 <para>A few examples (to be found in <link
2787 xlink:href="examples/iPodSearchEuml.cpp">this tutorial</link>):<itemizedlist>
2788 <listitem>
2789 <para><code>push_back_(fsm_(m_tgt_container),event_(m_song))</code>:
2790 the state machine has an attribute m_tgt_container of type
2791 std::vector&lt;OneSong> and the event has an attribute m_song of
2792 type OneSong. The line therefore pushes m_song at the end of
2793 m_tgt_container</para>
2794 </listitem>
2795 <listitem>
2796 <para><code>if_then_( state_(m_src_it) !=
2797 end_(fsm_(m_src_container)),
2798 process2_(OneSong(),*(state_(m_src_it)++)) )</code>: the
2799 current state has an attribute m_src_it (an iterator). If this
2800 iterator != fsm.m_src_container.end(), process OneSong on fsm,
2801 copy-constructed from state.m_src_it which we
2802 post-increment</para>
2803 </listitem>
2804 </itemizedlist></para>
2805 </sect2>
2806 <sect2>
2807 <title><command xml:id="eUML-phoenix"/>Writing actions with Boost.Phoenix (in development)</title>
2808 <para> It is also possible to write actions, guards, state entry and exit
2809 actions using a reduced set of Boost.Phoenix capabilities. This feature
2810 is still in development stage, so you might get here and there some
2811 surprise. Simple cases, however, should work well. What will not work
2812 will be mixing of eUML and Phoenix functors. Writing guards in one
2813 language and actions in another is ok though.</para>
2814 <para>Phoenix also supports a larger syntax than what will ever be possible
2815 with eUML, so you can only use a reduced set of phoenix's grammar. This
2816 is due to the nature of eUML. The run-time transition table definition
2817 is translated to a type using Boost.Typeof. The result is a "normal" MSM
2818 transition table made of functor types. As C++ does not allow mixing
2819 run-time and compile-time constructs, there will be some limit (trying
2820 to instantiate a template class MyTemplateClass&lt;i> where i is an int
2821 will give you an idea). This means following valid Phoenix constructs
2822 will not work:</para>
2823 <para>
2824 <itemizedlist>
2825 <listitem>
2826 <para>literals</para>
2827 </listitem>
2828 <listitem>
2829 <para>function pointers</para>
2830 </listitem>
2831 <listitem>
2832 <para>bind</para>
2833 </listitem>
2834 <listitem>
2835 <para>->*</para>
2836 </listitem>
2837 </itemizedlist>
2838 </para>
2839 <para>MSM also provides placeholders which make more sense in its context
2840 than arg1.. argn:</para>
2841 <para>
2842 <itemizedlist>
2843 <listitem>
2844 <para>_event: the event triggering the transition</para>
2845 </listitem>
2846 <listitem>
2847 <para>_fsm: the state machine processing the event</para>
2848 </listitem>
2849 <listitem>
2850 <para>_source: the source state of the transition</para>
2851 </listitem>
2852 <listitem>
2853 <para>_target: the target state of the transition</para>
2854 </listitem>
2855 <listitem>
2856 <para>_state: for state entry/exit actions, the entry/exit
2857 state</para>
2858 </listitem>
2859 </itemizedlist>
2860 </para>
2861 <para>Future versions of MSM will support Phoenix better. You can contribute
2862 by finding out cases which do not work but should, so that they can be
2863 added.</para>
2864 <para>Phoenix support is not activated by default. To activate it, add
2865 before any MSM header: #define BOOST_MSM_EUML_PHOENIX_SUPPORT.</para>
2866 <para>A <link
2867 xlink:href="examples/SimplePhoenix.cpp">simple example</link> shows some basic capabilities.</para>
2868 </sect2>
2869 </sect1>
2870 <sect1>
2871 <title>Back-end</title>
2872 <para>There is, at the moment, one back-end. This back-end contains the library
2873 engine and defines the performance and functionality trade-offs. The currently
2874 available back-end implements most of the functionality defined by the UML 2.0
2875 standard at very high runtime speed, in exchange for longer compile-time. The
2876 runtime speed is due to a constant-time double-dispatch and self-adapting
2877 capabilities allowing the framework to adapt itself to the features used by a
2878 given concrete state machine. All unneeded features either disable themselves or
2879 can be manually disabled. See section 5.1 for a complete description of the
2880 run-to-completion algorithm.</para>
2881 <sect2>
2882 <title>Creation </title>
2883 <para>MSM being divided between front and back-end, one needs to first define a
2884 front-end. Then, to create a real state machine, the back-end must be
2885 declared:
2886 <programlisting>typedef msm::back::state_machine&lt;my_front_end> my_fsm;</programlisting></para>
2887 <para>We now have a fully functional state machine type. The next sections will
2888 describe what can be done with it.</para>
2889 </sect2>
2890 <sect2>
2891 <title><command xml:id="backend-start"/>Starting and stopping a state
2892 machine</title>
2893 <para>The <code>start()</code> method starts the state machine, meaning it will
2894 activate the initial state, which means in turn that the initial state's
2895 entry behavior will be called. We need the start method because you do not
2896 always want the entry behavior of the initial state to be called immediately
2897 but only when your state machine is ready to process events. A good example
2898 of this is when you use a state machine to write an algorithm and each loop
2899 back to the initial state is an algorithm call. Each call to start will make
2900 the algorithm run once. The <link xlink:href="examples/iPodSearch.cpp"
2901 >iPodSearch</link> example uses this possibility.</para>
2902 <para>The <code>stop()</code> method works the same way. It will cause the exit
2903 actions of the currently active states(s) to be called.</para>
2904 <para>Both methods are actually not an absolute need. Not calling them will
2905 simply cause your first entry or your last exit action not to be
2906 called.</para>
2907 </sect2>
2908 <sect2>
2909 <title>Event dispatching</title>
2910 <para>The main reason to exist for a state machine is to dispatch events. For
2911 MSM, events are objects of a given event type. The object itself can contain
2912 data, but the event type is what decides of the transition to be taken. For
2913 MSM, if some_event is a given type (a simple struct for example) and e1 and
2914 e2 concrete instances of some_event, e1 and e2 are equivalent, from a
2915 transition perspective. Of course, e1 and e2 can have different values and
2916 you can use them inside actions. Events are dispatched as const reference,
2917 so actions cannot modify events for obvious side-effect reasons. To dispatch
2918 an event of type some_event, you can simply create one on the fly or
2919 instantiate if before processing: </para>
2920 <programlisting>my_fsm fsm; fsm.process_event(some_event());
2921 some_event e1; fsm.process_event(e1)</programlisting>
2922 <para>Creating an event on the fly will be optimized by the compiler so the
2923 performance will not degrade.</para>
2924 </sect2>
2925 <sect2>
2926 <title>Active state(s)</title>
2927 <para>The backend also offers a way to know which state is active, though you
2928 will normally only need this for debugging purposes. If what you need simply
2929 is doing something with the active state, <command
2930 xlink:href="#UML-internal-transition">internal transitions</command> or
2931 <command xlink:href="#backend-visitor">visitors</command> are a better
2932 alternative. If you need to know what state is active, const int*
2933 current_state() will return an array of state ids. Please refer to the
2934 <command xlink:href="#internals-state-id">internals section</command> to
2935 know how state ids are generated.</para>
2936 </sect2>
2937 <sect2>
2938 <title><command xml:id="back-end-serialization"/>Serialization</title>
2939 <para>A common need is the ability to save a state machine and restore it at a
2940 different time. MSM supports this feature for the basic and functor
2941 front-ends, and in a more limited manner for eUML. MSM supports
2942 boost::serialization out of the box (by offering a <code>serialize</code>
2943 function). Actually, for basic serialization, you need not do much, a MSM
2944 state machine is serializable almost like any other type. Without any
2945 special work, you can make a state machine remember its state, for
2946 example:</para>
2947 <para>
2948 <programlisting>MyFsm fsm;
2949 // write to archive
2950 std::ofstream ofs("fsm.txt");
2951 // save fsm to archive
2952 {
2953 boost::archive::text_oarchive oa(ofs);
2954 // write class instance to archive
2955 oa &lt;&lt; fsm;
2956 } </programlisting>
2957 </para>
2958 <para>Loading back is very similar:</para>
2959 <para>
2960 <programlisting>MyFsm fsm;
2961 {
2962 // create and open an archive for input
2963 std::ifstream ifs("fsm.txt");
2964 boost::archive::text_iarchive ia(ifs);
2965 // read class state from archive
2966 ia >> fsm;
2967 } </programlisting>
2968 </para>
2969 <para>This will (de)serialize the state machine itself but not the concrete
2970 states' data. This can be done on a per-state basis to reduce the amount of
2971 typing necessary. To allow serialization of a concrete state, provide a
2972 do_serialize typedef and implement the serialize function:</para>
2973 <para>
2974 <programlisting>struct Empty : public msm::front::state&lt;>
2975 {
2976 // we want Empty to be serialized. First provide the typedef
2977 typedef int do_serialize;
2978 // then implement serialize
2979 template&lt;class Archive>
2980 void serialize(Archive &amp; ar, const unsigned int /* version */)
2981 {
2982 ar &amp; some_dummy_data;
2983 }
2984 Empty():some_dummy_data(0){}
2985 int some_dummy_data;
2986 }; </programlisting>
2987 </para>
2988 <para>You can also serialize data contained in the front-end class. Again, you
2989 need to provide the typedef and implement serialize:</para>
2990 <para>
2991 <programlisting>struct player_ : public msm::front::state_machine_def&lt;player_>
2992 {
2993 //we might want to serialize some data contained by the front-end
2994 int front_end_data;
2995 player_():front_end_data(0){}
2996 // to achieve this, provide the typedef
2997 typedef int do_serialize;
2998 // and implement serialize
2999 template&lt;class Archive>
3000 void serialize(Archive &amp; ar, const unsigned int )
3001 {
3002 ar &amp; front_end_data;
3003 }
3004 ...
3005 }; </programlisting>
3006 </para>
3007 <para>The saving of the back-end data (the current state(s)) is valid for all
3008 front-ends, so a front-end written using eUML can be serialized. However, to
3009 serialize a concrete state, the macros like
3010 <code>BOOST_MSM_EUML_STATE</code> cannot be used, so the state will have
3011 to be implemented by directly inheriting from
3012 <code>front::euml::euml_state</code>.</para>
3013 <para>The only limitiation is that the event queues cannot be serialized so
3014 serializing must be done in a stable state, when no event is being
3015 processed. You can serialize during event processing only if using no queue
3016 (deferred or event queue).</para>
3017 <para>This <link
3018 xlink:href="examples/Serialize.cpp">example</link> shows a state machine which we serialize after processing an
3019 event. The <code>Empty</code> state also has some data to serialize.</para>
3020 </sect2>
3021 <sect2>
3022 <title><command xml:id="backend-base-state"/>Base state type </title>
3023 <para>Sometimes, one needs to customize states to avoid repetition and provide a
3024 common functionality, for example in the form of a virtual method. You might
3025 also want to make your states polymorphic so that you can call typeid on
3026 them for logging or debugging. It is also useful if you need a visitor, like
3027 the next section will show. You will notice that all front-ends offer the
3028 possibility of adding a base type. Note that all states and state machines
3029 must have the same base state, so this could reduce reuse. For example,
3030 using the basic front end, you need to:<itemizedlist>
3031 <listitem>
3032 <para>Add the non-default base state in your msm::front::state&lt;>
3033 definition, as first template argument (except for
3034 interrupt_states for which it is the second argument, the first
3035 one being the event ending the interrupt), for example,
3036 my_base_state being your new base state for all states in a
3037 given state machine:
3038 <programlisting>struct Empty : public msm::front::state&lt;my_base_state></programlisting>
3039 Now, my_base_state is your new base state. If it has a virtual
3040 function, your states become polymorphic. MSM also provides a
3041 default polymorphic base type,
3042 <code>msm::front::polymorphic_state</code>
3043 </para>
3044 </listitem>
3045 <listitem>
3046 <para>Add the user-defined base state in the state machine frontend
3047 definition, as a second template argument, for example:
3048 <programlisting>struct player_ : public msm::front::state_machine&lt;player_,my_base_state> </programlisting></para>
3049 </listitem>
3050 </itemizedlist></para>
3051 <para>You can also ask for a state with a given id (which you might have gotten
3052 from current_state()) using <code>const base_state* get_state_by_id(int id)
3053 const</code> where base_state is the one you just defined. You can now
3054 do something polymorphically.</para>
3055 </sect2>
3056 <sect2>
3057 <title><command xml:id="backend-visitor"/>Visitor</title>
3058 <para>In some cases, having a pointer-to-base of the currently active states is
3059 not enough. You might want to call non-virtually a method of the currently
3060 active states. It will not be said that MSM forces the virtual keyword down
3061 your throat!</para>
3062 <para>To achieve this goal, MSM provides its own variation of a visitor pattern
3063 using the previously described user-defined state technique. If you add to
3064 your user-defined base state an <code>accept_sig</code> typedef giving the
3065 return value (unused for the moment) and parameters and provide an accept
3066 method with this signature, calling visit_current_states will cause accept
3067 to be called on the currently active states. Typically, you will also want
3068 to provide an empty default accept in your base state in order in order not
3069 to force all your states to implement accept. For example your base state
3070 could be:</para>
3071 <programlisting>struct my_visitable_state
3072 {
3073 // signature of the accept function
3074 typedef args&lt;void> accept_sig;
3075 // we also want polymorphic states
3076 virtual ~my_visitable_state() {}
3077 // default implementation for states who do not need to be visited
3078 void accept() const {}
3079 };</programlisting>
3080 <para>This makes your states polymorphic and visitable. In this case, accept is
3081 made const and takes no argument. It could also be:</para>
3082 <programlisting>struct SomeVisitor {…};
3083 struct my_visitable_state
3084 {
3085 // signature of the accept function
3086 typedef args&lt;void,SomeVisitor&amp;> accept_sig;
3087 // we also want polymorphic states
3088 virtual ~my_visitable_state() {}
3089 // default implementation for states who do not need to be visited
3090 void accept(SomeVisitor&amp;) const {}
3091 };</programlisting>
3092 <para>And now, <code>accept</code> will take one argument (it could also be
3093 non-const). By default, <code>accept</code> takes up to 2 arguments. To get
3094 more, set #define BOOST_MSM_VISITOR_ARG_SIZE to another value before
3095 including state_machine.hpp. For example:</para>
3096 <programlisting>#define BOOST_MSM_VISITOR_ARG_SIZE 3
3097 #include &lt;boost/msm/back/state_machine.hpp></programlisting>
3098 <para>Note that accept will be called on ALL active states <emphasis
3099 role="underline">and also automatically on sub-states of a
3100 submachine</emphasis>.</para>
3101 <para><emphasis role="underline">Important warning</emphasis>: The method
3102 visit_current_states takes its parameter by value, so if the signature of
3103 the accept function is to contain a parameter passed by reference, pass this
3104 parameter with a boost:ref/cref to avoid undesired copies or slicing. So,
3105 for example, in the above case, call:</para>
3106 <programlisting>SomeVisitor vis; sm.visit_current_states(boost::ref(vis));</programlisting>
3107 <para>This <link xlink:href="examples/SM-2Arg.cpp">example</link> uses a
3108 visiting function with 2 arguments.</para>
3109 </sect2>
3110 <sect2>
3111 <title>Flags</title>
3112 <para>Flags is a MSM-only concept, supported by all front-ends, which base
3113 themselves on the functions: </para>
3114 <programlisting>template &lt;class Flag> bool is_flag_active()
3115 template &lt;class Flag,class BinaryOp> bool is_flag_active()</programlisting>
3116 <para>These functions return true if the currently active state(s) support the
3117 Flag property. The first variant ORs the result if there are several
3118 orthogonal regions, the second one expects OR or AND, for example:</para>
3119 <programlisting>my_fsm.is_flag_active&lt;MyFlag>()
3120 my_fsm.is_flag_active&lt;MyFlag,my_fsm_type::Flag_OR>()</programlisting>
3121 <para>Please refer to the front-ends sections for usage examples.</para>
3122 </sect2>
3123 <sect2>
3124 <title>Getting a state</title>
3125 <para>It is sometimes necessary to have the client code get access to the
3126 states' data. After all, the states are created once for good and hang
3127 around as long as the state machine does so why not use it? You simply just
3128 need sometimes to get information about any state, even inactive ones. An
3129 example is if you want to write a coverage tool and know how many times a
3130 state was visited. To get a state, use the get_state method giving the state
3131 name, for example: </para>
3132 <programlisting>player::Stopped* tempstate = p.get_state&lt;player::Stopped*>();</programlisting>
3133 <para> or </para>
3134 <programlisting>player::Stopped&amp; tempstate2 = p.get_state&lt;player::Stopped&amp;>();</programlisting>
3135 <para>depending on your personal taste. </para>
3136 </sect2>
3137 <sect2>
3138 <title><command xml:id="backend-fsm-constructor-args"/> State machine constructor with arguments </title>
3139 <para>You might want to define a state machine with a non-default constructor.
3140 For example, you might want to write: </para>
3141 <programlisting>struct player_ : public msm::front::state_machine_def&lt;player_>
3142 {
3143 player_(int some_value){…}
3144 }; </programlisting>
3145 <para>This is possible, using the back-end as forwarding object: </para>
3146 <programlisting>typedef msm::back::state_machine&lt;player_ > player; player p(3);</programlisting>
3147 <para>The back-end will call the corresponding front-end constructor upon
3148 creation.</para>
3149 <para>You can pass arguments up to the value of the
3150 BOOST_MSM_CONSTRUCTOR_ARG_SIZE macro (currently 5) arguments. Change this
3151 value before including any header if you need to overwrite the default. </para>
3152 <para>You can also pass arguments by reference (or const-reference) using
3153 boost::ref (or boost::cref):</para>
3154 <programlisting>struct player_ : public msm::front::state_machine_def&lt;player_>
3155 {
3156 player_(SomeType&amp; t, int some_value){…}
3157 };
3158
3159 typedef msm::back::state_machine&lt;player_ > player;
3160 SomeType data;
3161 player p(boost::ref(data),3);
3162 </programlisting>
3163 <para>Normally, MSM default-constructs all its states or submachines. There are
3164 however cases where you might not want this. An example is when you use a
3165 state machine as submachine, and this submachine used the above defined
3166 constructors. You can add as first argument of the state machine constructor
3167 an expression where existing states are passed and copied:</para>
3168 <programlisting>player p( back::states_ &lt;&lt; state_1 &lt;&lt; ... &lt;&lt; state_n , boost::ref(data),3);</programlisting>
3169 <para>Where state_1..n are instances of some or all of the states of the state
3170 machine. Submachines being state machines, this can recurse, for example, if
3171 Playing is a submachine containing a state Song1 having itself a constructor
3172 where some data is passed:</para>
3173 <programlisting>player p( back::states_ &lt;&lt; Playing(back::states_ &lt;&lt; Song1(some_Song1_data)) ,
3174 boost::ref(data),3);</programlisting>
3175 <para>It is also possible to replace a given state by a new instance at any time
3176 using <code>set_states()</code> and the same syntax, for example:
3177 <programlisting>p.set_states( back::states_ &lt;&lt; state_1 &lt;&lt; ... &lt;&lt; state_n );</programlisting></para>
3178 <para>An <link xlink:href="examples/Constructor.cpp"
3179 >example</link> making intensive use of this capability is provided.</para>
3180 </sect2>
3181 <sect2>
3182 <title><command xml:id="backend-tradeof-rt-ct"/>Trading run-time speed for
3183 better compile-time / multi-TU compilation</title>
3184 <para>MSM is optimized for run-time speed at the cost of longer compile-time.
3185 This can become a problem with older compilers and big state machines,
3186 especially if you don't really care about run-time speed that much and would
3187 be satisfied by a performance roughly the same as most state machine
3188 libraries. MSM offers a back-end policy to help there. But before you try
3189 it, if you are using a VC compiler, deactivate the /Gm compiler option
3190 (default for debug builds). This option can cause builds to be 3 times
3191 longer... If the compile-time still is a problem, read further. MSM offers a
3192 policy which will speed up compiling in two main cases:<itemizedlist>
3193 <listitem>
3194 <para>many transition conflicts</para>
3195 </listitem>
3196 <listitem>
3197 <para>submachines</para>
3198 </listitem>
3199 </itemizedlist></para>
3200 <para>The back-end <code>msm::back::state_machine</code> has a policy argument
3201 (first is the front-end, then the history policy) defaulting to
3202 <code>favor_runtime_speed</code>. To switch to
3203 <code>favor_compile_time</code>, which is declared in
3204 <code>&lt;msm/back/favor_compile_time.hpp></code>, you need to:<itemizedlist>
3205 <listitem>
3206 <para>switch the policy to <code>favor_compile_time</code> for the
3207 main state machine (and possibly submachines)</para>
3208 </listitem>
3209 <listitem>
3210 <para>move the submachine declarations into their own header which
3211 includes
3212 <code>&lt;msm/back/favor_compile_time.hpp></code></para>
3213 </listitem>
3214 <listitem>
3215 <para>add for each submachine a cpp file including your header and
3216 calling a macro, which generates helper code, for
3217 example:</para>
3218 <programlisting>#include "mysubmachine.hpp"
3219 BOOST_MSM_BACK_GENERATE_PROCESS_EVENT(mysubmachine)</programlisting>
3220 </listitem>
3221 <listitem>
3222 <para>configure your compiler for multi-core compilation</para>
3223 </listitem>
3224 </itemizedlist></para>
3225 <para>You will now compile your state machine on as many cores as you have
3226 submachines, which will greatly speed up the compilation if you factor your
3227 state machine into smaller submachines.</para>
3228 <para>Independently, transition conflicts resolution will also be much
3229 faster.</para>
3230 <para>This policy uses boost.any behind the hood, which means that we will lose
3231 a feature which MSM offers with the default policy, <link
3232 xlink:href="#event-hierarchy">event hierarchy</link>. The following
3233 example takes our iPod example and speeds up compile-time by using this
3234 technique. We have:<itemizedlist>
3235 <listitem>
3236 <para><link xlink:href="examples/iPod_distributed/iPod.cpp">our main
3237 state machine and main function</link></para>
3238 </listitem>
3239 <listitem>
3240 <para><link xlink:href="examples/iPod_distributed/PlayingMode.hpp"
3241 >PlayingMode moved to a separate header</link></para>
3242 </listitem>
3243 <listitem>
3244 <para><link xlink:href="examples/iPod_distributed/PlayingMode.cpp">a
3245 cpp for PlayingMode</link></para>
3246 </listitem>
3247 <listitem>
3248 <para><link xlink:href="examples/iPod_distributed/MenuMode.hpp"
3249 >MenuMode moved to a separate header</link></para>
3250 </listitem>
3251 <listitem>
3252 <para><link xlink:href="examples/iPod_distributed/MenuMode.cpp">a
3253 cpp for MenuMode</link></para>
3254 </listitem>
3255 <listitem>
3256 <para><link xlink:href="examples/iPod_distributed/Events.hpp">events
3257 move to a separate header as all machines use
3258 it</link></para>
3259 </listitem>
3260 </itemizedlist>
3261 </para>
3262 </sect2>
3263 <sect2>
3264 <title><command xml:id="backend-compile-time-analysis"/>Compile-time state machine analysis </title>
3265 <para>A MSM state machine being a metaprogram, it is only logical that cheking
3266 for the validity of a concrete state machine happens compile-time. To this
3267 aim, using the compile-time graph library <link xlink:href="http://www.dynagraph.org/mpl_graph/">mpl_graph</link> (delivered at the moment
3268 with MSM) from Gordon Woodhull, MSM provides several compile-time checks:<itemizedlist>
3269 <listitem>
3270 <para>Check that orthogonal regions ar truly orthogonal.</para>
3271 </listitem>
3272 <listitem>
3273 <para>Check that all states are either reachable from the initial
3274 states or are explicit entries / pseudo-entry states.</para>
3275 </listitem>
3276 </itemizedlist></para>
3277 <para>To make use of this feature, the back-end provides a policy (default is no
3278 analysis), <code>msm::back::mpl_graph_fsm_check</code>. For example:</para>
3279 <programlisting> typedef msm::back::state_machine&lt; player_,msm::back::mpl_graph_fsm_check> player; </programlisting>
3280 <para>As MSM is now using Boost.Parameter to declare policies, the policy choice
3281 can be made at any position after the front-end type (in this case
3282 <code>player_</code>).</para>
3283 <para>In case an error is detected, a compile-time assertion is provoked.</para>
3284 <para>This feature is not enabled by default because it has a non-neglectable
3285 compile-time cost. The algorithm is linear if no explicit or pseudo entry
3286 states are found in the state machine, unfortunately still O(number of
3287 states * number of entry states) otherwise. This will be improved in future
3288 versions of MSM.</para>
3289 <para>The same algorithm is also used in case you want to omit providing the
3290 region index in the <command xlink:href="#explicit-entry-no-region-id">explicit entry / pseudo entry state</command> declaration.</para>
3291 <para>The author's advice is to enable the checks after any state machine
3292 structure change and disable it again after sucessful analysis.</para>
3293 <para>The <link xlink:href="examples/TestErrorOrthogonality.cpp">following example</link> provokes an assertion if one of the first two lines
3294 of the transition table is used.</para>
3295 </sect2>
3296 <sect2>
3297 <title><command xml:id="backend-enqueueing"/> Enqueueing events for later
3298 processing </title>
3299 <para>Calling <code>process_event(Event const&amp;)</code> will immediately
3300 process the event with run-to-completion semantics. You can also enqueue the
3301 events and delay their processing by calling <code>enqueue_event(Event
3302 const&amp;)</code> instead. Calling <code>execute_queued_events()</code>
3303 will then process all enqueued events (in FIFO order). Calling
3304 <code>execute_single_queued_event()</code> will execute the oldest
3305 enqueued event.</para>
3306 <para>You can query the queue size by calling <code>get_message_queue_size()</code>.</para>
3307 </sect2>
3308 <sect2>
3309 <title><command xml:id="backend-queues"/> Customizing the message queues </title>
3310 <para>MSM uses by default a std::deque for its queues (one message queue for
3311 events generated during run-to-completion or with
3312 <code>enqueue_event</code>, one for deferred events). Unfortunately, on some
3313 STL implementations, it is a very expensive container in size and copying
3314 time. Should this be a problem, MSM offers an alternative based on
3315 boost::circular_buffer. The policy is msm::back::queue_container_circular.
3316 To use it, you need to provide it to the back-end definition:</para>
3317 <programlisting> typedef msm::back::state_machine&lt; player_,msm::back::queue_container_circular> player; </programlisting>
3318 <para>You can access the queues with get_message_queue and get_deferred_queue,
3319 both returning a reference or a const reference to the queues themselves.
3320 Boost::circular_buffer is outside of the scope of this documentation. What
3321 you will however need to define is the queue capacity (initially is 0) to
3322 what you think your queue will at most grow, for example (size 1 is
3323 common):</para>
3324 <programlisting> fsm.get_message_queue().set_capacity(1); </programlisting>
3325 </sect2>
3326 <sect2>
3327 <title><command xml:id="backend-boost-parameter"/>Policy definition with Boost.Parameter </title>
3328 <para>MSM uses Boost.Parameter to allow easier definition of
3329 back::state_machine&lt;> policy arguments (all except the front-end). This
3330 allows you to define policy arguments (history, compile-time / run-time,
3331 state machine analysis, container for the queues) at any position, in any
3332 number. For example: </para>
3333 <programlisting> typedef msm::back::state_machine&lt; player_,msm::back::mpl_graph_fsm_check> player;
3334 typedef msm::back::state_machine&lt; player_,msm::back::AlwaysHistory> player;
3335 typedef msm::back::state_machine&lt; player_,msm::back::mpl_graph_fsm_check,msm::back::AlwaysHistory> player;
3336 typedef msm::back::state_machine&lt; player_,msm::back::AlwaysHistory,msm::back::mpl_graph_fsm_check> player; </programlisting>
3337 </sect2>
3338 <sect2>
3339 <title><command xml:id="backend-state-switch"/>Choosing when to switch active
3340 states </title>
3341 <para>The UML Standard is silent about a very important question: when a
3342 transition fires, at which exact point is the target state the new active
3343 state of a state machine? At the end of the transition? After the source
3344 state has been left? What if an exception is thrown? The Standard considers
3345 that run-to-completion means a transition completes in almost no time. But
3346 even this can be in some conditions a very very long time. Consider the
3347 following example. We have a state machine representing a network
3348 connection. We can be <code>Connected</code> and <code>Disconnected</code>. When we move from one
3349 state to another, we send a (Boost) Signal to another entity. By default,
3350 MSM makes the target state as the new state after the transition is
3351 completed. We want to send a signal based on a flag is_connected which is
3352 true when in state Connected.</para>
3353 <para>We are in state <code>Disconnected</code> and receive an event <code>connect</code>. The transition
3354 action will ask the state machine <code>is_flag_active&lt;is_connected></code> and will
3355 get... false because we are still in <code>Disconnected</code>. Hmm, what to do? We could
3356 queue the action and execute it later, but it means an extra queue, more
3357 work and higher run-time.</para>
3358 <para>MSM provides the possibility (in form of a policy) for a front-end to
3359 decide when the target state becomes active. It can be:<itemizedlist>
3360 <listitem>
3361 <para>before the transition fires, if the guard will allow the
3362 transition to fire:
3363 <code>active_state_switch_before_transition</code></para>
3364 </listitem>
3365 <listitem>
3366 <para>after calling the exit action of the source state:
3367 <code>active_state_switch_after_exit</code></para>
3368 </listitem>
3369 <listitem>
3370 <para>after the transition action is executed:
3371 <code>active_state_switch_after_transition_action</code></para>
3372 </listitem>
3373 <listitem>
3374 <para>after the entry action of the target state is executed
3375 (default): <code>active_state_switch_after_entry</code></para>
3376 </listitem>
3377 </itemizedlist>The problem and the solution is shown for the
3378 <link xlink:href="examples/ActiveStateSetBeforeTransition.cpp">functor-front-end</link>
3379 and <link xlink:href="examples/ActivateStateBeforeTransitionEuml.cpp">eUML</link>. Removing <code>active_state_switch_before_transition</code>
3380 will show the default state. </para>
3381 </sect2>
3382 </sect1>
3383 </chapter>
3384 <chapter>
3385 <title> Performance / Compilers</title>
3386 <para>Tests were made on different PCs running Windows XP and Vista and compiled with
3387 VC9 SP1 or Ubuntu and compiled with g++ 4.2 and 4.3. For these tests, the same
3388 player state machine was written using Boost.Statechart, as a <link
3389 xlink:href="examples/SCSimple.cpp">state machine with only simple states</link>
3390 and as a <link xlink:href="examples/SCComposite.cpp">state machine with a composite
3391 state</link>. The same simple and composite state machines are implemented with
3392 MSM with a standard frontend <link xlink:href="examples/MsmSimple.cpp"
3393 >(simple)</link><link xlink:href="examples/MsmComposite.cpp">(composite)</link>,
3394 the simple one also with <link xlink:href="examples/MsmSimpleFunctors.cpp"
3395 >functors</link> and with <link xlink:href="examples/EumlSimple.cpp"
3396 >eUML</link>. As these simple machines need no terminate/interrupt states, no
3397 message queue and have no-throw guarantee on their actions, the MSM state machines
3398 are defined with minimum functionality. Test machine is a Q6600 2.4GHz, Vista
3399 64.</para>
3400 <sect1>
3401 <title>Speed</title>
3402 <para>VC9:<itemizedlist>
3403 <listitem>
3404 <para>The simple test completes 90 times faster with MSM than with
3405 Boost.Statechart</para>
3406 </listitem>
3407 <listitem>
3408 <para>The composite test completes 25 times faster with MSM</para>
3409 </listitem>
3410 </itemizedlist></para>
3411 <para>gcc 4.2.3 (Ubuntu 8.04 in VMWare, same PC):<itemizedlist>
3412 <listitem>
3413 <para>The simple test completes 46 times faster with MSM</para>
3414 </listitem>
3415 <listitem>
3416 <para>The composite test completes 19 times faster with Msm</para>
3417 </listitem>
3418 </itemizedlist></para>
3419 </sect1>
3420 <sect1>
3421 <title>Executable size</title>
3422 <para>There are some worries that MSM generates huge code. Is it true? The 2
3423 compilers I tested disagree with this claim. On VC9, the test state machines
3424 used in the performance section produce executables of 14kB (for simple and
3425 eUML) and 21kB (for the composite). This includes the test code and iostreams.
3426 By comparison, an empty executable with iostreams generated by VC9 has a size of
3427 7kB. Boost.Statechart generates executables of 43kB and 54kB. As a bonus, eUML
3428 comes for “free” in terms of executable size. You even get a speed gain. With
3429 g++ 4.3, it strongly depends on the compiler options (much more than VC). A good
3430 size state machine with –O3 can generate an executable of 600kB, and with eUML
3431 you can get to 1.5MB. Trying with –Os –s I come down to 18kB and 30kB for the
3432 test state machines, while eUML will go down to 1MB (which is still big), so in
3433 this case eUML does not come for free.</para>
3434 </sect1>
3435 <sect1>
3436 <title>Supported compilers</title>
3437 <para>For a current status, have a look at the <link
3438 xlink:href="http://www.boost.org/development/tests/trunk/developer/msm.html"
3439 >regression tests</link>.</para>
3440 <para>MSM was successfully tested with: <itemizedlist>
3441 <listitem>
3442 <para>VC8 (partly), VC9, VC10</para>
3443 </listitem>
3444 <listitem>
3445 <para>g++ 4.0.1 and higher</para>
3446 </listitem>
3447 <listitem>
3448 <para>Intel 10.1 and higher</para>
3449 </listitem>
3450 <listitem>
3451 <para>Clang 2.9</para>
3452 </listitem>
3453 <listitem>
3454 <para>Green Hills Software MULTI for ARM v5.0.5 patch 4416 (Simple and
3455 Composite tutorials)</para>
3456 </listitem>
3457 <listitem>
3458 <para>Partial support for IBM compiler</para>
3459 </listitem>
3460 </itemizedlist></para>
3461 <para>VC8 and to some lesser extent VC9 suffer from a bug. Enabling the option
3462 "Enable Minimal Rebuild" (/Gm) will cause much higher compile-time (up to three
3463 times with VC8!). This option being activated per default in Debug mode, this
3464 can be a big problem.</para>
3465 </sect1>
3466 <sect1>
3467 <title> Limitations </title>
3468 <para>
3469 <itemizedlist>
3470 <listitem>
3471 <para>Compilation times of state machines with > 80 transitions that are
3472 going to make you storm the CFO's office and make sure you get a
3473 shiny octocore with 12GB RAM by next week, unless he's interested in
3474 paying you watch the compiler agonize for hours... (Make sure you
3475 ask for dual 24" as well, it doesn't hurt).</para>
3476 </listitem>
3477 <listitem>
3478 <para>eUML allows very long constructs but will also quickly increase
3479 your compile time on some compilers (VC9, VC10) with buggy decltype
3480 support (I suspect some at least quadratic algorithms there). Even
3481 g++ 4.4 shows some regression compared to 4.3 and will crash if the
3482 constructs become too big.</para>
3483 </listitem>
3484 <listitem>
3485 <para>Need to overwrite the mpl::vector/list default-size-limit of 20
3486 and fusion default vector size of 10 if more than 10 states found in
3487 a state machine</para>
3488 </listitem>
3489 <listitem>
3490 <para><command xlink:href="#limitation-submachine">Limitation for
3491 submachines</command> and entry actions requiring an event
3492 property.</para>
3493 </listitem>
3494 </itemizedlist>
3495 </para>
3496 </sect1>
3497 <sect1>
3498 <title> Compilers corner </title>
3499 <para>Compilers are sometimes full of surprises and such strange errors happened in
3500 the course of the development that I wanted to list the most fun for readers’
3501 entertainment.</para>
3502 <para><emphasis role="underline">VC8</emphasis>: </para>
3503 <programlisting>template &lt;class StateType>
3504 typename ::boost::enable_if&lt;
3505 typename ::boost::mpl::and_&lt;
3506 typename ::boost::mpl::not_&lt;
3507 typename has_exit_pseudo_states&lt;StateType>::type
3508 >::type,
3509 typename ::boost::mpl::not_&lt;
3510 typename is_pseudo_exit&lt;StateType>::type
3511 >::type
3512 >::type,
3513 BaseState*>::type </programlisting>
3514 <para>I get the following error:</para>
3515 <para>error C2770: invalid explicit template argument(s) for '`global
3516 namespace'::boost::enable_if&lt;...>::...' </para>
3517 <para>If I now remove the first “::” in ::boost::mpl , the compiler shuts up. So in
3518 this case, it is not possible to follow Boost’s guidelines.</para>
3519 <para><emphasis role="underline">VC9</emphasis>:<itemizedlist>
3520 <listitem>
3521 <para>This one is my all times’ favorite. Do you know why the exit
3522 pseudo states are referenced in the transition table with a
3523 “submachine::exit_pt” ? Because “exit” will crash the compiler.
3524 “Exit” is not possible either because it will crash the compiler on
3525 one machine, but not on another (the compiler was installed from the
3526 same disk).</para>
3527 </listitem>
3528 <listitem>
3529 <para>Sometimes, removing a policy crashes the compiler, so some
3530 versions are defining a dummy policy called WorkaroundVC9.</para>
3531 </listitem>
3532 <listitem>
3533 <para>Typeof: While g++ and VC9 compile “standard” state machines in
3534 comparable times, Typeof (while in both ways natively supported)
3535 seems to behave in a quadratic complexity with VC9 and VC10.</para>
3536 </listitem>
3537 <listitem>
3538 <para>eUML: in case of a compiler crash, changing the order of state
3539 definitions (first states without entry or exit) sometimes solves
3540 the problem.</para>
3541 </listitem>
3542 </itemizedlist></para>
3543 <para><emphasis role="underline">g++ 4.x</emphasis>: Boring compiler, almost all is
3544 working almost as expected. Being not a language lawyer I am unsure about the
3545 following “Typeof problem”. VC9 and g++ disagree on the question if you can
3546 derive from the BOOST_TYPEOF generated type without first defining a typedef. I
3547 will be thankful for an answer on this. I only found two ways to break the compiler:<itemizedlist>
3548 <listitem>
3549 <para>Add more eUML constructs until something explodes (especially with
3550 g++-4.4) </para>
3551 </listitem>
3552 <listitem>
3553 <para>The build_terminate function uses 2 mpl::push_back instead of
3554 mpl::insert_range because g++ would not accept insert_range.</para>
3555 </listitem>
3556 </itemizedlist></para>
3557 <para>You can test your compiler’s decltype implementation with the <link
3558 xlink:href="examples/CompilerStressTestEuml.cpp">following stress
3559 test</link> and reactivate the commented-out code until the compiler
3560 crashes.</para>
3561 </sect1>
3562 </chapter>
3563 <chapter>
3564 <title>Questions &amp; Answers, tips</title>
3565 <para><emphasis role="underline">Where should I define a state machine?</emphasis>: The
3566 tutorials are implemented in a simple cpp source file for simplicity. I want to
3567 model dynamic behavior of a class as a state machine, how should I define the state
3568 machine?</para>
3569 <para><emphasis role="underline">Answer</emphasis>: Usually you'll want to implement the
3570 state machine as an attribute of the class. Unfortunately, a concrete state machine
3571 is a typedef, which cannot be forward-declared. This leaves you with two
3572 possibilities: <itemizedlist>
3573 <listitem>
3574 <para>Provide the state machine definition inside the header class and
3575 contain an instance as attribute. Simple, but with several drawbacks:
3576 using namespace directives are not advised, and compile-time cost for
3577 all modules including the header.</para>
3578 </listitem>
3579 <listitem>
3580 <para>Keep the state machine as (shared) pointer to void inside the <link
3581 xlink:href="examples/FsmAsPtr.hpp">class definition</link>, and
3582 implement the state machine in the <link
3583 xlink:href="examples/FsmAsPtr.cpp">cpp file</link>. Minimum
3584 compile-time, using directives are okay, but the state machine is now
3585 located inside the heap.</para>
3586 </listitem>
3587 </itemizedlist></para>
3588 <para><emphasis role="underline">Question</emphasis>: on_entry gets as argument, the
3589 sent event. What event do I get when the state becomes default-activated (because it
3590 is an initial state)?</para>
3591 <para>
3592 <emphasis role="underline">Answer</emphasis>: To allow you to know that the state
3593 was default-activated, MSM generates a boost::msm::InitEvent default event. </para>
3594 <para><emphasis role="underline">Question</emphasis>: Why do I see no call to
3595 no_transition in my submachine? </para>
3596 <para><emphasis role="underline">Answer</emphasis>: Because of the priority rule defined
3597 by UML. It says that in case of transition conflict, the most inner state has a
3598 higher priority. So after asking the inner state, the containing composite has to be
3599 also asked to handle the transition and could find a possible transition.</para>
3600 <para><emphasis role="underline">Question</emphasis>: Why do I get a compile error
3601 saying the compiler cannot convert to a function ...Fsm::*(some_event)? </para>
3602 <para><emphasis role="underline">Answer</emphasis>: You probably defined a transition
3603 triggered by the event some_event, but used a guard/action method taking another
3604 event. </para>
3605 <para><emphasis role="underline">Question</emphasis>: Why do I get a compile error
3606 saying something like “too few” or “too many” template arguments? </para>
3607 <para><emphasis role="underline">Answer</emphasis>: You probably defined a transition in
3608 form of a a_row or g_row where you wanted just a _row or the other way around. With
3609 Row, it could mean that you forgot a "none". </para>
3610 <para><emphasis role="underline">Question</emphasis>: Why do I get a very long compile
3611 error when I define more than 20 rows in the transition table? </para>
3612 <para><emphasis role="underline">Answer</emphasis>: MSM uses Boost.MPL under the hood
3613 and this is the default maximum size. Please define the following 3 macros before
3614 including any MSM headers: </para>
3615 <programlisting>#define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
3616 #define BOOST_MPL_LIMIT_VECTOR_SIZE 30 // or whatever you need
3617 #define BOOST_MPL_LIMIT_MAP_SIZE 30 // or whatever you need </programlisting>
3618 <para><emphasis role="underline">Question</emphasis>: Why do I get this error: ”error
3619 C2977: 'boost::mpl::vector' : too many template arguments”? </para>
3620 <para><emphasis role="underline">Answer</emphasis>: The first possibility is that you
3621 defined a transition table as, say, vector17 and have 18 entries. The second is that
3622 you have 17 entries and have a composite state. Under the hood, MSM adds a row for
3623 every event in the composite transition table. The third one is that you used a
3624 mpl::vector without the number of entries but are close to the MPL default of 50 and
3625 have a composite, thus pushing you above 50. Then you need mpl/vector60/70….hpp and
3626 a mpl/map60/70….hpp </para>
3627 <para><emphasis role="underline">Question</emphasis>: Why do I get a very long compile
3628 error when I define more than 10 states in a state machine? </para>
3629 <para><emphasis role="underline">Answer</emphasis>: MSM uses Boost.Fusion under the hood
3630 and this is the default maximum size. Please define the following macro before
3631 including any MSM headers: </para>
3632 <programlisting>#define FUSION_MAX_VECTOR_SIZE 20 // or whatever you need </programlisting>
3633 </chapter>
3634 <chapter>
3635 <title>Internals</title>
3636 <para>This chapter describes the internal machinery of the back-end, which can be useful
3637 for UML experts but can be safely ignored for most users. For implementers, the
3638 interface between front- and back- end is also described in detail.</para>
3639 <sect1>
3640 <title><command xml:id="run-to-completion"/>Backend: Run To Completion</title>
3641 <para>The back-end implements the following run-to completion algorithm:<itemizedlist>
3642 <listitem>
3643 <para>Check if one region of the concrete state machine is in a
3644 terminate or interrupt state. If yes, event processing is disabled
3645 while the condition lasts (forever for a terminate pseudo-state,
3646 while active for an interrupt pseudo-state).</para>
3647 </listitem>
3648 <listitem>
3649 <para>If the message queue feature is enabled and if the state machine
3650 is already processing an event, push the currently processed event
3651 into the queue and end processing. Otherwise, remember that the
3652 state machine is now processing an event and continue.</para>
3653 </listitem>
3654 <listitem>
3655 <para>If the state machine detected that no deferred event is used, skip
3656 this step. Otherwise, mark the first deferred event from the
3657 deferred queue as active.</para>
3658 </listitem>
3659 <listitem>
3660 <para>Now start the core of event dispatching. If exception handling is
3661 activated, this will happen inside a try/catch block and the
3662 front-end <code>exception_caught</code> is called if an exception
3663 occurs. </para>
3664 </listitem>
3665 <listitem>
3666 <para>The event is now dispatched in turn to every region, in the order
3667 defined by the initial state front-end definition. This will, for
3668 every region, call the corresponding front-end transition definition
3669 (the "row" or "Row" of the transition table).</para>
3670 </listitem>
3671 <listitem>
3672 <para>Without transition conflict, if for a given region a transition is
3673 possible, the guard condition is checked. If it returns
3674 <code>true</code>, the transition processing continues and the
3675 current state's exit action is called, followed by the transition
3676 action behavior and the new active state's entry behavior.</para>
3677 </listitem>
3678 <listitem>
3679 <para>With transition conflicts (several possible transitions,
3680 disambiguated by mutually exclusive guard conditions), the guard
3681 conditions are tried in reverse order of their transition definition
3682 in the transition table. The first one returning <code>true</code>
3683 selects its transition. Note that this is not defined by the UML
3684 standard, which simply specifies that if the guard conditions are
3685 not mutually exclusive, the state machine is ill-formed and the
3686 behaviour undefined. Relying on this implementation-specific
3687 behaviour will make it harder for the developer to support another
3688 state machine framework.</para>
3689 </listitem>
3690 <listitem>
3691 <para>If at least one region processes the event, this event is seen as
3692 having been accepted. If not, the library calls
3693 <code>no_transition</code> on the state machine for every
3694 contained region.</para>
3695 </listitem>
3696 <listitem>
3697 <para>If the currently active state is a submachine, the behaviour is
3698 slightly different. The UML standard specifies that internal
3699 transitions have to be tried first, so the event is first dispatched
3700 to the submachine. Only if the submachine does not accept the event
3701 are other (non internal) transitions tried.</para>
3702 </listitem>
3703 <listitem>
3704 <para>This back-end supports simple states' and submachines' internal
3705 transitions. These are provided in the state's
3706 <code>internal_transition_table</code> type. Transitions defined
3707 in this table are added at the end of the main state machine's
3708 transition table, but with a lesser priority than the submachine's
3709 transitions (defined in <code>transition_table</code>). This means,
3710 for simple states, that these transitions have higher priority than
3711 non-internal transitions, conform to the UML standard which gives
3712 higher priority to deeper-level transitions. For submachines, this
3713 is a non-standard addition which can help make event processing
3714 faster by giving a chance to bypass subregion processing. With
3715 standard UML, one would need to add a subregion only to process
3716 these internal transitions, which would be slower.</para>
3717 </listitem>
3718 <listitem>
3719 <para>After the dispatching itself, the deferred event marked in step 3
3720 (if any) now gets a chance of processing.</para>
3721 </listitem>
3722 <listitem>
3723 <para>Then, events queued in the message queue also get a dispatching
3724 chance</para>
3725 </listitem>
3726 <listitem>
3727 <para>Finally, completion / anonymous transitions, if to be found in the
3728 transition table, also get their dispatching chance.</para>
3729 </listitem>
3730 </itemizedlist></para>
3731 <para>This algorithm illustrates how the back-end configures itself at compile-time
3732 as much as possible. Every feature not found in a given state machine definition
3733 is deactivated and has therefore no runtime cost. Completion events, deferred
3734 events, terminate states, dispatching to several regions, internal transitions
3735 are all deactivated if not used. User configuration is only for exception
3736 handling and message queue necessary.</para>
3737 </sect1>
3738 <sect1>
3739 <title><command xml:id="internals-front-back-interface"/>Frontend / Backend
3740 interface</title>
3741 <para>The design of MSM tries to make front-ends and back-ends (later) to be as
3742 interchangeable as possible. Of course, no back-end will ever implement every
3743 feature defined by any possible front-end and inversely, but the goal is to make
3744 it as easy as possible to extend the current state of the library.</para>
3745 <para>To achieve this, MSM divides the functionality between both sides: the
3746 front-end is a sort of user interface and is descriptive, the back-end
3747 implements the state machine engine.</para>
3748 <para>MSM being based on a transition table, a concrete state machine (or a given
3749 front-end) must provide a transition_table. This transition table must be made
3750 of rows. And each row must tell what kind of transition it is and implement the
3751 calls to the actions and guards. A state machine must also define its regions
3752 (marked by initial states) And that is about the only constraints for
3753 front-ends. How the rows are described is implementer's choice. </para>
3754 <para>Every row must provide:</para>
3755 <itemizedlist>
3756 <listitem>
3757 <para>A <code>Source</code> typedef indicating, well, the type of the source
3758 state.</para>
3759 </listitem>
3760 <listitem>
3761 <para>A <code>Target</code> typedef indicating, well, the type of the target
3762 state.</para>
3763 </listitem>
3764 <listitem>
3765 <para>A <code>Evt</code> typedef indicating the type of the event triggering
3766 the transition.</para>
3767 </listitem>
3768 <listitem>
3769 <para>A <code>row_type_tag</code> typedef indicating the type of the
3770 transition.</para>
3771 </listitem>
3772 <listitem>
3773 <para>Rows having a type requiring transition actions must provide a static
3774 function <code>action_call</code> with the following signature: <code>
3775 template &lt;class Fsm,class SourceState,class TargetState,class
3776 AllStates> </code></para>
3777 <para><code>static void action_call (Fsm&amp; fsm, Event const&amp; evt,
3778 SourceState&amp;, TargetState&amp;, AllStates&amp;) </code></para>
3779 <para>The function gets as parameters the (back-end) state machine, the
3780 event, source and target states and a container (in the current
3781 back-end, a fusion::set) of all the states defined in the state machine.
3782 For example, as the back-end has the front-end as basic class,
3783 <code>action_call</code> is simply defined as
3784 <code>(fsm.*action)(evt)</code>.</para>
3785 </listitem>
3786 <listitem>
3787 <para>Rows having a type requiring a guard must provide a static function
3788 <code>guard_call</code> with the following signature:<code
3789 > </code></para>
3790 <para><code>template &lt;class Fsm,class SourceState,class TargetState,class
3791 AllStates></code></para>
3792 <para><code>static bool guard_call (Fsm&amp;, Event const&amp;,
3793 SourceState&amp;, TargetState&amp;, AllStates&amp;)</code></para>
3794 </listitem>
3795 <listitem>
3796 <para>The possible transition (row) types are:<itemizedlist>
3797 <listitem>
3798 <para>a_row_tag: a transition with actions and no guard</para>
3799 </listitem>
3800 <listitem>
3801 <para>g_row_type: a transition with a guard and no
3802 actions</para>
3803 </listitem>
3804 <listitem>
3805 <para>_row_tag: a transition without actions or guard</para>
3806 </listitem>
3807 <listitem>
3808 <para>row_tag: a transition with guard and actions</para>
3809 </listitem>
3810 <listitem>
3811 <para>a_irow_tag: an internal transition (defined inside the
3812 <code>transition_table</code>) with actions</para>
3813 </listitem>
3814 <listitem>
3815 <para>g_irow_tag: an internal transition (defined inside the
3816 <code>transition_table</code>) with guard</para>
3817 </listitem>
3818 <listitem>
3819 <para>irow_tag: an internal transition (defined inside the
3820 <code>transition_table</code>) with actions and
3821 guards</para>
3822 </listitem>
3823 <listitem>
3824 <para>_irow_tag: an internal transition (defined inside the
3825 <code>transition_table</code>) without action or guard.
3826 Due to higher priority for internal transitions, this is
3827 equivalent to a "ignore event"</para>
3828 </listitem>
3829 <listitem>
3830 <para>sm_a_i_row_tag: an internal transition (defined inside the
3831 <code>internal_transition_table</code>) with
3832 actions</para>
3833 </listitem>
3834 <listitem>
3835 <para>sm_g_i_row_tag: an internal transition (defined inside the
3836 <code>internal_transition_table</code>) with
3837 guard</para>
3838 </listitem>
3839 <listitem>
3840 <para>sm_i_row_tag: an internal transition (defined inside the
3841 <code>internal_transition_table</code>) with actions and
3842 guards</para>
3843 </listitem>
3844 <listitem>
3845 <para>sm__i_row_tag: an internal transition (defined inside the
3846 <code>internal_transition_table</code>) without action
3847 or guard. Due to higher priority for internal transitions,
3848 this is quivalent to a "ignore event"</para>
3849 </listitem>
3850 </itemizedlist></para>
3851 </listitem>
3852 </itemizedlist>
3853 <para>Furthermore, a front-end must provide the definition of states and state
3854 machines. State machine definitions must provide (the implementer is free to
3855 provide it or let it be done by every concrete state machine. Different MSM
3856 front-ends took one or the other approach):<itemizedlist>
3857 <listitem>
3858 <para><code>initial_state</code>: This typedef can be a single state or
3859 a mpl container and provides the initial states defining one or
3860 several orthogonal regions.</para>
3861 </listitem>
3862 <listitem>
3863 <para><code>transition_table</code>: This typedef is a MPL sequence of
3864 transition rows.</para>
3865 </listitem>
3866 <listitem>
3867 <para><code>configuration</code>: this typedef is a MPL sequence of
3868 known types triggering special behavior in the back-end, for example
3869 if a concrete fsm requires a message queue or exception
3870 catching.</para>
3871 </listitem>
3872 </itemizedlist></para>
3873 <para>States and state machines must both provide a (possibly empty) definition of:<itemizedlist>
3874 <listitem>
3875 <para><code>flag_list</code>: the flags being active when this state or
3876 state machine become the current state of the fsm.</para>
3877 </listitem>
3878 <listitem>
3879 <para><code>deferred_events</code>: events being automatically deferred
3880 when the state is the current state of the fsm.</para>
3881 </listitem>
3882 <listitem>
3883 <para><code>internal_transition_table</code>: the internal transitions
3884 of this state.</para>
3885 </listitem>
3886 <listitem>
3887 <para><code>on_entry</code> and <code>on_exit</code> methods.</para>
3888 </listitem>
3889 </itemizedlist></para>
3890 </sect1>
3891 <sect1>
3892 <title><command xml:id="internals-state-id"/> Generated state ids </title>
3893 <para>Normally, one does not need to know the ids are generated for all the states
3894 of a state machine, unless for debugging purposes, like the pstate function does
3895 in the tutorials in order to display the name of the current state. This section
3896 will show how to automatically display typeid-generated names, but these are not
3897 very readable on all platforms, so it can help to know how the ids are
3898 generated. The ids are generated using the transition table, from the “Start”
3899 column up to down, then from the “Next” column, up to down, as shown in the next
3900 image: </para>
3901 <para><inlinemediaobject>
3902 <imageobject>
3903 <imagedata fileref="images/AnnexA.jpg" width="90%" scalefit="1"/>
3904 </imageobject>
3905 </inlinemediaobject></para>
3906 <para>Stopped will get id 0, Open id 1, ErrorMode id 6 and SleepMode (seen only in
3907 the “Next” column) id 7. If you have some implicitly created states, like
3908 transition-less initial states or states created using the explicit_creation
3909 typedef, these will be added as a source at the end of the transition table. If
3910 you have submachine states, a row will be added for them at the end of the
3911 table, after the automatically or explicitly created states, which can change
3912 their id. The next help you will need for debugging would be to call the
3913 current_state method of the state_machine class, then the display_type helper to
3914 generate a readable name from the id. If you do not want to go through the
3915 transition table to fill an array of names, the library provides another helper,
3916 fill_state_names, which, given an array of sufficient size (please see next
3917 section to know how many states are defined in the state machine), will fill it
3918 with typeid-generated names. </para>
3919 </sect1>
3920 <sect1>
3921 <title>Metaprogramming tools</title>
3922 <para>We can find for the transition table more uses than what we have seen so far.
3923 Let's suppose you need to write a coverage tool. A state machine would be
3924 perfect for such a job, if only it could provide some information about its
3925 structure. Thanks to the transition table and Boost.MPL, it does.</para>
3926 <para>What is needed for a coverage tool? You need to know how many states are
3927 defined in the state machine, and how many events can be fired. This way you can
3928 log the fired events and the states visited in the life of a concrete machine
3929 and be able to perform some coverage analysis, like “fired 65% of all possible
3930 events and visited 80% of the states defined in the state machine”. To achieve
3931 this, MSM provides a few useful tools:<itemizedlist>
3932 <listitem>
3933 <para>generate_state_set&lt;transition table>: returns a mpl::set of all
3934 the states defined in the table.</para>
3935 </listitem>
3936 <listitem>
3937 <para>generate_event_set&lt;transition table>: returns a mpl::set of all
3938 the events defined in the table.</para>
3939 </listitem>
3940 <listitem>
3941 <para>using mpl::size&lt;>::value you can get the number of elements in
3942 the set.</para>
3943 </listitem>
3944 <listitem>
3945 <para>display_type defines an operator() sending typeid(Type).name() to
3946 cout.</para>
3947 </listitem>
3948 <listitem>
3949 <para>fill_state_names fills an array of char const* with names of all
3950 states (found by typeid)</para>
3951 </listitem>
3952 <listitem>
3953 <para>using mpl::for_each on the result of generate_state_set and
3954 generate_event_set passing display_type as argument will display all
3955 the states of the state machine.</para>
3956 </listitem>
3957 <listitem>
3958 <para>let's suppose you need to recursively find the states and events
3959 defined in the composite states and thus also having a transition
3960 table. Calling recursive_get_transition_table&lt;Composite> will
3961 return you the transition table of the composite state, recursively
3962 adding the transition tables of all sub-state machines and
3963 sub-sub...-sub-state machines. Then call generate_state_set or
3964 generate_event_set on the result to get the full list of states and
3965 events. </para>
3966 </listitem>
3967 </itemizedlist></para>
3968 <para> An <link xlink:href="examples/BoostCon09Full.cpp">example</link> shows the
3969 tools in action. </para>
3970 </sect1>
3971 </chapter>
3972 <chapter>
3973 <title>Acknowledgements</title>
3974 <para>I am in debt to the following people who helped MSM along the way.</para>
3975 <sect1>
3976 <title>MSM v2</title>
3977 <para>
3978 <itemizedlist>
3979 <listitem>
3980 <para>Thanks to Dave Abrahams for managing the review</para>
3981 </listitem>
3982 <listitem>
3983 <para>Thanks to Eric Niebler for his patience correcting my grammar
3984 errors</para>
3985 </listitem>
3986 <listitem>
3987 <para>Special thanks to Joel de Guzman who gave me very good ideas at
3988 the BoostCon09. These ideas were the starting point of the redesign.
3989 Any time again, Joel ☺</para>
3990 </listitem>
3991 <listitem>
3992 <para>Thanks to Richard O’Hara for making Green Hills bring a patch in
3993 less than 1 week, thus adding one more compiler to the supported
3994 list.</para>
3995 </listitem>
3996 <listitem>
3997 <para>Big thanks to those who took the time to write a review: Franz
3998 Alt, David Bergman, Michael Caisse, Barend Gehrels, Darryl Greene,
3999 Juraj Ivancic, Erik Nelson, Kenny Riddile.</para>
4000 </listitem>
4001 <listitem>
4002 <para>Thanks to Matt Calabrese, Juraj Ivancic, Adam Merz and Joseph Wu
4003 for reporting bugs.</para>
4004 </listitem>
4005 <listitem>
4006 <para>Thanks to Thomas Mistretta for providing an addition to the
4007 section "What do you actually do inside actions / guards".</para>
4008 </listitem>
4009 </itemizedlist>
4010 </para>
4011 </sect1>
4012 <sect1>
4013 <title> MSM v1</title>
4014 <para>
4015 <itemizedlist>
4016 <listitem>
4017 <para>The original version of this framework is based on the brilliant
4018 work of David Abrahams and Aleksey Gurtovoy who laid down the base
4019 and the principles of the framework in their excellent book, “C++
4020 template Metaprogramming”. The implementation also makes heavy use
4021 of the boost::mpl.</para>
4022 </listitem>
4023 <listitem>
4024 <para>Thanks to Jeff Flinn for his idea of the user-defined base state
4025 and his review which allowed MSM to be presented at the
4026 BoostCon09.</para>
4027 </listitem>
4028 <listitem>
4029 <para>Thanks to my MSM v1 beta testers, Christoph Woskowski and Franz
4030 Alt for using the framework with little documentation and to my
4031 private reviewer, Edouard Alligand</para>
4032 </listitem>
4033 </itemizedlist>
4034 </para>
4035 </sect1>
4036 </chapter>
4037 <chapter>
4038 <title>Version history</title>
4039 <sect1>
4040 <title>From V2.27 to V2.28 (Boost 1.57)</title>
4041 <para>
4042 <itemizedlist>
4043 <listitem>
4044 <para>Fixed BOOST_MSM_EUML_EVENT_WITH_ATTRIBUTES (broken in
4045 1.56).</para>
4046 </listitem>
4047 <listitem>
4048 <para>Fixed execute_queued_events, added
4049 execute_single_queued_event</para>
4050 </listitem>
4051 <listitem>
4052 <para>Fixed warnings for unused variables</para>
4053 </listitem>
4054 </itemizedlist>
4055 </para>
4056 </sect1>
4057 <sect1>
4058 <title>From V2.26 to V2.27 (Boost 1.56)</title>
4059 <para>
4060 <itemizedlist>
4061 <listitem>
4062 <para>Bugfix: no_transition in case of an exception.</para>
4063 </listitem>
4064 <listitem>
4065 <para>Bugfix: Trac 9280</para>
4066 </listitem>
4067 <listitem>
4068 <para>Bugfix: incomplete namespace names in eUML</para>
4069 </listitem>
4070 </itemizedlist>
4071 </para>
4072 </sect1>
4073 <sect1>
4074 <title>From V2.25 to V2.26 (Boost 1.55)</title>
4075 <para>
4076 <itemizedlist>
4077 <listitem>
4078 <para>New feature: interrupt states now support a sequence of events to
4079 end the interruption</para>
4080 </listitem>
4081 <listitem>
4082 <para>Bugfix: Trac 8686.</para>
4083 </listitem>
4084 </itemizedlist>
4085 </para>
4086 </sect1>
4087 <sect1>
4088 <title>From V2.24 to V2.25 (Boost 1.54)</title>
4089 <para>
4090 <itemizedlist>
4091 <listitem>
4092 <para>Bugfix: Exit points broken for the favor_compile_time
4093 policy.</para>
4094 </listitem>
4095 <listitem>
4096 <para>Bugfix: copy breaks exit points of subsubmachines.</para>
4097 </listitem>
4098 <listitem>
4099 <para>Bugfix: Trac 8046.</para>
4100 </listitem>
4101 </itemizedlist>
4102 </para>
4103 </sect1>
4104 <sect1>
4105 <title>From V2.23 to V2.24 (Boost 1.51)</title>
4106 <para>
4107 <itemizedlist>
4108 <listitem>
4109 <para> Support for <command xlink:href="#any-event">boost::any</command>
4110 or <command xlink:href="#kleene-event">kleene</command> as an
4111 acceptable event.</para>
4112 </listitem>
4113 <listitem>
4114 <para>Bugfix: compiler error with fsm internal table and
4115 <code>none</code>(compound) event.</para>
4116 </listitem>
4117 <listitem>
4118 <para>Bugfix: <code>euml::defer_</code> leading to stack overflow.</para>
4119 </listitem>
4120 </itemizedlist>
4121 </para>
4122 </sect1>
4123 <sect1>
4124 <title>From V2.22 to V2.23 (Boost 1.50)</title>
4125 <para>
4126 <itemizedlist>
4127 <listitem>
4128 <para> <command xlink:href="#eUML-composite-table">eUML</command> : better syntax
4129 for front-ends defined with eUML as transititon table only. Caution:
4130 Breaking Change!</para>
4131 </listitem>
4132 <listitem>
4133 <para>Bugfix: graph building was only working if
4134 <code>initial_state</code> defined as a sequence</para>
4135 </listitem>
4136 <listitem>
4137 <para>Bugfix: flags defined for a Terminate or Interrupt state do not
4138 break the blocking function of these states any more.</para>
4139 </listitem>
4140 <listitem>
4141 <para>Bugfix: multiple deferred events from several regions were not
4142 working in every case.</para>
4143 </listitem>
4144 <listitem>
4145 <para>Bugfix: visitor was passed by value to submachines.</para>
4146 </listitem>
4147 <listitem>
4148 <para>Bugfix: <code>no_transition</code> was not called for submachines who send an
4149 event to themselves.</para>
4150 </listitem>
4151 <listitem>
4152 <para>Fixed warnings with gcc</para>
4153 </listitem>
4154 </itemizedlist>
4155 </para>
4156 </sect1>
4157 <sect1>
4158 <title>From V2.21 to V2.22 (Boost 1.48)</title>
4159 <para>
4160 <itemizedlist>
4161 <listitem>
4162 <para>eUML: added easier event reprocessing:
4163 <code>process(event_)</code> and <code>reprocess()</code></para>
4164 </listitem>
4165 <listitem>
4166 <para>Rewrite of internal transition tables. There were a few bugs
4167 (failing recursivity in internal transition tables of sub-sub
4168 machines) and a missing feature (unused internal transition table of
4169 the main state machine).</para>
4170 </listitem>
4171 <listitem>
4172 <para>Bugfixes<itemizedlist>
4173 <listitem>
4174 <para>Reverted favor_compile_time policy to Boost 1.46
4175 state</para>
4176 </listitem>
4177 <listitem>
4178 <para><code>none</code> event now is convertible from any
4179 other event </para>
4180 </listitem>
4181 <listitem>
4182 <para>eUML and pseudo exit states</para>
4183 </listitem>
4184 <listitem>
4185 <para>Fixed not working Flag_AND</para>
4186 </listitem>
4187 <listitem>
4188 <para>Fixed rare bugs causing multiple processing of the
4189 same event in a submachine whose transition table
4190 contains this event and a base event of it.</para>
4191 </listitem>
4192 <listitem>
4193 <para>gcc warnings about unused variables</para>
4194 </listitem>
4195 </itemizedlist></para>
4196 </listitem>
4197 <listitem>
4198 <para>Breaking change: the new internal transition table feature causes
4199 a minor breaking change. In a submachine, the "Fsm" template
4200 parameter for guards / actions of an internal table declared using
4201 <code>internal_transition_table</code> now is the submachine,
4202 not the higher-level state machine. Internal transitions declared
4203 using internal rows in the higher-level state machine keep their
4204 behavior (the "Fsm" parameter is the higher-level state machine). To
4205 sum up, the internal transition "Fsm" parameter is the closest state
4206 machine containing this transition.</para>
4207 </listitem>
4208 </itemizedlist>
4209 </para>
4210 </sect1>
4211 <sect1>
4212 <title>From V2.20 to V2.21 (Boost 1.47)</title>
4213 <para>
4214 <itemizedlist>
4215 <listitem>
4216 <para>Added a <command xlink:href="#backend-start">stop()</command>
4217 method in the back-end.</para>
4218 </listitem>
4219 <listitem>
4220 <para><command xlink:href="#eUML-phoenix">Added partial support for
4221 Boost.Phoenix functors in eUML</command></para>
4222 </listitem>
4223 <listitem>
4224 <para>Added the possibility to choose when <command xlink:href="#backend-state-switch">state switching</command>
4225 occurs.</para>
4226 </listitem>
4227 <listitem>
4228 <para>Bugfixes<itemizedlist>
4229 <listitem>
4230 <para>Trac 5117, 5253, 5533, 5573</para>
4231 </listitem>
4232 <listitem>
4233 <para>gcc warnings about unused variables</para>
4234 </listitem>
4235 <listitem>
4236 <para>better implemenation of favor_compile_time back-end
4237 policy</para>
4238 </listitem>
4239 <listitem>
4240 <para>bug with eUML and state construction</para>
4241 </listitem>
4242 <listitem>
4243 <para>incorrect eUML event and state macros</para>
4244 </listitem>
4245 <listitem>
4246 <para>incorrect event type passed to a direct entry state's
4247 on_entry action</para>
4248 </listitem>
4249 <listitem>
4250 <para>more examples</para>
4251 </listitem>
4252 </itemizedlist></para>
4253 </listitem>
4254 </itemizedlist>
4255 </para>
4256 </sect1>
4257 <sect1>
4258 <title>From V2.12 to V2.20 (Boost 1.46)</title>
4259 <para>
4260 <itemizedlist>
4261 <listitem>
4262 <para>Compile-time state machine analysis using mpl_graph:</para>
4263 <itemizedlist>
4264 <listitem>
4265 <para><command xlink:href="#backend-compile-time-analysis">checking of region orthogonality</command>.</para>
4266 </listitem>
4267 <listitem>
4268 <para><command xlink:href="#backend-compile-time-analysis">search for unreachable states</command>.</para>
4269 </listitem>
4270 <listitem>
4271 <para><command xlink:href="#explicit-entry-no-region-id">automatic region index search for pseudo entry or explicit
4272 entry states</command>.</para>
4273 </listitem>
4274 </itemizedlist>
4275 </listitem>
4276 <listitem>
4277 <para><command xlink:href="#backend-boost-parameter">Boost.Parameter interface definition</command> for
4278 msm::back::state_machine&lt;> template arguments.</para>
4279 </listitem>
4280 <listitem>
4281 <para><command xlink:href="#backend-queues">Possibility to provide a
4282 container</command> for the event and deferred event queues. A
4283 policy implementation based on a more efficient Boost.CircularBuffer
4284 is provided.</para>
4285 </listitem>
4286 <listitem>
4287 <para>msm::back::state_machine&lt;>::is_flag_active method made
4288 const.</para>
4289 </listitem>
4290 <listitem>
4291 <para>added possibility to <command xlink:href="#backend-enqueueing"
4292 >enqueue events</command> for delayed processing.</para>
4293 </listitem>
4294 <listitem>
4295 <para>Bugfixes<itemizedlist>
4296 <listitem>
4297 <para>Trac 4926</para>
4298 </listitem>
4299 <listitem>
4300 <para>stack overflow using the Defer functor</para>
4301 </listitem>
4302 <listitem>
4303 <para>anonymous transition of a submachine not called for
4304 the initial state</para>
4305 </listitem>
4306 </itemizedlist></para>
4307 </listitem>
4308 </itemizedlist>
4309 </para>
4310 </sect1>
4311 <sect1>
4312 <title>From V2.10 to V2.12 (Boost 1.45)</title>
4313 <para>
4314 <itemizedlist>
4315 <listitem>
4316 <para>Support for <command xlink:href="#back-end-serialization">serialization</command></para>
4317 </listitem>
4318 <listitem>
4319 <para><command xlink:href="#eUML-reuse-functor">Possibility to use
4320 normal functors</command> (from functor front-end) in
4321 eUML.</para>
4322 </listitem>
4323 <listitem>
4324 <para><command xlink:href="#backend-fsm-constructor-args">New constructors</command> where substates / submachines can be taken as
4325 arguments. This allows passing arguments to the constructor of a
4326 submachine.</para>
4327 </listitem>
4328 <listitem>
4329 <para>Bugfixes</para>
4330 </listitem>
4331 </itemizedlist>
4332 </para>
4333 </sect1>
4334 <sect1>
4335 <title>From V2.0 to V2.12 (Boost 1.44)</title>
4336 <para>
4337 <itemizedlist>
4338 <listitem>
4339 <para>New documentation</para>
4340 </listitem>
4341 <listitem>
4342 <para>Internal transitions. Either as part of the transition table or
4343 using a state's internal transition table</para>
4344 </listitem>
4345 <listitem>
4346 <para>increased dispatch and copy speed</para>
4347 </listitem>
4348 <listitem>
4349 <para><command xlink:href="#basic-row2">new row types</command> for the
4350 basic front-end</para>
4351 </listitem>
4352 <listitem>
4353 <para>new eUML syntax, better attribute support, macros to ease
4354 developer's life. Even VC8 seems to like it better.</para>
4355 </listitem>
4356 <listitem>
4357 <para>New policy for reduced compile-time at the cost of dispatch
4358 speed</para>
4359 </listitem>
4360 <listitem>
4361 <para>Support for base events</para>
4362 </listitem>
4363 <listitem>
4364 <para>possibility to choose the initial event</para>
4365 </listitem>
4366 </itemizedlist>
4367 </para>
4368 </sect1>
4369 </chapter>
4370 </part>
4371 <part>
4372 <title><command xml:id="Reference-begin"/>Reference</title>
4373 <chapter>
4374 <title>External references to MSM</title>
4375 <para>An interesting mapping UML &lt;-> MSM from Takatoshi Kondo can be found at
4376 <command xlink:href="http://redboltz.wikidot.com/boost-msm-guide"
4377 >Redboltz</command>.</para>
4378 </chapter>
4379 <chapter>
4380 <title>eUML operators and basic helpers</title>
4381 <para>The following table lists the supported operators: </para>
4382 <para>
4383 <table frame="all">
4384 <title>Operators and state machine helpers</title>
4385 <tgroup cols="3">
4386 <colspec colname="c1" colnum="1"/>
4387 <colspec colname="c2" colnum="2"/>
4388 <colspec colname="c3" colnum="3"/>
4389 <thead>
4390 <row>
4391 <entry>eUML function / operator</entry>
4392 <entry>Description</entry>
4393 <entry>Functor</entry>
4394 </row>
4395 </thead>
4396 <tbody>
4397 <row>
4398 <entry>&amp;&amp;</entry>
4399 <entry>Calls lazily Action1&amp;&amp; Action2</entry>
4400 <entry>And_</entry>
4401 </row>
4402 <row>
4403 <entry>||</entry>
4404 <entry>Calls lazily Action1|| Action2</entry>
4405 <entry>Or_</entry>
4406 </row>
4407 <row>
4408 <entry>!</entry>
4409 <entry>Calls lazily !Action1</entry>
4410 <entry>Not_</entry>
4411 </row>
4412 <row>
4413 <entry>!=</entry>
4414 <entry>Calls lazily Action1 != Action2</entry>
4415 <entry>NotEqualTo_</entry>
4416 </row>
4417 <row>
4418 <entry>==</entry>
4419 <entry>Calls lazily Action1 == Action2</entry>
4420 <entry>EqualTo_</entry>
4421 </row>
4422 <row>
4423 <entry>></entry>
4424 <entry>Calls lazily Action1 > Action2</entry>
4425 <entry>Greater_</entry>
4426 </row>
4427 <row>
4428 <entry>>=</entry>
4429 <entry>Calls lazily Action1 >= Action2</entry>
4430 <entry>Greater_Equal_</entry>
4431 </row>
4432 <row>
4433 <entry>&lt;</entry>
4434 <entry>Calls lazily Action1 &lt; Action2</entry>
4435 <entry>Less_</entry>
4436 </row>
4437 <row>
4438 <entry>&lt;=</entry>
4439 <entry>Calls lazily Action1 &lt;= Action2</entry>
4440 <entry>Less_Equal_</entry>
4441 </row>
4442 <row>
4443 <entry>&amp;</entry>
4444 <entry>Calls lazily Action1 &amp; Action2</entry>
4445 <entry>Bitwise_And_</entry>
4446 </row>
4447 <row>
4448 <entry>|</entry>
4449 <entry>Calls lazily Action1 | Action2</entry>
4450 <entry>Bitwise_Or_</entry>
4451 </row>
4452 <row>
4453 <entry>^</entry>
4454 <entry>Calls lazily Action1 ^ Action2</entry>
4455 <entry>Bitwise_Xor_</entry>
4456 </row>
4457 <row>
4458 <entry>--</entry>
4459 <entry>Calls lazily --Action1 / Action1--</entry>
4460 <entry>Pre_Dec_ / Post_Dec_</entry>
4461 </row>
4462 <row>
4463 <entry>++</entry>
4464 <entry>Calls lazily ++Action1 / Action1++</entry>
4465 <entry>Pre_Inc_ / Post_Inc_</entry>
4466 </row>
4467 <row>
4468 <entry>/</entry>
4469 <entry>Calls lazily Action1 / Action2</entry>
4470 <entry>Divides_</entry>
4471 </row>
4472 <row>
4473 <entry>/=</entry>
4474 <entry>Calls lazily Action1 /= Action2</entry>
4475 <entry>Divides_Assign_</entry>
4476 </row>
4477 <row>
4478 <entry>*</entry>
4479 <entry>Calls lazily Action1 * Action2</entry>
4480 <entry>Multiplies_</entry>
4481 </row>
4482 <row>
4483 <entry>*=</entry>
4484 <entry>Calls lazily Action1 *= Action2</entry>
4485 <entry>Multiplies_Assign_</entry>
4486 </row>
4487 <row>
4488 <entry>+ (binary)</entry>
4489 <entry>Calls lazily Action1 + Action2</entry>
4490 <entry>Plus_</entry>
4491 </row>
4492 <row>
4493 <entry>+ (unary)</entry>
4494 <entry>Calls lazily +Action1</entry>
4495 <entry>Unary_Plus_</entry>
4496 </row>
4497 <row>
4498 <entry>+=</entry>
4499 <entry>Calls lazily Action1 += Action2</entry>
4500 <entry>Plus_Assign_</entry>
4501 </row>
4502 <row>
4503 <entry>- (binary)</entry>
4504 <entry>Calls lazily Action1 - Action2</entry>
4505 <entry>Minus_</entry>
4506 </row>
4507 <row>
4508 <entry>- (unary)</entry>
4509 <entry>Calls lazily -Action1</entry>
4510 <entry>Unary_Minus_</entry>
4511 </row>
4512 <row>
4513 <entry>-=</entry>
4514 <entry>Calls lazily Action1 -= Action2</entry>
4515 <entry>Minus_Assign_</entry>
4516 </row>
4517 <row>
4518 <entry>%</entry>
4519 <entry>Calls lazily Action1 % Action2</entry>
4520 <entry>Modulus_</entry>
4521 </row>
4522 <row>
4523 <entry>%=</entry>
4524 <entry>Calls lazily Action1 %= Action2</entry>
4525 <entry>Modulus_Assign_</entry>
4526 </row>
4527 <row>
4528 <entry>>></entry>
4529 <entry>Calls lazily Action1 >> Action2</entry>
4530 <entry>ShiftRight_</entry>
4531 </row>
4532 <row>
4533 <entry>>>=</entry>
4534 <entry>Calls lazily Action1 >>= Action2</entry>
4535 <entry>ShiftRight_Assign_</entry>
4536 </row>
4537 <row>
4538 <entry>&lt;&lt;</entry>
4539 <entry>Calls lazily Action1 &lt;&lt; Action2</entry>
4540 <entry>ShiftLeft_</entry>
4541 </row>
4542 <row>
4543 <entry>&lt;&lt;=</entry>
4544 <entry>Calls lazily Action1 &lt;&lt;= Action2</entry>
4545 <entry>ShiftLeft_Assign_</entry>
4546 </row>
4547 <row>
4548 <entry>[] (works on vector, map, arrays)</entry>
4549 <entry>Calls lazily Action1 [Action2]</entry>
4550 <entry>Subscript_</entry>
4551 </row>
4552 <row>
4553 <entry>if_then_else_(Condition,Action1,Action2)</entry>
4554 <entry>Returns either the result of calling Action1 or the result of
4555 calling Action2</entry>
4556 <entry>If_Else_</entry>
4557 </row>
4558 <row>
4559 <entry>if_then_(Condition,Action)</entry>
4560 <entry>Returns the result of calling Action if Condition</entry>
4561 <entry>If_Then_</entry>
4562 </row>
4563 <row>
4564 <entry>while_(Condition, Body)</entry>
4565 <entry>While Condition(), calls Body(). Returns nothing</entry>
4566 <entry>While_Do_</entry>
4567 </row>
4568 <row>
4569 <entry>do_while_(Condition, Body)</entry>
4570 <entry>Calls Body() while Condition(). Returns nothing</entry>
4571 <entry>Do_While_</entry>
4572 </row>
4573 <row>
4574 <entry>for_(Begin,Stop,EndLoop,Body)</entry>
4575 <entry>Calls for(Begin;Stop;EndLoop){Body;}</entry>
4576 <entry>For_Loop_</entry>
4577 </row>
4578 <row>
4579 <entry>process_(Event [,fsm1] [,fsm2] [,fsm3] [,fsm4])</entry>
4580 <entry>Processes Event on the current state machine (if no fsm
4581 specified) or on up to 4 state machines returned by an
4582 appropriate functor.</entry>
4583 <entry>Process_</entry>
4584 </row>
4585 <row>
4586 <entry>process2_(Event, Data [,fsm1] [,fsm2] [,fsm3])</entry>
4587 <entry>Processes Event on the current state machine (if no fsm
4588 specified) or on up to 2 state machines returned by an
4589 appropriate functor. The event is copy-constructed from what
4590 Data() returns.</entry>
4591 <entry>Process2_</entry>
4592 </row>
4593 <row>
4594 <entry>is_flag_(Flag [,fsm])</entry>
4595 <entry>Calls is_flag_active() on the current state machine or the
4596 one returned by calling fsm.</entry>
4597 <entry>Get_Flag_</entry>
4598 </row>
4599 <row>
4600 <entry>event_ [(attribute name)]</entry>
4601 <entry>Returns the current event (as const reference)</entry>
4602 <entry>GetEvent_</entry>
4603 </row>
4604 <row>
4605 <entry>source_ [(attribute name)]</entry>
4606 <entry>Returns the source state of the currently triggered
4607 transition (as reference). If an attribute name is provided,
4608 returns the attribute by reference.</entry>
4609 <entry>GetSource_</entry>
4610 </row>
4611 <row>
4612 <entry>target_ [(attribute name)]</entry>
4613 <entry>Returns the target state of the currently triggered
4614 transition (as reference). If an attribute name is provided,
4615 returns the attribute by reference.</entry>
4616 <entry>GetTarget_</entry>
4617 </row>
4618 <row>
4619 <entry>state_ [(attribute name)]</entry>
4620 <entry>Returns the source state of the currently active state (as
4621 reference). Valid inside a state entry/exit action. If an
4622 attribute name is provided, returns the attribute by
4623 reference.</entry>
4624 <entry>GetState_</entry>
4625 </row>
4626 <row>
4627 <entry>fsm_ [(attribute name)]</entry>
4628 <entry>Returns the current state machine (as reference). Valid
4629 inside a state entry/exit action or a transition. If an
4630 attribute name is provided, returns the attribute by
4631 reference.</entry>
4632 <entry>GetFsm_</entry>
4633 </row>
4634 <row>
4635 <entry>substate_(state_name [,fsm])</entry>
4636 <entry>Returns (as reference) the state state_name referenced in the
4637 current state machine or the one given as argument.</entry>
4638 <entry>SubState_</entry>
4639 </row>
4640 </tbody>
4641 </tgroup>
4642 </table>
4643 </para>
4644 <para>To use these functions, you need to include: </para>
4645 <para><code>#include &lt;msm/front/euml/euml.hpp></code></para>
4646 </chapter>
4647 <chapter>
4648 <title>
4649 <command xml:id="eUML-STL-all"/>Functional programming </title>
4650 <para>To use these functions, you need to include: </para>
4651 <para><code>#include &lt;msm/front/euml/stl.hpp></code></para>
4652 <para>or the specified header in the following tables.</para>
4653 <para>The following tables list the supported STL algorithms: </para>
4654 <para>
4655 <command xml:id="eUML-STL-querying"/>
4656 <table frame="all">
4657 <title>STL algorithms</title>
4658 <tgroup cols="2">
4659 <colspec colname="c2" colnum="1"/>
4660 <colspec colname="c3" colnum="2"/>
4661 <thead>
4662 <row>
4663 <entry>STL algorithms in querying.hpp</entry>
4664 <entry>Functor</entry>
4665 </row>
4666 </thead>
4667 <tbody>
4668 <row>
4669 <entry>find_(first, last, value)</entry>
4670 <entry>Find_</entry>
4671 </row>
4672 <row>
4673 <entry>find_if_(first, last, value)</entry>
4674 <entry>FindIf_</entry>
4675 </row>
4676 <row>
4677 <entry>lower_bound_(first, last, value [,opᵃ])</entry>
4678 <entry>LowerBound_</entry>
4679 </row>
4680 <row>
4681 <entry>upper_bound_(first, last, value [,opᵃ])</entry>
4682 <entry>UpperBound_</entry>
4683 </row>
4684 <row>
4685 <entry>equal_range_(first, last, value [,opᵃ])</entry>
4686 <entry>EqualRange_</entry>
4687 </row>
4688 <row>
4689 <entry>binary_search_(first, last, value [,opᵃ])</entry>
4690 <entry>BinarySearch_</entry>
4691 </row>
4692 <row>
4693 <entry>min_element_(first, last[,opᵃ])</entry>
4694 <entry>MinElement_</entry>
4695 </row>
4696 <row>
4697 <entry>max_element_(first, last[,opᵃ])</entry>
4698 <entry>MaxElement_</entry>
4699 </row>
4700 <row>
4701 <entry>adjacent_find_(first, last[,opᵃ])</entry>
4702 <entry>AdjacentFind_</entry>
4703 </row>
4704 <row>
4705 <entry>find_end_( first1, last1, first2, last2 [,op ᵃ])</entry>
4706 <entry>FindEnd_</entry>
4707 </row>
4708 <row>
4709 <entry>find_first_of_( first1, last1, first2, last2 [,op ᵃ])</entry>
4710 <entry>FindFirstOf_</entry>
4711 </row>
4712 <row>
4713 <entry>equal_( first1, last1, first2 [,op ᵃ])</entry>
4714 <entry>Equal_</entry>
4715 </row>
4716 <row>
4717 <entry>search_( first1, last1, first2, last2 [,op ᵃ])</entry>
4718 <entry>Search_</entry>
4719 </row>
4720 <row>
4721 <entry>includes_( first1, last1, first2, last2 [,op ᵃ])</entry>
4722 <entry>Includes_</entry>
4723 </row>
4724 <row>
4725 <entry>lexicographical_compare_ ( first1, last1, first2, last2 [,op
4726 ᵃ]) </entry>
4727 <entry>LexicographicalCompare_</entry>
4728 </row>
4729 <row>
4730 <entry>count_(first, last, value [,size])</entry>
4731 <entry>Count_</entry>
4732 </row>
4733 <row>
4734 <entry>count_if_(first, last, op ᵃ [,size])</entry>
4735 <entry>CountIf_</entry>
4736 </row>
4737 <row>
4738 <entry>distance_(first, last)</entry>
4739 <entry>Distance_</entry>
4740 </row>
4741 <row>
4742 <entry>mismatch _( first1, last1, first2 [,op ᵃ])</entry>
4743 <entry>Mismatch_</entry>
4744 </row>
4745 </tbody>
4746 </tgroup>
4747 </table>
4748 </para>
4749 <para>
4750 <command xml:id="eUML-STL-iteration"/>
4751 <table frame="all">
4752 <title>STL algorithms</title>
4753 <tgroup cols="2">
4754 <colspec colname="c2" colnum="1"/>
4755 <colspec colname="c3" colnum="2"/>
4756 <thead>
4757 <row>
4758 <entry>STL algorithms in iteration.hpp</entry>
4759 <entry>Functor</entry>
4760 </row>
4761 </thead>
4762 <tbody>
4763 <row>
4764 <entry>for_each_(first,last, unary opᵃ)</entry>
4765 <entry>ForEach_</entry>
4766 </row>
4767 <row>
4768 <entry>accumulate_first, last, init [,opᵃ])</entry>
4769 <entry>Accumulate_</entry>
4770 </row>
4771 </tbody>
4772 </tgroup>
4773 </table>
4774 </para>
4775 <para>
4776 <command xml:id="eUML-STL-transformation"/>
4777 <table>
4778 <title>STL algorithms</title>
4779 <tgroup cols="2">
4780 <colspec colname="c2" colnum="1"/>
4781 <colspec colname="c3" colnum="2"/>
4782 <thead>
4783 <row>
4784 <entry>STL algorithms in transformation.hpp</entry>
4785 <entry>Functor</entry>
4786 </row>
4787 </thead>
4788 <tbody>
4789 <row>
4790 <entry>copy_(first, last, result)</entry>
4791 <entry>Copy_</entry>
4792 </row>
4793 <row>
4794 <entry>copy_backward_(first, last, result)</entry>
4795 <entry>CopyBackward_</entry>
4796 </row>
4797 <row>
4798 <entry>reverse_(first, last)</entry>
4799 <entry>Reverse_</entry>
4800 </row>
4801 <row>
4802 <entry>reverse_copy_(first, last , result)</entry>
4803 <entry>ReverseCopy_</entry>
4804 </row>
4805 <row>
4806 <entry>remove_(first, last, value)</entry>
4807 <entry>Remove_</entry>
4808 </row>
4809 <row>
4810 <entry>remove_if_(first, last , opᵃ)</entry>
4811 <entry>RemoveIf_</entry>
4812 </row>
4813 <row>
4814 <entry>remove_copy_(first, last , output, value)</entry>
4815 <entry>RemoveCopy_</entry>
4816 </row>
4817 <row>
4818 <entry>remove_copy_if_(first, last, output, opᵃ)</entry>
4819 <entry>RemoveCopyIf_</entry>
4820 </row>
4821 <row>
4822 <entry>fill_(first, last, value)</entry>
4823 <entry>Fill_</entry>
4824 </row>
4825 <row>
4826 <entry>fill_n_(first, size, value)ᵇ</entry>
4827 <entry>FillN_</entry>
4828 </row>
4829 <row>
4830 <entry>generate_(first, last, generatorᵃ)</entry>
4831 <entry>Generate_</entry>
4832 </row>
4833 <row>
4834 <entry>generate_(first, size, generatorᵃ)ᵇ</entry>
4835 <entry>GenerateN_</entry>
4836 </row>
4837 <row>
4838 <entry>unique_(first, last [,opᵃ])</entry>
4839 <entry>Unique_</entry>
4840 </row>
4841 <row>
4842 <entry>unique_copy_(first, last, output [,opᵃ])</entry>
4843 <entry>UniqueCopy_</entry>
4844 </row>
4845 <row>
4846 <entry>random_shuffle_(first, last [,opᵃ])</entry>
4847 <entry>RandomShuffle_</entry>
4848 </row>
4849 <row>
4850 <entry>rotate_copy_(first, middle, last, output)</entry>
4851 <entry>RotateCopy_</entry>
4852 </row>
4853 <row>
4854 <entry>partition_ (first, last [,opᵃ])</entry>
4855 <entry>Partition_</entry>
4856 </row>
4857 <row>
4858 <entry>stable_partition_ (first, last [,opᵃ])</entry>
4859 <entry>StablePartition_</entry>
4860 </row>
4861 <row>
4862 <entry>stable_sort_(first, last [,opᵃ])</entry>
4863 <entry>StableSort_</entry>
4864 </row>
4865 <row>
4866 <entry>sort_(first, last [,opᵃ])</entry>
4867 <entry>Sort_</entry>
4868 </row>
4869 <row>
4870 <entry>partial_sort_(first, middle, last [,opᵃ])</entry>
4871 <entry>PartialSort_</entry>
4872 </row>
4873 <row>
4874 <entry>partial_sort_copy_ (first, last, res_first, res_last [,opᵃ]) </entry>
4875 <entry>PartialSortCopy_</entry>
4876 </row>
4877 <row>
4878 <entry>nth_element_(first, nth, last [,opᵃ])</entry>
4879 <entry>NthElement_</entry>
4880 </row>
4881 <row>
4882 <entry>merge_( first1, last1, first2, last2, output [,op ᵃ])</entry>
4883 <entry>Merge_</entry>
4884 </row>
4885 <row>
4886 <entry>inplace_merge_(first, middle, last [,opᵃ])</entry>
4887 <entry>InplaceMerge_</entry>
4888 </row>
4889 <row>
4890 <entry>set_union_(first1, last1, first2, last2, output [,op
4891 ᵃ])</entry>
4892 <entry>SetUnion_</entry>
4893 </row>
4894 <row>
4895 <entry>push_heap_(first, last [,op ᵃ])</entry>
4896 <entry>PushHeap_</entry>
4897 </row>
4898 <row>
4899 <entry>pop_heap_(first, last [,op ᵃ])</entry>
4900 <entry>PopHeap_</entry>
4901 </row>
4902 <row>
4903 <entry>make_heap_(first, last [,op ᵃ])</entry>
4904 <entry>MakeHeap_</entry>
4905 </row>
4906 <row>
4907 <entry>sort_heap_(first, last [,op ᵃ])</entry>
4908 <entry>SortHeap_</entry>
4909 </row>
4910 <row>
4911 <entry>next_permutation_(first, last [,op ᵃ])</entry>
4912 <entry>NextPermutation_</entry>
4913 </row>
4914 <row>
4915 <entry>prev_permutation_(first, last [,op ᵃ])</entry>
4916 <entry>PrevPermutation_</entry>
4917 </row>
4918 <row>
4919 <entry>inner_product_(first1, last1, first2, init [,op1ᵃ] [,op2ᵃ]) </entry>
4920 <entry>InnerProduct_</entry>
4921 </row>
4922 <row>
4923 <entry>partial_sum_(first, last, output [,opᵃ])</entry>
4924 <entry>PartialSum_</entry>
4925 </row>
4926 <row>
4927 <entry>adjacent_difference_(first, last, output [,opᵃ])</entry>
4928 <entry>AdjacentDifference_</entry>
4929 </row>
4930 <row>
4931 <entry>replace_(first, last, old_value, new_value)</entry>
4932 <entry>Replace_</entry>
4933 </row>
4934 <row>
4935 <entry>replace_if_(first, last, opᵃ, new_value)</entry>
4936 <entry>ReplaceIf_</entry>
4937 </row>
4938 <row>
4939 <entry>replace_copy_(first, last, result, old_value,
4940 new_value)</entry>
4941 <entry>ReplaceCopy_</entry>
4942 </row>
4943 <row>
4944 <entry>replace_copy_if_(first, last, result, opᵃ, new_value)</entry>
4945 <entry>ReplaceCopyIf_</entry>
4946 </row>
4947 <row>
4948 <entry>rotate_(first, middle, last)ᵇ</entry>
4949 <entry>Rotate_</entry>
4950 </row>
4951 </tbody>
4952 </tgroup>
4953 </table>
4954 </para>
4955 <para>
4956 <command xml:id="eUML-STL-container"/>
4957 <table>
4958 <title>STL container methods</title>
4959 <tgroup cols="2">
4960 <colspec colname="c2" colnum="1"/>
4961 <colspec colname="c3" colnum="2"/>
4962 <thead>
4963 <row>
4964 <entry>STL container methods(common) in container.hpp</entry>
4965 <entry>Functor</entry>
4966 </row>
4967 </thead>
4968 <tbody>
4969 <row>
4970 <entry>container::reference front_(container)</entry>
4971 <entry>Front_</entry>
4972 </row>
4973 <row>
4974 <entry>container::reference back_(container)</entry>
4975 <entry>Back_</entry>
4976 </row>
4977 <row>
4978 <entry>container::iterator begin_(container)</entry>
4979 <entry>Begin_</entry>
4980 </row>
4981 <row>
4982 <entry>container::iterator end_(container)</entry>
4983 <entry>End_</entry>
4984 </row>
4985 <row>
4986 <entry>container::reverse_iterator rbegin_(container)</entry>
4987 <entry>RBegin_</entry>
4988 </row>
4989 <row>
4990 <entry>container::reverse_iterator rend_(container)</entry>
4991 <entry>REnd_</entry>
4992 </row>
4993 <row>
4994 <entry>void push_back_(container, value)</entry>
4995 <entry>Push_Back_</entry>
4996 </row>
4997 <row>
4998 <entry>void pop_back_(container, value)</entry>
4999 <entry>Pop_Back_</entry>
5000 </row>
5001 <row>
5002 <entry>void push_front_(container, value)</entry>
5003 <entry>Push_Front_</entry>
5004 </row>
5005 <row>
5006 <entry>void pop_front_(container, value)</entry>
5007 <entry>Pop_Front_</entry>
5008 </row>
5009 <row>
5010 <entry>void clear_(container)</entry>
5011 <entry>Clear_</entry>
5012 </row>
5013 <row>
5014 <entry>size_type capacity_(container)</entry>
5015 <entry>Capacity_</entry>
5016 </row>
5017 <row>
5018 <entry>size_type size_(container)</entry>
5019 <entry>Size_</entry>
5020 </row>
5021 <row>
5022 <entry>size_type max_size_(container)</entry>
5023 <entry>Max_Size_</entry>
5024 </row>
5025 <row>
5026 <entry>void reserve_(container, value)</entry>
5027 <entry>Reserve _</entry>
5028 </row>
5029 <row>
5030 <entry>void resize_(container, value)</entry>
5031 <entry>Resize _</entry>
5032 </row>
5033 <row>
5034 <entry>iterator insert_(container, pos, value)</entry>
5035 <entry>Insert_</entry>
5036 </row>
5037 <row>
5038 <entry>void insert_( container , pos, first, last)</entry>
5039 <entry>Insert_</entry>
5040 </row>
5041 <row>
5042 <entry>void insert_( container , pos, number, value)</entry>
5043 <entry>Insert_</entry>
5044 </row>
5045 <row>
5046 <entry>void swap_( container , other_container)</entry>
5047 <entry>Swap_</entry>
5048 </row>
5049 <row>
5050 <entry>void erase_( container , pos)</entry>
5051 <entry>Erase_</entry>
5052 </row>
5053 <row>
5054 <entry>void erase_( container , first, last) </entry>
5055 <entry>Erase_</entry>
5056 </row>
5057 <row>
5058 <entry>bool empty_( container)</entry>
5059 <entry>Empty_</entry>
5060 </row>
5061 </tbody>
5062 </tgroup>
5063 </table>
5064 </para>
5065 <para>
5066 <table>
5067 <title>STL list methods</title>
5068 <tgroup cols="2">
5069 <colspec colname="c2" colnum="1"/>
5070 <colspec colname="c3" colnum="2"/>
5071 <thead>
5072 <row>
5073 <entry>std::list methods in container.hpp</entry>
5074 <entry>Functor</entry>
5075 </row>
5076 </thead>
5077 <tbody>
5078 <row>
5079 <entry>void list_remove_(container, value)</entry>
5080 <entry>ListRemove_</entry>
5081 </row>
5082 <row>
5083 <entry>void list_remove_if_(container, opᵃ)</entry>
5084 <entry>ListRemove_If_</entry>
5085 </row>
5086 <row>
5087 <entry>void list_merge_(container, other_list)</entry>
5088 <entry>ListMerge_</entry>
5089 </row>
5090 <row>
5091 <entry>void list_merge_(container, other_list, opᵃ)</entry>
5092 <entry>ListMerge_</entry>
5093 </row>
5094 <row>
5095 <entry>void splice_(container, iterator, other_list)</entry>
5096 <entry>Splice_</entry>
5097 </row>
5098 <row>
5099 <entry>void splice_(container, iterator, other_list,
5100 iterator)</entry>
5101 <entry>Splice_</entry>
5102 </row>
5103 <row>
5104 <entry>void splice_(container, iterator, other_list, first,
5105 last)</entry>
5106 <entry>Splice_</entry>
5107 </row>
5108 <row>
5109 <entry>void list_reverse_(container)</entry>
5110 <entry>ListReverse_</entry>
5111 </row>
5112 <row>
5113 <entry>void list_unique_(container)</entry>
5114 <entry>ListUnique_</entry>
5115 </row>
5116 <row>
5117 <entry>void list_unique_(container, opᵃ)</entry>
5118 <entry>ListUnique_</entry>
5119 </row>
5120 <row>
5121 <entry>void list_sort_(container)</entry>
5122 <entry>ListSort_</entry>
5123 </row>
5124 <row>
5125 <entry>void list_sort_(container, opᵃ)</entry>
5126 <entry>ListSort_</entry>
5127 </row>
5128 </tbody>
5129 </tgroup>
5130 </table>
5131 </para>
5132 <para>
5133 <table>
5134 <title>STL associative container methods </title>
5135 <tgroup cols="2">
5136 <colspec colname="c2" colnum="1"/>
5137 <colspec colname="c3" colnum="2"/>
5138 <thead>
5139 <row>
5140 <entry>Associative container methods in container.hpp</entry>
5141 <entry>Functor</entry>
5142 </row>
5143 </thead>
5144 <tbody>
5145 <row>
5146 <entry>iterator insert_(container, pos, value)</entry>
5147 <entry>Insert_</entry>
5148 </row>
5149 <row>
5150 <entry>void insert_( container , first, last)</entry>
5151 <entry>Insert_</entry>
5152 </row>
5153 <row>
5154 <entry>pair&lt;iterator, bool> insert_( container , value)</entry>
5155 <entry>Insert_</entry>
5156 </row>
5157 <row>
5158 <entry>void associative_erase_( container , pos)</entry>
5159 <entry>Associative_Erase_</entry>
5160 </row>
5161 <row>
5162 <entry>void associative_erase_( container , first, last)</entry>
5163 <entry>Associative_Erase_</entry>
5164 </row>
5165 <row>
5166 <entry>size_type associative_erase_( container , key)</entry>
5167 <entry>Associative_Erase_</entry>
5168 </row>
5169 <row>
5170 <entry>iterator associative_find_( container , key)</entry>
5171 <entry>Associative_Find_</entry>
5172 </row>
5173 <row>
5174 <entry>size_type associative_count_( container , key)</entry>
5175 <entry>AssociativeCount_</entry>
5176 </row>
5177 <row>
5178 <entry>iterator associative_lower_bound_( container , key)</entry>
5179 <entry>Associative_Lower_Bound_</entry>
5180 </row>
5181 <row>
5182 <entry>iterator associative_upper_bound_( container , key)</entry>
5183 <entry>Associative_Upper_Bound_</entry>
5184 </row>
5185 <row>
5186 <entry>pair&lt;iterator, iterator> associative_equal_range_(
5187 container , key)</entry>
5188 <entry>Associative_Equal_Range_</entry>
5189 </row>
5190 </tbody>
5191 </tgroup>
5192 </table>
5193 </para>
5194 <para>
5195 <table>
5196 <title>STL pair</title>
5197 <tgroup cols="2">
5198 <colspec colname="c2" colnum="1"/>
5199 <colspec colname="c3" colnum="2"/>
5200 <thead>
5201 <row>
5202 <entry>std::pair in container.hpp</entry>
5203 <entry>Functor</entry>
5204 </row>
5205 </thead>
5206 <tbody>
5207 <row>
5208 <entry>first_type first_(pair&lt;T1, T2>)</entry>
5209 <entry>First_</entry>
5210 </row>
5211 <row>
5212 <entry>second_type second_(pair&lt;T1, T2>)</entry>
5213 <entry>Second_</entry>
5214 </row>
5215 </tbody>
5216 </tgroup>
5217 </table>
5218 </para>
5219 <para>
5220 <table>
5221 <title>STL string</title>
5222 <tgroup cols="3">
5223 <colspec colname="newCol1" colnum="1"/>
5224 <colspec colname="c2" colnum="2"/>
5225 <colspec colname="c3" colnum="3"/>
5226 <thead>
5227 <row>
5228 <entry>STL string method</entry>
5229 <entry>std::string method in container.hpp</entry>
5230 <entry>Functor</entry>
5231 </row>
5232 </thead>
5233 <tbody>
5234 <row>
5235 <entry>substr (size_type pos, size_type size)</entry>
5236 <entry>string substr_(container, pos, length)</entry>
5237 <entry>Substr_</entry>
5238 </row>
5239 <row>
5240 <entry>int compare(string)</entry>
5241 <entry>int string_compare_(container, another_string)</entry>
5242 <entry>StringCompare_</entry>
5243 </row>
5244 <row>
5245 <entry>int compare(char*)</entry>
5246 <entry>int string_compare_(container, another_string)</entry>
5247 <entry>StringCompare_</entry>
5248 </row>
5249 <row>
5250 <entry>int compare(size_type pos, size_type size, string)</entry>
5251 <entry>int string_compare_(container, pos, size,
5252 another_string)</entry>
5253 <entry>StringCompare_</entry>
5254 </row>
5255 <row>
5256 <entry>int compare (size_type pos, size_type size, string, size_type
5257 length)</entry>
5258 <entry>int string_compare_(container, pos, size, another_string,
5259 length)</entry>
5260 <entry>StringCompare_</entry>
5261 </row>
5262 <row>
5263 <entry>string&amp; append(const string&amp;)</entry>
5264 <entry>string&amp; append_(container, another_string)</entry>
5265 <entry>Append_</entry>
5266 </row>
5267 <row>
5268 <entry>string&amp; append (charT*)</entry>
5269 <entry>string&amp; append_(container, another_string)</entry>
5270 <entry>Append_</entry>
5271 </row>
5272 <row>
5273 <entry>string&amp; append (string , size_type pos, size_type
5274 size)</entry>
5275 <entry>string&amp; append_(container, other_string, pos,
5276 size)</entry>
5277 <entry>Append_</entry>
5278 </row>
5279 <row>
5280 <entry>string&amp; append (charT*, size_type size)</entry>
5281 <entry>string&amp; append_(container, another_string,
5282 length)</entry>
5283 <entry>Append_</entry>
5284 </row>
5285 <row>
5286 <entry>string&amp; append (size_type size, charT)</entry>
5287 <entry>string&amp; append_(container, size, char)</entry>
5288 <entry>Append_</entry>
5289 </row>
5290 <row>
5291 <entry>string&amp; append (iterator begin, iterator end)</entry>
5292 <entry>string&amp; append_(container, begin, end)</entry>
5293 <entry>Append_</entry>
5294 </row>
5295 <row>
5296 <entry>string&amp; insert (size_type pos, charT*)</entry>
5297 <entry>string&amp; string_insert_(container, pos,
5298 other_string)</entry>
5299 <entry>StringInsert_</entry>
5300 </row>
5301 <row>
5302 <entry>string&amp; insert(size_type pos, charT*,size_type n)</entry>
5303 <entry>string&amp; string_insert_(container, pos, other_string,
5304 n)</entry>
5305 <entry>StringInsert_</entry>
5306 </row>
5307 <row>
5308 <entry>string&amp; insert(size_type pos,size_type n, charT
5309 c)</entry>
5310 <entry>string&amp; string_insert_(container, pos, n, c)</entry>
5311 <entry>StringInsert_</entry>
5312 </row>
5313 <row>
5314 <entry>string&amp; insert (size_type pos, const string&amp;)</entry>
5315 <entry>string&amp; string_insert_(container, pos,
5316 other_string)</entry>
5317 <entry>StringInsert_</entry>
5318 </row>
5319 <row>
5320 <entry>string&amp; insert (size_type pos, const string&amp;,
5321 size_type pos1, size_type n)</entry>
5322 <entry>string&amp; string_insert_(container, pos, other_string,
5323 pos1, n)</entry>
5324 <entry>StringInsert_</entry>
5325 </row>
5326 <row>
5327 <entry>string&amp; erase(size_type pos=0, size_type n=npos)</entry>
5328 <entry>string&amp; string_erase_(container, pos, n)</entry>
5329 <entry>StringErase_</entry>
5330 </row>
5331 <row>
5332 <entry>string&amp; assign(const string&amp;)</entry>
5333 <entry>string&amp; string_assign_(container, another_string)</entry>
5334 <entry>StringAssign_</entry>
5335 </row>
5336 <row>
5337 <entry>string&amp; assign(const charT*)</entry>
5338 <entry>string&amp; string_assign_(container, another_string)</entry>
5339 <entry>StringAssign_</entry>
5340 </row>
5341 <row>
5342 <entry>string&amp; assign(const string&amp;, size_type pos,
5343 size_type n)</entry>
5344 <entry>string&amp; string_assign_(container, another_string, pos,
5345 n)</entry>
5346 <entry>StringAssign_</entry>
5347 </row>
5348 <row>
5349 <entry>string&amp; assign(const charT*, size_type n)</entry>
5350 <entry>string&amp; string_assign_(container, another_string,
5351 n)</entry>
5352 <entry>StringAssign_</entry>
5353 </row>
5354 <row>
5355 <entry>string&amp; assign(size_type n, charT c)</entry>
5356 <entry>string&amp; string_assign_(container, n, c)</entry>
5357 <entry>StringAssign_</entry>
5358 </row>
5359 <row>
5360 <entry>string&amp; assign(iterator first, iterator last)</entry>
5361 <entry>string&amp; string_assign_(container, first, last)</entry>
5362 <entry>StringAssign_</entry>
5363 </row>
5364 <row>
5365 <entry>string&amp; replace(size_type pos, size_type n, const
5366 string&amp;)</entry>
5367 <entry>string&amp; string_replace_(container, pos, n,
5368 another_string)</entry>
5369 <entry>StringReplace_</entry>
5370 </row>
5371 <row>
5372 <entry>string&amp; replace(size_type pos, size_type n, const charT*,
5373 size_type n1)</entry>
5374 <entry>string&amp; string_replace_(container, pos, n,
5375 another_string, n1)</entry>
5376 <entry>StringReplace_</entry>
5377 </row>
5378 <row>
5379 <entry>string&amp; replace(size_type pos, size_type n, const
5380 charT*)</entry>
5381 <entry>string&amp; string_replace_(container, pos, n,
5382 another_string)</entry>
5383 <entry>StringReplace_</entry>
5384 </row>
5385 <row>
5386 <entry>string&amp; replace(size_type pos, size_type n, size_type n1,
5387 charT c)</entry>
5388 <entry>string&amp; string_replace_(container, pos, n, n1, c)</entry>
5389 <entry>StringReplace_</entry>
5390 </row>
5391 <row>
5392 <entry>string&amp; replace(iterator first, iterator last, const
5393 string&amp;)</entry>
5394 <entry>string&amp; string_replace_(container, first, last,
5395 another_string)</entry>
5396 <entry>StringReplace_</entry>
5397 </row>
5398 <row>
5399 <entry>string&amp; replace(iterator first, iterator last, const
5400 charT*, size_type n)</entry>
5401 <entry>string&amp; string_replace_(container, first, last,
5402 another_string, n)</entry>
5403 <entry>StringReplace_</entry>
5404 </row>
5405 <row>
5406 <entry>string&amp; replace(iterator first, iterator last, const
5407 charT*)</entry>
5408 <entry>string&amp; string_replace_(container, first, last,
5409 another_string)</entry>
5410 <entry>StringReplace_</entry>
5411 </row>
5412 <row>
5413 <entry>string&amp; replace(iterator first, iterator last, size_type
5414 n, charT c)</entry>
5415 <entry>string&amp; string_replace_(container, first, last, n,
5416 c)</entry>
5417 <entry>StringReplace_</entry>
5418 </row>
5419 <row>
5420 <entry>string&amp; replace(iterator first, iterator last, iterator
5421 f, iterator l)</entry>
5422 <entry>string&amp; string_replace_(container, first, last, f,
5423 l)</entry>
5424 <entry>StringReplace_</entry>
5425 </row>
5426 <row>
5427 <entry>const charT* c_str()</entry>
5428 <entry>const charT* c_str_(container)</entry>
5429 <entry>CStr_</entry>
5430 </row>
5431 <row>
5432 <entry>const charT* data()</entry>
5433 <entry>const charT* string_data_(container)</entry>
5434 <entry>StringData_</entry>
5435 </row>
5436 <row>
5437 <entry>size_type copy(charT* buf, size_type n, size_type pos =
5438 0)</entry>
5439 <entry>size_type string_copy_(container, buf, n, pos); size_type
5440 string_copy_(container, buf, n) </entry>
5441 <entry>StringCopy_</entry>
5442 </row>
5443 <row>
5444 <entry>size_type find(charT* s, size_type pos, size_type n)</entry>
5445 <entry>size_type string_find_(container, s, pos, n)</entry>
5446 <entry>StringFind_</entry>
5447 </row>
5448 <row>
5449 <entry>size_type find(charT* s, size_type pos=0)</entry>
5450 <entry>size_type string_find_(container, s, pos); size_type
5451 string_find_(container, s) </entry>
5452 <entry>StringFind_</entry>
5453 </row>
5454 <row>
5455 <entry>size_type find(const string&amp; s, size_type pos=0)</entry>
5456 <entry>size_type string_find_(container, s, pos) size_type
5457 string_find_(container, s) </entry>
5458 <entry>StringFind_</entry>
5459 </row>
5460 <row>
5461 <entry>size_type find(charT c, size_type pos=0)</entry>
5462 <entry>size_type string_find_(container, c, pos) size_type
5463 string_find_(container, c) </entry>
5464 <entry>StringFind_</entry>
5465 </row>
5466 <row>
5467 <entry>size_type rfind(charT* s, size_type pos, size_type n)</entry>
5468 <entry>size_type string_rfind_(container, s, pos, n)</entry>
5469 <entry>StringRFind_</entry>
5470 </row>
5471 <row>
5472 <entry>size_type rfind(charT* s, size_type pos=npos)</entry>
5473 <entry>size_type string_rfind_(container, s, pos); size_type
5474 string_rfind_(container, s) </entry>
5475 <entry>StringRFind_</entry>
5476 </row>
5477 <row>
5478 <entry>size_type rfind(const string&amp; s, size_type
5479 pos=npos)</entry>
5480 <entry>size_type string_rfind_(container, s, pos); size_type
5481 string_rfind_(container, s) </entry>
5482 <entry>StringRFind_</entry>
5483 </row>
5484 <row>
5485 <entry>size_type rfind(charT c, size_type pos=npos)</entry>
5486 <entry>size_type string_rfind_(container, c, pos) size_type
5487 string_rfind_(container, c) </entry>
5488 <entry>StringRFind_</entry>
5489 </row>
5490 <row>
5491 <entry>size_type find_first_of(charT* s, size_type pos, size_type
5492 n)</entry>
5493 <entry>size_type find_first_of_(container, s, pos, n)</entry>
5494 <entry>StringFindFirstOf_</entry>
5495 </row>
5496 <row>
5497 <entry>size_type find_first_of (charT* s, size_type pos=0)</entry>
5498 <entry>size_type find_first_of_(container, s, pos); size_type
5499 find_first_of_(container, s) </entry>
5500 <entry>StringFindFirstOf_</entry>
5501 </row>
5502 <row>
5503 <entry>size_type find_first_of (const string&amp; s, size_type
5504 pos=0)</entry>
5505 <entry>size_type find_first_of_(container, s, pos); size_type
5506 find_first_of_(container, s) </entry>
5507 <entry>StringFindFirstOf_</entry>
5508 </row>
5509 <row>
5510 <entry>size_type find_first_of (charT c, size_type pos=0)</entry>
5511 <entry>size_type find_first_of_(container, c, pos) size_type
5512 find_first_of_(container, c) </entry>
5513 <entry>StringFindFirstOf_</entry>
5514 </row>
5515 <row>
5516 <entry>size_type find_first_not_of(charT* s, size_type pos,
5517 size_type n)</entry>
5518 <entry>size_type find_first_not_of_(container, s, pos, n)</entry>
5519 <entry>StringFindFirstNotOf_</entry>
5520 </row>
5521 <row>
5522 <entry>size_type find_first_not_of (charT* s, size_type
5523 pos=0)</entry>
5524 <entry>size_type find_first_not_of_(container, s, pos); size_type
5525 find_first_not_of_(container, s) </entry>
5526 <entry>StringFindFirstNotOf_</entry>
5527 </row>
5528 <row>
5529 <entry>size_type find_first_not_of (const string&amp; s, size_type
5530 pos=0)</entry>
5531 <entry>size_type find_first_not_of_(container, s, pos); size_type
5532 find_first_not_of_(container, s) </entry>
5533 <entry>StringFindFirstNotOf_</entry>
5534 </row>
5535 <row>
5536 <entry>size_type find_first_not_of (charT c, size_type
5537 pos=0)</entry>
5538 <entry>size_type find_first_not_of_(container, c, pos); size_type
5539 find_first_not_of_(container, c) </entry>
5540 <entry>StringFindFirstNotOf_</entry>
5541 </row>
5542 <row>
5543 <entry>size_type find_last_of(charT* s, size_type pos, size_type
5544 n)</entry>
5545 <entry>size_type find_last_of_(container, s, pos, n)</entry>
5546 <entry>StringFindLastOf_</entry>
5547 </row>
5548 <row>
5549 <entry>size_type find_last_of (charT* s, size_type pos=npos)</entry>
5550 <entry>size_type find_last_of_(container, s, pos); size_type
5551 find_last_of_(container, s) </entry>
5552 <entry>StringFindLastOf_</entry>
5553 </row>
5554 <row>
5555 <entry>size_type find_last_of (const string&amp; s, size_type
5556 pos=npos)</entry>
5557 <entry>size_type find_last_of_(container, s, pos); size_type
5558 find_last_of_(container, s) </entry>
5559 <entry>StringFindLastOf_</entry>
5560 </row>
5561 <row>
5562 <entry>size_type find_last_of (charT c, size_type pos=npos)</entry>
5563 <entry>size_type find_last_of_(container, c, pos); size_type
5564 find_last_of_(container, c) </entry>
5565 <entry>StringFindLastOf_</entry>
5566 </row>
5567 <row>
5568 <entry>size_type find_last_not_of(charT* s, size_type pos, size_type
5569 n)</entry>
5570 <entry>size_type find_last_not_of_(container, s, pos, n)</entry>
5571 <entry>StringFindLastNotOf_</entry>
5572 </row>
5573 <row>
5574 <entry>size_type find_last_not_of (charT* s, size_type
5575 pos=npos)</entry>
5576 <entry>size_type find_last_not_of_(container, s, pos); size_type
5577 find_last_of_(container, s) </entry>
5578 <entry>StringFindLastNotOf_</entry>
5579 </row>
5580 <row>
5581 <entry>size_type find_last_not_of (const string&amp; s, size_type
5582 pos=npos)</entry>
5583 <entry>size_type find_last_not_of_(container, s, pos); size_type
5584 find_last_not_of_(container, s) </entry>
5585 <entry>StringFindLastNotOf_</entry>
5586 </row>
5587 <row>
5588 <entry>size_type find_last_not_of (charT c, size_type
5589 pos=npos)</entry>
5590 <entry>size_type find_last_not_of_(container, c, pos); size_type
5591 find_last_not_of_(container, c) </entry>
5592 <entry>StringFindLastNotOf_</entry>
5593 </row>
5594 </tbody>
5595 </tgroup>
5596 </table>
5597 </para>
5598 <para><emphasis role="underline">Notes</emphasis>: <itemizedlist>
5599 <listitem>
5600 <para>ᵃ: algorithms requiring a predicate need to make them eUML compatible
5601 by wrapping them inside a Predicate_ functor. For example,
5602 std::less&lt;int> => Predicate_&lt;std::less&lt;int> >()</para>
5603 </listitem>
5604 <listitem>
5605 <para>ᵇ: If using the SGI STL implementation, these functors use the SGI
5606 return value</para>
5607 </listitem>
5608 </itemizedlist>
5609 </para>
5610 </chapter>
5611 <refentry>
5612 <refnamediv>
5613 <refname>Common headers</refname>
5614 <refpurpose>The common types used by front- and back-ends</refpurpose>
5615 </refnamediv>
5616 <refsect1>
5617 <title>msm/common.hpp</title>
5618 <para>This header provides one type, wrap, which is an empty type whose only reason
5619 to exist is to be cheap to construct, so that it can be used with mpl::for_each,
5620 as shown in the Metaprogramming book, chapter 9.</para>
5621 <classsynopsis>
5622 <ooclass>
5623 <classname>template &lt;class Dummy> wrap{};</classname>
5624 </ooclass>
5625 </classsynopsis>
5626 </refsect1>
5627 <refsect1>
5628 <title>msm/row_tags.hpp</title>
5629 <para>This header contains the row type tags which front-ends can support partially
5630 or totally. Please see the <command xlink:href="#internals-front-back-interface"
5631 >Internals</command> section for a description of the different
5632 types.</para>
5633 </refsect1>
5634 </refentry>
5635 <refentry>
5636 <refnamediv>
5637 <refname>Back-end</refname>
5638 <refpurpose>The back-end headers</refpurpose>
5639 </refnamediv>
5640 <refsect1>
5641 <title>msm/back/state_machine.hpp</title>
5642 <para> This header provides one type, state_machine, MSM's state machine engine
5643 implementation.</para>
5644 <classsynopsis>
5645 <ooclass>
5646 <classname>template &lt;class Derived,class HistoryPolicy=NoHistory,class
5647 CompilePolicy=favor_runtime_speed> state_machine</classname>
5648 </ooclass>
5649 </classsynopsis>
5650 <refsect2>
5651 <title> Template arguments </title>
5652 <refsect3>
5653 <title> Derived </title>
5654 <para>The name of the front-end state machine definition. All three
5655 front-ends are possible.</para>
5656 </refsect3>
5657 <refsect3>
5658 <title> HistoryPolicy </title>
5659 <para>The desired history. This can be: AlwaysHistory, NoHistory,
5660 ShallowHistory. Default is NoHistory.</para>
5661 </refsect3>
5662 <refsect3>
5663 <title> CompilePolicy </title>
5664 <para>The trade-off performance / compile-time. There are two predefined
5665 policies, favor_runtime_speed and favor_compile_time. Default is
5666 favor_runtime_speed, best performance, longer compile-time. See <link
5667 xlink:href="#backend-tradeof-rt-ct">the backend</link>.</para>
5668 </refsect3>
5669 </refsect2>
5670 <refsect2>
5671 <title> methods </title>
5672 <refsect3>
5673 <title>start</title>
5674 <para> The start methods must be called before any call to process_event. It
5675 activates the entry action of the initial state(s). This allows you to
5676 choose when a state machine can start. See <link
5677 xlink:href="#backend-start">backend</link>.</para>
5678 <methodsynopsis>
5679 <methodname>void start</methodname>
5680 <methodparam>
5681 <funcparams/>
5682 </methodparam>
5683 </methodsynopsis>
5684 </refsect3>
5685 <refsect3>
5686 <title>process_event</title>
5687 <para>The event processing method implements the double-dispatch. Each call
5688 to this function with a new event type instantiates a new dispatch
5689 algorithm and increases compile-time.</para>
5690 <methodsynopsis>
5691 <methodname>template &lt;class Event> HandledEnum
5692 process_event</methodname>
5693 <methodparam>
5694 <funcparams>Event const&amp;</funcparams>
5695 </methodparam>
5696 </methodsynopsis>
5697 </refsect3>
5698 <refsect3>
5699 <title>current_state</title>
5700 <para>Returns the ids of currently active states. You will typically need it
5701 only for debugging or logging purposes.</para>
5702 <methodsynopsis>
5703 <methodname>const int* current_state const</methodname>
5704 <methodparam>
5705 <funcparams/>
5706 </methodparam>
5707 </methodsynopsis>
5708 </refsect3>
5709 <refsect3>
5710 <title>get_state_by_id</title>
5711 <para>Returns the state whose id is given. As all states of a concrete state
5712 machine share a common base state, the return value is a base state. If
5713 the id corresponds to no state, a null pointer is returned.</para>
5714 <methodsynopsis>
5715 <methodname>const BaseState* get_state_by_id const</methodname>
5716 <methodparam>
5717 <funcparams>int id</funcparams>
5718 </methodparam>
5719 </methodsynopsis>
5720 </refsect3>
5721 <refsect3>
5722 <title>is_contained</title>
5723 <para>Helper returning true if the state machine is contained as a
5724 submachine of another state machine.</para>
5725 <methodsynopsis>
5726 <methodname>bool is_contained const</methodname>
5727 <methodparam>
5728 <funcparams/>
5729 </methodparam>
5730 </methodsynopsis>
5731 </refsect3>
5732 <refsect3>
5733 <title>get_state</title>
5734 <para>Returns the required state of the state machine as a pointer. A
5735 compile error will occur if the state is not to be found in the state
5736 machine.</para>
5737 <methodsynopsis>
5738 <methodname>template &lt;class State> State* get_state</methodname>
5739 <methodparam>
5740 <funcparams/>
5741 </methodparam>
5742 </methodsynopsis>
5743 </refsect3>
5744 <refsect3>
5745 <title>get_state</title>
5746 <para>Returns the required state of the state machine as a reference. A
5747 compile error will occur if the state is not to be found in the state
5748 machine.</para>
5749 <methodsynopsis>
5750 <methodname>template &lt;class State> State&amp; get_state</methodname>
5751 <methodparam>
5752 <funcparams/>
5753 </methodparam>
5754 </methodsynopsis>
5755 </refsect3>
5756 <refsect3>
5757 <title>is_flag_active</title>
5758 <para>Returns true if the given flag is currently active. A flag is active
5759 if the active state of one region is tagged with this flag (using OR as
5760 BinaryOp) or active states of <emphasis role="underline">all</emphasis>
5761 regions (using AND as BinaryOp)</para>
5762 <methodsynopsis>
5763 <methodname>template &lt;class Flag,class BinaryOp> bool
5764 is_flag_active</methodname>
5765 <methodparam>
5766 <funcparams/>
5767 </methodparam>
5768 </methodsynopsis>
5769 </refsect3>
5770 <refsect3>
5771 <title>is_flag_active</title>
5772 <para>Returns true if the given flag is currently active. A flag is active
5773 if the active state of one region is tagged with this flag.</para>
5774 <methodsynopsis>
5775 <methodname>template &lt;class Flag> bool is_flag_active</methodname>
5776 <methodparam>
5777 <funcparams/>
5778 </methodparam>
5779 </methodsynopsis>
5780 </refsect3>
5781 <refsect3>
5782 <title>visit_current_states</title>
5783 <para>Visits all active states and their substates. A state is visited using
5784 the <code>accept</code> method without argument. The base class of all
5785 states must provide an <code>accept_sig</code> type.</para>
5786 <methodsynopsis>
5787 <methodname>void visit_current_states</methodname>
5788 <methodparam>
5789 <funcparams/>
5790 </methodparam>
5791 </methodsynopsis>
5792 </refsect3>
5793 <refsect3>
5794 <title>visit_current_states</title>
5795 <para>Visits all active states and their substates. A state is visited using
5796 the <code>accept</code> method with arguments. The base class of all
5797 states must provide an <code>accept_sig</code> type defining the
5798 signature and thus the number and type of the parameters.</para>
5799 <methodsynopsis>
5800 <methodname>void visit_current_states</methodname>
5801 <methodparam>
5802 <funcparams>any-type param1, any-type param2,...</funcparams>
5803 </methodparam>
5804 </methodsynopsis>
5805 </refsect3>
5806 <refsect3>
5807 <title>defer_event</title>
5808 <para> Defers the provided event. This method can be called only if at least
5809 one state defers an event or if the state machine provides the
5810 <code>activate_deferred_events</code>(see <link
5811 xlink:href="examples/Orthogonal-deferred2.cpp">example</link>) type
5812 either directly or using the deferred_events configuration of eUML
5813 (<code>configure_ &lt;&lt; deferred_events</code>)</para>
5814 <methodsynopsis>
5815 <methodname>template &lt;class Event> void defer_event</methodname>
5816 <methodparam>
5817 <funcparams>Event const&amp;</funcparams>
5818 </methodparam>
5819 </methodsynopsis>
5820 </refsect3>
5821 </refsect2>
5822 <refsect2>
5823 <title>Types</title>
5824 <refsect3>
5825 <title>nr_regions </title>
5826 <para>The number of orthogonal regions contained in the state machine</para>
5827 </refsect3>
5828 <refsect3>
5829 <title>entry_pt</title>
5830 <para>This nested type provides the necessary typedef for entry point
5831 pseudostates.
5832 <code>state_machine&lt;...>::entry_pt&lt;state_name></code> is a
5833 transition's valid target inside the containing state machine's
5834 transition table.</para>
5835 <classsynopsis>
5836 <ooclass>
5837 <classname>entry_pt</classname>
5838 </ooclass>
5839 </classsynopsis>
5840 </refsect3>
5841 <refsect3>
5842 <title>exit_pt</title>
5843 <para>This nested type provides the necessary typedef for exit point
5844 pseudostates. <code>state_machine&lt;...>::exit_pt&lt;state_name></code>
5845 is a transition's valid source inside the containing state machine's
5846 transition table.</para>
5847 <classsynopsis>
5848 <ooclass>
5849 <classname>exit_pt</classname>
5850 </ooclass>
5851 </classsynopsis>
5852 </refsect3>
5853 <refsect3>
5854 <title>direct</title>
5855 <para>This nested type provides the necessary typedef for an explicit entry
5856 inside a submachine.
5857 <code>state_machine&lt;...>::direct&lt;state_name></code> is a
5858 transition's valid target inside the containing state machine's
5859 transition table.</para>
5860 <classsynopsis>
5861 <ooclass>
5862 <classname>direct</classname>
5863 </ooclass>
5864 </classsynopsis>
5865 </refsect3>
5866 <refsect3>
5867 <title>stt</title>
5868 <para>Calling state_machine&lt;frontend>::stt returns a mpl::vector
5869 containing the transition table of the state machine. This type can then
5870 be used with generate_state_set or generate_event_set.</para>
5871 </refsect3>
5872 </refsect2>
5873 </refsect1>
5874 <refsect1>
5875 <title>args.hpp</title>
5876 <para>This header provides one type, args. which provides the necessary types for a
5877 visitor implementation.</para>
5878 </refsect1>
5879 <refsect1>
5880 <title><command xml:id="history-interface"/>msm/back/history_policies.hpp</title>
5881 <para>This header provides the out-of-the-box history policies supported by MSM.
5882 There are 3 such policies.</para>
5883 <refsect2>
5884 <title>Every history policy must implement the following methods: </title>
5885 <refsect3>
5886 <title> set_initial_states </title>
5887 <para> This method is called by msm::back::state_machine when constructed.
5888 It gives the policy a chance to save the ids of all initial states
5889 (passed as array).</para>
5890 <funcsynopsis>
5891 <funcprototype>
5892 <funcdef>void set_initial_states</funcdef>
5893 <paramdef>
5894 <funcparams>int* const</funcparams>
5895 </paramdef>
5896 </funcprototype>
5897 </funcsynopsis>
5898 </refsect3>
5899 <refsect3>
5900 <title> history_exit </title>
5901 <para>This method is called by msm::back::state_machine when the submachine
5902 is exited. It gives the policy a chance to remember the ids of the last
5903 active substates of this submachine (passed as array).</para>
5904 <funcsynopsis>
5905 <funcprototype>
5906 <funcdef>void history_exit</funcdef>
5907 <paramdef>
5908 <funcparams>int* const</funcparams>
5909 </paramdef>
5910 </funcprototype>
5911 </funcsynopsis>
5912 </refsect3>
5913 <refsect3>
5914 <title> history_entry </title>
5915 <para>This method is called by msm::back::state_machine when the submachine
5916 is entered. It gives the policy a chance to set the active states
5917 according to the policy's aim. The policy gets as parameter the event
5918 which activated the submachine and returns an array of active states
5919 ids.</para>
5920 <funcsynopsis>
5921 <funcprototype>
5922 <funcdef>template &lt;class Event> int* const history_exit</funcdef>
5923 <paramdef>
5924 <funcparams>Event const&amp;</funcparams>
5925 </paramdef>
5926 </funcprototype>
5927 </funcsynopsis>
5928 </refsect3>
5929 </refsect2>
5930 <refsect2>
5931 <title>Out-of-the-box policies: </title>
5932 <refsect3>
5933 <title>NoHistory</title>
5934 <para>This policy is the default used by state_machine. No active state of a
5935 submachine is remembered and at every new activation of the submachine,
5936 the initial state(s) are activated. </para>
5937 </refsect3>
5938 <refsect3>
5939 <title>AlwaysHistory</title>
5940 <para>This policy is a non-UML-standard extension. The active state(s) of a
5941 submachine is (are) always remembered at every new activation of the
5942 submachine. </para>
5943 </refsect3>
5944 <refsect3>
5945 <title>ShallowHistory</title>
5946 <para>This policy activates the active state(s) of a submachine if the event
5947 is found in the policy's event list. </para>
5948 </refsect3>
5949 </refsect2>
5950 </refsect1>
5951 <refsect1>
5952 <title>msm/back/default_compile_policy.hpp</title>
5953 <para>This header contains the definition of favor_runtime_speed. This policy has
5954 two settings:<itemizedlist>
5955 <listitem>
5956 <para>Submachines dispatch faster because their transitions are added
5957 into their containing machine's transition table instead of simply
5958 forwarding events.</para>
5959 </listitem>
5960 <listitem>
5961 <para>It solves transition conflicts at compile-time</para>
5962 </listitem>
5963 </itemizedlist></para>
5964 </refsect1>
5965 <refsect1>
5966 <title>msm/back/favor_compile_time.hpp</title>
5967 <para>This header contains the definition of favor_compile_time. This policy has two settings:<itemizedlist>
5968 <listitem>
5969 <para>Submachines dispatch is slower because all events, even those with
5970 no dispatch chance, are forwarded to submachines. In exchange, no
5971 row is added into the containing machine's transition table, which
5972 reduces compile-time.</para>
5973 </listitem>
5974 <listitem>
5975 <para>It solves transition conflicts at run-time.</para>
5976 </listitem>
5977 </itemizedlist></para>
5978 </refsect1>
5979 <refsect1>
5980 <title>msm/back/metafunctions.hpp </title>
5981 <para>This header contains metafunctions for use by the library. Three metafunctions
5982 can be useful for the user:<itemizedlist>
5983 <listitem>
5984 <para><code>generate_state_set&lt; stt ></code>: generates the list of
5985 all states referenced by the transition table stt. If stt is a
5986 recursive table (generated by
5987 <code>recursive_get_transition_table</code>), the metafunction
5988 finds recursively all states of the submachines. A non-recursive
5989 table can be obtained with some_backend_fsm::stt.</para>
5990 </listitem>
5991 <listitem>
5992 <para><code>generate_event_set&lt; stt></code>: generates the list of
5993 all events referenced by the transition table stt. If stt is a
5994 recursive table (generated by
5995 <code>recursive_get_transition_table</code>), the metafunction
5996 finds recursively all events of the submachines. A non-recursive
5997 table can be obtained with some_backend_fsm::stt.</para>
5998 </listitem>
5999 <listitem>
6000 <para><code>recursive_get_transition_table&lt;fsm></code>: recursively
6001 extends the transition table of the state machine fsm with tables
6002 from the submachines.</para>
6003 </listitem>
6004 </itemizedlist></para>
6005 </refsect1>
6006 <refsect1>
6007 <title>msm/back/tools.hpp </title>
6008 <para> This header contains a few metaprogramming tools to get some information out
6009 of a state machine.</para>
6010 <refsect2>
6011 <title>fill_state_names </title>
6012 <refsect3>
6013 <title>attributes </title>
6014 <para> fill_state_names has for attribute:<itemizedlist>
6015 <listitem>
6016 <para><code>char const** m_names</code>: an already allocated
6017 array of const char* where the typeid-generated names of a
6018 state machine states will be witten.</para>
6019 </listitem>
6020 </itemizedlist></para>
6021 </refsect3>
6022 <refsect3>
6023 <title>constructor </title>
6024 <constructorsynopsis>
6025 <methodparam>
6026 <funcparams>char const** names_to_fill</funcparams>
6027 </methodparam>
6028 </constructorsynopsis>
6029 </refsect3>
6030 <refsect3>
6031 <title>usage</title>
6032 <para> fill_state_names is made for use in a mpl::for_each iterating on a
6033 state list and writing inside a pre-allocated array the state names.
6034 Example:</para>
6035 <programlisting>typedef some_fsm::stt Stt;
6036 typedef msm::back::generate_state_set&lt;Stt>::type all_states; //states
6037 static char const* state_names[mpl::size&lt;all_states>::value];
6038 // array to fill with names
6039 // fill the names of the states defined in the state machine
6040 mpl::for_each&lt;all_states,boost::msm::wrap&lt;mpl::placeholders::_1> >
6041 (msm::back::fill_state_names&lt;Stt>(state_names));
6042 // display all active states
6043 for (unsigned int i=0;i&lt;some_fsm::nr_regions::value;++i)
6044 {
6045 std::cout &lt;&lt; " -> "
6046 &lt;&lt; state_names[my_fsm_instance.current_state()[i]]
6047 &lt;&lt; std::endl;
6048 }</programlisting>
6049 </refsect3>
6050 </refsect2>
6051 <refsect2>
6052 <title>get_state_name </title>
6053 <refsect3>
6054 <title> attributes </title>
6055 <para>get_state_name has for attributes:<itemizedlist>
6056 <listitem>
6057 <para>std::string&amp; m_name: the return value of the
6058 iteration</para>
6059 </listitem>
6060 <listitem>
6061 <para>int m_state_id: the searched state's id</para>
6062 </listitem>
6063 </itemizedlist></para>
6064 </refsect3>
6065 <refsect3>
6066 <title>constructor</title>
6067 <para>The constructor takes as argument a reference to the string to fill
6068 with the state name and the id which must be searched.</para>
6069 <constructorsynopsis>
6070 <methodparam>
6071 <funcparams>string&amp; name_to_fill,int state_id</funcparams>
6072 </methodparam>
6073 </constructorsynopsis>
6074 </refsect3>
6075 <refsect3>
6076 <title> usage</title>
6077 <para>This type is made for the same search as in the previous example,
6078 using a mpl::for_each to iterate on states. After the iteration, the
6079 state name reference has been set.</para>
6080 <programlisting>// we need a fsm's table
6081 typedef player::stt Stt;
6082 typedef msm::back::generate_state_set&lt;Stt>::type all_states; //all states
6083 std::string name_of_open; // id of Open is 1
6084 // fill name_of_open for state of id 1
6085 boost::mpl::for_each&lt;all_states,boost::msm::wrap&lt;mpl::placeholders::_1> >
6086 (msm::back::get_state_name&lt;Stt>(name_of_open,1));
6087 std::cout &lt;&lt; "typeid-generated name Open is: " &lt;&lt; name_of_open &lt;&lt; std::endl;</programlisting>
6088 </refsect3>
6089 </refsect2>
6090 <refsect2>
6091 <title>display_type </title>
6092 <refsect3>
6093 <title> attributes </title>
6094 <para>none</para>
6095 </refsect3>
6096 <refsect3>
6097 <title> usage</title>
6098 <para>Reusing the state list from the previous example, we can output all
6099 state names:</para>
6100 <para><code>mpl::for_each&lt;all_states,boost::msm::wrap&lt;mpl::placeholders::_1>
6101 >(msm::back::display_type ());</code></para>
6102 </refsect3>
6103 </refsect2>
6104 </refsect1>
6105 </refentry>
6106 <refentry>
6107 <refnamediv>
6108 <refname>Front-end</refname>
6109 <refpurpose>The front-end headers</refpurpose>
6110 </refnamediv>
6111 <refsect1>
6112 <title>msm/front/common_states.hpp</title>
6113 <para>This header contains the predefined types to serve as base for states or state machines:<itemizedlist>
6114 <listitem>
6115 <para>default_base_state: non-polymorphic empty type.</para>
6116 </listitem>
6117 <listitem>
6118 <para>polymorphic_state: type with a virtual destructor, which makes all
6119 states polymorphic.</para>
6120 </listitem>
6121 </itemizedlist></para>
6122 </refsect1>
6123 <refsect1>
6124 <title>msm/front/completion_event.hpp</title>
6125 <para>This header contains one type, <code>none</code>. This type has several
6126 meanings inside a transition table:<itemizedlist>
6127 <listitem>
6128 <para>as action or guard: that there is no action or guard</para>
6129 </listitem>
6130 <listitem>
6131 <para>as target state: that the transition is an internal
6132 transition</para>
6133 </listitem>
6134 <listitem>
6135 <para>as event: the transition is an anonymous (completion)
6136 transition</para>
6137 </listitem>
6138 </itemizedlist></para>
6139 </refsect1>
6140 <refsect1>
6141 <title>msm/front/functor_row.hpp</title>
6142 <para>This header implements the functor front-end's transitions and helpers.</para>
6143 <refsect2>
6144 <title>Row</title>
6145 <refsect3>
6146 <title>definition</title>
6147 <classsynopsis>
6148 <ooclass>
6149 <classname>template &lt;class Source,class Event,class Target,class
6150 Action,class Guard> Row</classname>
6151 </ooclass>
6152 </classsynopsis>
6153 </refsect3>
6154 <refsect3>
6155 <title>tags</title>
6156 <para>row_type_tag is defined differently for every specialization:<itemizedlist>
6157 <listitem>
6158 <para>all 5 template parameters means a normal transition with
6159 action and guard: <code>typedef row_tag
6160 row_type_tag;</code></para>
6161 </listitem>
6162 <listitem>
6163 <para>Row&lt;Source,Event,Target,none,none> a normal transition
6164 without action or guard: <code>typedef _row_tag
6165 row_type_tag;</code></para>
6166 </listitem>
6167 <listitem>
6168 <para>Row&lt;Source,Event,Target,Action,none> a normal
6169 transition without guard: <code>typedef a_row_tag
6170 row_type_tag;</code></para>
6171 </listitem>
6172 <listitem>
6173 <para>Row&lt;Source,Event,Target,none,Guard> a normal transition
6174 without action: <code>typedef g_row_tag
6175 row_type_tag;</code></para>
6176 </listitem>
6177 <listitem>
6178 <para>Row&lt;Source,Event,none,Action,none> an internal
6179 transition without guard: <code>typedef a_irow_tag
6180 row_type_tag;</code></para>
6181 </listitem>
6182 <listitem>
6183 <para>Row&lt;Source,Event,none,none,Guard> an internal
6184 transition without action: <code>typedef g_irow_tag
6185 row_type_tag;</code></para>
6186 </listitem>
6187 <listitem>
6188 <para>Row&lt;Source,Event,none,none,Guard> an internal
6189 transition with action and guard: <code>typedef irow_tag
6190 row_type_tag;</code></para>
6191 </listitem>
6192 <listitem>
6193 <para>Row&lt;Source,Event,none,none,none> an internal transition
6194 without action or guard: <code>typedef _irow_tag
6195 row_type_tag;</code></para>
6196 </listitem>
6197 </itemizedlist></para>
6198 </refsect3>
6199 <refsect3>
6200 <title>methods</title>
6201 <para>Like any other front-end, Row implements the two necessary static
6202 functions for action and guard call. Each function receives as parameter
6203 the (deepest-level) state machine processsing the event, the event
6204 itself, the source and target states and all the states contained in a
6205 state machine.</para>
6206 <funcsynopsis>
6207 <funcprototype>
6208 <funcdef>template &lt;class Fsm,class SourceState,class TargetState,
6209 class AllStates> static void action_call</funcdef>
6210 <paramdef>
6211 <funcparams>Fsm&amp; fsm,Event const&amp;
6212 evt,SourceState&amp;,TargetState,AllStates&amp;</funcparams>
6213 </paramdef>
6214 </funcprototype>
6215 </funcsynopsis>
6216 <funcsynopsis>
6217 <funcprototype>
6218 <funcdef>template &lt;class Fsm,class SourceState,class TargetState,
6219 class AllStates> static bool guard_call</funcdef>
6220 <paramdef>
6221 <funcparams>Fsm&amp; fsm,Event const&amp;
6222 evt,SourceState&amp;,TargetState,AllStates&amp;</funcparams>
6223 </paramdef>
6224 </funcprototype>
6225 </funcsynopsis>
6226 </refsect3>
6227 </refsect2>
6228 <refsect2>
6229 <title>Internal</title>
6230 <refsect3>
6231 <title>definition</title>
6232 <classsynopsis>
6233 <ooclass>
6234 <classname>template &lt;class Event,class Action,class Guard>
6235 Internal</classname>
6236 </ooclass>
6237 </classsynopsis>
6238 </refsect3>
6239 <refsect3>
6240 <title>tags</title>
6241 <para>row_type_tag is defined differently for every specialization:<itemizedlist>
6242 <listitem>
6243 <para>all 3 template parameters means an internal transition
6244 with action and guard: <code>typedef sm_i_row_tag
6245 row_type_tag;</code></para>
6246 </listitem>
6247 <listitem>
6248 <para>Internal&lt;Event,none,none> an internal transition
6249 without action or guard: <code>typedef sm__i_row_tag
6250 row_type_tag;</code></para>
6251 </listitem>
6252 <listitem>
6253 <para>Internal&lt;Event,Action,none> an internal transition
6254 without guard: <code>typedef sm_a_i_row_tag
6255 row_type_tag;</code></para>
6256 </listitem>
6257 <listitem>
6258 <para>Internal&lt;Event,none,Guard> an internal transition
6259 without action: <code>typedef sm_g_i_row_tag
6260 row_type_tag;</code></para>
6261 </listitem>
6262 </itemizedlist></para>
6263 </refsect3>
6264 <refsect3>
6265 <title>methods</title>
6266 <para>Like any other front-end, Internal implements the two necessary static
6267 functions for action and guard call. Each function receives as parameter
6268 the (deepest-level) state machine processsing the event, the event
6269 itself, the source and target states and all the states contained in a
6270 state machine.</para>
6271 <funcsynopsis>
6272 <funcprototype>
6273 <funcdef>template &lt;class Fsm,class SourceState,class TargetState,
6274 class AllStates> static void action_call</funcdef>
6275 <paramdef>
6276 <funcparams>Fsm&amp; fsm,Event const&amp;
6277 evt,SourceState&amp;,TargetState,AllStates&amp;</funcparams>
6278 </paramdef>
6279 </funcprototype>
6280 </funcsynopsis>
6281 <funcsynopsis>
6282 <funcprototype>
6283 <funcdef>template &lt;class Fsm,class SourceState,class TargetState,
6284 class AllStates> static bool guard_call</funcdef>
6285 <paramdef>
6286 <funcparams>Fsm&amp; fsm,Event const&amp;
6287 evt,SourceState&amp;,TargetState,AllStates&amp;</funcparams>
6288 </paramdef>
6289 </funcprototype>
6290 </funcsynopsis>
6291 </refsect3>
6292 </refsect2>
6293 <refsect2>
6294 <title>ActionSequence_</title>
6295 <para>This functor calls every element of the template Sequence (which are also
6296 callable functors) in turn. It is also the underlying implementation of the
6297 eUML sequence grammar (action1,action2,...).</para>
6298 <refsect3>
6299 <title>definition</title>
6300 <classsynopsis>
6301 <ooclass>
6302 <classname>template &lt;class Sequence> ActionSequence_</classname>
6303 </ooclass>
6304 </classsynopsis>
6305 </refsect3>
6306 <refsect3>
6307 <title>methods</title>
6308 <para>This helper functor is made for use in a transition table and in a
6309 state behavior and therefore implements an operator() with 3 and with 4
6310 arguments:</para>
6311 <para>
6312 <funcsynopsis>
6313 <funcprototype>
6314 <funcdef>template &lt;class Evt,class Fsm,class
6315 SourceState,class TargetState> operator()</funcdef>
6316 <paramdef>Evt const&amp; ,Fsm&amp; ,SourceState&amp;
6317 ,TargetState&amp; </paramdef>
6318 </funcprototype>
6319 </funcsynopsis>
6320 </para>
6321 <para>
6322 <funcsynopsis>
6323 <funcprototype>
6324 <funcdef>template &lt;class Evt,class Fsm,class State>
6325 operator()</funcdef>
6326 <paramdef>Evt const&amp;, Fsm&amp;, State&amp;</paramdef>
6327 </funcprototype>
6328 </funcsynopsis>
6329 </para>
6330 </refsect3>
6331 </refsect2>
6332 <refsect2>
6333 <title>Defer</title>
6334 <refsect3>
6335 <title>definition</title>
6336 <classsynopsis>
6337 <ooclass>
6338 <classname>Defer</classname>
6339 </ooclass>
6340 </classsynopsis>
6341 </refsect3>
6342 <refsect3>
6343 <title>methods</title>
6344 <para>This helper functor is made for use in a transition table and
6345 therefore implements an operator() with 4 arguments:</para>
6346 <funcsynopsis>
6347 <funcprototype>
6348 <funcdef>template &lt;class Evt,class Fsm,class SourceState,class
6349 TargetState> operator()</funcdef>
6350 <paramdef>Evt const&amp;, Fsm&amp; , SourceState&amp;,
6351 TargetState&amp;</paramdef>
6352 </funcprototype>
6353 </funcsynopsis>
6354 </refsect3>
6355 </refsect2>
6356 </refsect1>
6357 <refsect1>
6358 <title>msm/front/internal_row.hpp</title>
6359 <para>This header implements the internal transition rows for use inside an
6360 internal_transition_table. All these row types have no source or target state,
6361 as the backend will recognize internal transitions from this
6362 internal_transition_table.</para>
6363 <refsect2>
6364 <title>methods</title>
6365 <para>Like any other front-end, the following transition row types implements
6366 the two necessary static functions for action and guard call. Each function
6367 receives as parameter the (deepest-level) state machine processsing the
6368 event, the event itself, the source and target states and all the states
6369 contained in a state machine.</para>
6370 <funcsynopsis>
6371 <funcprototype>
6372 <funcdef>template &lt;class Fsm,class SourceState,class TargetState,
6373 class AllStates> static void action_call</funcdef>
6374 <paramdef>
6375 <funcparams>Fsm&amp; fsm,Event const&amp;
6376 evt,SourceState&amp;,TargetState,AllStates&amp;</funcparams>
6377 </paramdef>
6378 </funcprototype>
6379 </funcsynopsis>
6380 <funcsynopsis>
6381 <funcprototype>
6382 <funcdef>template &lt;class Fsm,class SourceState,class TargetState,
6383 class AllStates> static bool guard_call</funcdef>
6384 <paramdef>
6385 <funcparams>Fsm&amp; fsm,Event const&amp;
6386 evt,SourceState&amp;,TargetState,AllStates&amp;</funcparams>
6387 </paramdef>
6388 </funcprototype>
6389 </funcsynopsis>
6390 </refsect2>
6391 <refsect2>
6392 <title>a_internal</title>
6393 <refsect3>
6394 <title>definition</title>
6395 <para>This is an internal transition with an action called during the
6396 transition.</para>
6397 <classsynopsis>
6398 <ooclass>
6399 <classname>template&lt; class Event, class CalledForAction, void
6400 (CalledForAction::*action)(Event const&amp;)>
6401 a_internal</classname>
6402 </ooclass>
6403 </classsynopsis>
6404 </refsect3>
6405 <refsect3>
6406 <title>template parameters</title>
6407 <para>
6408 <itemizedlist>
6409 <listitem>
6410 <para>Event: the event triggering the internal
6411 transition.</para>
6412 </listitem>
6413 <listitem>
6414 <para>CalledForAction: the type on which the action method will
6415 be called. It can be either a state of the containing state
6416 machine or the state machine itself.</para>
6417 </listitem>
6418 <listitem>
6419 <para>action: a pointer to the method which CalledForAction
6420 provides.</para>
6421 </listitem>
6422 </itemizedlist>
6423 </para>
6424 </refsect3>
6425 </refsect2>
6426 <refsect2>
6427 <title>g_internal</title>
6428 <para>This is an internal transition with a guard called before the transition
6429 and allowing the transition if returning true.</para>
6430 <refsect3>
6431 <title>definition</title>
6432 <classsynopsis>
6433 <ooclass>
6434 <classname>template&lt; class Event, class CalledForGuard, bool
6435 (CalledForGuard::*guard)(Event const&amp;)>
6436 g_internal</classname>
6437 </ooclass>
6438 </classsynopsis>
6439 </refsect3>
6440 <refsect3>
6441 <title>template parameters</title>
6442 <para>
6443 <itemizedlist>
6444 <listitem>
6445 <para>Event: the event triggering the internal
6446 transition.</para>
6447 </listitem>
6448 <listitem>
6449 <para>CalledForGuard: the type on which the guard method will be
6450 called. It can be either a state of the containing state
6451 machine or the state machine itself.</para>
6452 </listitem>
6453 <listitem>
6454 <para>guard: a pointer to the method which CalledForGuard
6455 provides.</para>
6456 </listitem>
6457 </itemizedlist>
6458 </para>
6459 </refsect3>
6460 </refsect2>
6461 <refsect2>
6462 <title>internal</title>
6463 <para>This is an internal transition with a guard called before the transition
6464 and allowing the transition if returning true. It also calls an action
6465 called during the transition.</para>
6466 <refsect3>
6467 <title>definition</title>
6468 <classsynopsis>
6469 <ooclass>
6470 <classname>template&lt; class Event, class CalledForAction, void
6471 (CalledForAction::*action)(Event const&amp;), class
6472 CalledForGuard, bool (CalledForGuard::*guard)(Event const&amp;)>
6473 internal</classname>
6474 </ooclass>
6475 </classsynopsis>
6476 </refsect3>
6477 <refsect3>
6478 <title>template parameters</title>
6479 <para>
6480 <itemizedlist>
6481 <listitem>
6482 <para>Event: the event triggering the internal transition</para>
6483 </listitem>
6484 <listitem>
6485 <para>CalledForAction: the type on which the action method will
6486 be called. It can be either a state of the containing state
6487 machine or the state machine itself.</para>
6488 </listitem>
6489 <listitem>
6490 <para>action: a pointer to the method which CalledForAction
6491 provides.</para>
6492 </listitem>
6493 <listitem>
6494 <para>CalledForGuard: the type on which the guard method will be
6495 called. It can be either a state of the containing state
6496 machine or the state machine itself.</para>
6497 </listitem>
6498 <listitem>
6499 <para>guard: a pointer to the method which CalledForGuard
6500 provides.</para>
6501 </listitem>
6502 </itemizedlist>
6503 </para>
6504 </refsect3>
6505 </refsect2>
6506 <refsect2>
6507 <title>_internal</title>
6508 <para>This is an internal transition without action or guard. This is equivalent
6509 to an explicit "ignore event".</para>
6510 <refsect3>
6511 <title>definition</title>
6512 <classsynopsis>
6513 <ooclass>
6514 <classname>template&lt; class Event > _internal</classname>
6515 </ooclass>
6516 </classsynopsis>
6517 </refsect3>
6518 <refsect3>
6519 <title>template parameters</title>
6520 <para>
6521 <itemizedlist>
6522 <listitem>
6523 <para>Event: the event triggering the internal
6524 transition.</para>
6525 </listitem>
6526 </itemizedlist>
6527 </para>
6528 </refsect3>
6529 </refsect2>
6530 </refsect1>
6531 <refsect1>
6532 <title>msm/front/row2.hpp</title>
6533 <para>This header contains the variants of row2, which are an extension of the
6534 standard row transitions for use in the transition table. They offer the
6535 possibility to define action and guard not only in the state machine, but in any
6536 state of the state machine. They can also be used in internal transition tables
6537 through their irow2 variants.</para>
6538 <refsect2>
6539 <title>methods</title>
6540 <para>Like any other front-end, the following transition row types implements
6541 the two necessary static functions for action and guard call. Each function
6542 receives as parameter the (deepest-level) state machine processsing the
6543 event, the event itself, the source and target states and all the states
6544 contained in a state machine.</para>
6545 <funcsynopsis>
6546 <funcprototype>
6547 <funcdef>template &lt;class Fsm,class SourceState,class TargetState,
6548 class AllStates> static void action_call</funcdef>
6549 <paramdef>
6550 <funcparams>Fsm&amp; fsm,Event const&amp;
6551 evt,SourceState&amp;,TargetState,AllStates&amp;</funcparams>
6552 </paramdef>
6553 </funcprototype>
6554 </funcsynopsis>
6555 <funcsynopsis>
6556 <funcprototype>
6557 <funcdef>template &lt;class Fsm,class SourceState,class TargetState,
6558 class AllStates> static bool guard_call</funcdef>
6559 <paramdef>
6560 <funcparams>Fsm&amp; fsm,Event const&amp;
6561 evt,SourceState&amp;,TargetState,AllStates&amp;</funcparams>
6562 </paramdef>
6563 </funcprototype>
6564 </funcsynopsis>
6565 </refsect2>
6566 <refsect2>
6567 <title>_row2</title>
6568 <para>This is a transition without action or guard. The state machine only
6569 changes active state.</para>
6570 <refsect3>
6571 <title>definition</title>
6572 <classsynopsis>
6573 <ooclass>
6574 <classname>template&lt; class Source, class Event, class Target >
6575 _row2</classname>
6576 </ooclass>
6577 </classsynopsis>
6578 </refsect3>
6579 <refsect3>
6580 <title>template parameters</title>
6581 <para>
6582 <itemizedlist>
6583 <listitem>
6584 <para>Event: the event triggering the transition.</para>
6585 </listitem>
6586 <listitem>
6587 <para>Source: the source state of the transition.</para>
6588 </listitem>
6589 <listitem>
6590 <para>Target: the target state of the transition.</para>
6591 </listitem>
6592 </itemizedlist>
6593 </para>
6594 </refsect3>
6595 </refsect2>
6596 <refsect2>
6597 <title>a_row2</title>
6598 <para>This is a transition with action and without guard.</para>
6599 <refsect3>
6600 <title>definition</title>
6601 <classsynopsis>
6602 <ooclass>
6603 <classname>template&lt; class Source, class Event, class Target,
6604 </classname>
6605 </ooclass>
6606 </classsynopsis>
6607 <classsynopsis>
6608 <ooclass>
6609 <classname>class CalledForAction, void
6610 (CalledForAction::*action)(Event const&amp;) > _row2</classname>
6611 </ooclass>
6612 </classsynopsis>
6613 </refsect3>
6614 <refsect3>
6615 <title>template parameters</title>
6616 <para>
6617 <itemizedlist>
6618 <listitem>
6619 <para>Event: the event triggering the transition.</para>
6620 </listitem>
6621 <listitem>
6622 <para>Source: the source state of the transition.</para>
6623 </listitem>
6624 <listitem>
6625 <para>Target: the target state of the transition.</para>
6626 </listitem>
6627 <listitem>
6628 <para>CalledForAction: the type on which the action method will
6629 be called. It can be either a state of the containing state
6630 machine or the state machine itself.</para>
6631 </listitem>
6632 <listitem>
6633 <para>action: a pointer to the method which CalledForAction
6634 provides.</para>
6635 </listitem>
6636 </itemizedlist>
6637 </para>
6638 </refsect3>
6639 </refsect2>
6640 <refsect2>
6641 <title>g_row2</title>
6642 <para>This is a transition with guard and without action.</para>
6643 <refsect3>
6644 <title>definition</title>
6645 <classsynopsis>
6646 <ooclass>
6647 <classname>template&lt; class Source, class Event, class Target,
6648 </classname>
6649 </ooclass>
6650 </classsynopsis>
6651 <classsynopsis>
6652 <ooclass>
6653 <classname>class CalledForGuard, bool (CalledForGuard::*guard)(Event
6654 const&amp;) > _row2</classname>
6655 </ooclass>
6656 </classsynopsis>
6657 </refsect3>
6658 <refsect3>
6659 <title>template parameters</title>
6660 <para>
6661 <itemizedlist>
6662 <listitem>
6663 <para>Event: the event triggering the transition.</para>
6664 </listitem>
6665 <listitem>
6666 <para>Source: the source state of the transition.</para>
6667 </listitem>
6668 <listitem>
6669 <para>Target: the target state of the transition.</para>
6670 </listitem>
6671 <listitem>
6672 <para>CalledForGuard: the type on which the guard method will be
6673 called. It can be either a state of the containing state
6674 machine or the state machine itself.</para>
6675 </listitem>
6676 <listitem>
6677 <para>guard: a pointer to the method which CalledForGuard
6678 provides.</para>
6679 </listitem>
6680 </itemizedlist>
6681 </para>
6682 </refsect3>
6683 </refsect2>
6684 <refsect2>
6685 <title>row2</title>
6686 <para>This is a transition with guard and action.</para>
6687 <refsect3>
6688 <title>definition</title>
6689 <classsynopsis>
6690 <ooclass>
6691 <classname>template&lt; class Source, class Event, class Target,
6692 </classname>
6693 </ooclass>
6694 </classsynopsis>
6695 <classsynopsis>
6696 <ooclass>
6697 <classname>class CalledForAction, void
6698 (CalledForAction::*action)(Event const&amp;), </classname>
6699 </ooclass>
6700 </classsynopsis>
6701 <classsynopsis>
6702 <ooclass>
6703 <classname>class CalledForGuard, bool (CalledForGuard::*guard)(Event
6704 const&amp;) > _row2</classname>
6705 </ooclass>
6706 </classsynopsis>
6707 </refsect3>
6708 <refsect3>
6709 <title>template parameters</title>
6710 <para>
6711 <itemizedlist>
6712 <listitem>
6713 <para>Event: the event triggering the transition.</para>
6714 </listitem>
6715 <listitem>
6716 <para>Source: the source state of the transition.</para>
6717 </listitem>
6718 <listitem>
6719 <para>Target: the target state of the transition.</para>
6720 </listitem>
6721 <listitem>
6722 <para>CalledForAction: the type on which the action method will
6723 be called. It can be either a state of the containing state
6724 machine or the state machine itself.</para>
6725 </listitem>
6726 <listitem>
6727 <para>action: a pointer to the method which CalledForAction
6728 provides.</para>
6729 </listitem>
6730 <listitem>
6731 <para>CalledForGuard: the type on which the guard method will be
6732 called. It can be either a state of the containing state
6733 machine or the state machine itself.</para>
6734 </listitem>
6735 <listitem>
6736 <para>guard: a pointer to the method which CalledForGuard
6737 provides.</para>
6738 </listitem>
6739 </itemizedlist>
6740 </para>
6741 </refsect3>
6742 </refsect2>
6743 <refsect2>
6744 <title>a_irow2</title>
6745 <para>This is an internal transition for use inside a transition table, with
6746 action and without guard.</para>
6747 <refsect3>
6748 <title>definition</title>
6749 <classsynopsis>
6750 <ooclass>
6751 <classname>template&lt; class Source, class Event, </classname>
6752 </ooclass>
6753 </classsynopsis>
6754 <classsynopsis>
6755 <ooclass>
6756 <classname>class CalledForAction, void
6757 (CalledForAction::*action)(Event const&amp;) > _row2</classname>
6758 </ooclass>
6759 </classsynopsis>
6760 </refsect3>
6761 <refsect3>
6762 <title>template parameters</title>
6763 <para>
6764 <itemizedlist>
6765 <listitem>
6766 <para>Event: the event triggering the transition.</para>
6767 </listitem>
6768 <listitem>
6769 <para>Source: the source state of the transition.</para>
6770 </listitem>
6771 <listitem>
6772 <para>CalledForAction: the type on which the action method will
6773 be called. It can be either a state of the containing state
6774 machine or the state machine itself.</para>
6775 </listitem>
6776 <listitem>
6777 <para>action: a pointer to the method which CalledForAction
6778 provides.</para>
6779 </listitem>
6780 </itemizedlist>
6781 </para>
6782 </refsect3>
6783 </refsect2>
6784 <refsect2>
6785 <title>g_irow2</title>
6786 <para>This is an internal transition for use inside a transition table, with
6787 guard and without action.</para>
6788 <refsect3>
6789 <title>definition</title>
6790 <classsynopsis>
6791 <ooclass>
6792 <classname>template&lt; class Source, class Event, </classname>
6793 </ooclass>
6794 </classsynopsis>
6795 <classsynopsis>
6796 <ooclass>
6797 <classname>class CalledForGuard, bool (CalledForGuard::*guard)(Event
6798 const&amp;) > _row2</classname>
6799 </ooclass>
6800 </classsynopsis>
6801 </refsect3>
6802 <refsect3>
6803 <title>template parameters</title>
6804 <para>
6805 <itemizedlist>
6806 <listitem>
6807 <para>Event: the event triggering the transition.</para>
6808 </listitem>
6809 <listitem>
6810 <para>Source: the source state of the transition.</para>
6811 </listitem>
6812 <listitem>
6813 <para>CalledForGuard: the type on which the guard method will be
6814 called. It can be either a state of the containing state
6815 machine or the state machine itself.</para>
6816 </listitem>
6817 <listitem>
6818 <para>guard: a pointer to the method which CalledForGuard
6819 provides.</para>
6820 </listitem>
6821 </itemizedlist>
6822 </para>
6823 </refsect3>
6824 </refsect2>
6825 <refsect2>
6826 <title>irow2</title>
6827 <para>This is an internal transition for use inside a transition table, with
6828 guard and action.</para>
6829 <refsect3>
6830 <title>definition</title>
6831 <classsynopsis>
6832 <ooclass>
6833 <classname>template&lt; class Source, class Event, </classname>
6834 </ooclass>
6835 </classsynopsis>
6836 <classsynopsis>
6837 <ooclass>
6838 <classname>class CalledForAction, void
6839 (CalledForAction::*action)(Event const&amp;), </classname>
6840 </ooclass>
6841 </classsynopsis>
6842 <classsynopsis>
6843 <ooclass>
6844 <classname>class CalledForGuard, bool (CalledForGuard::*guard)(Event
6845 const&amp;) > _row2</classname>
6846 </ooclass>
6847 </classsynopsis>
6848 </refsect3>
6849 <refsect3>
6850 <title>template parameters</title>
6851 <para>
6852 <itemizedlist>
6853 <listitem>
6854 <para>Event: the event triggering the transition.</para>
6855 </listitem>
6856 <listitem>
6857 <para>Source: the source state of the transition.</para>
6858 </listitem>
6859 <listitem>
6860 <para>CalledForAction: the type on which the action method will
6861 be called. It can be either a state of the containing state
6862 machine or the state machine itself.</para>
6863 </listitem>
6864 <listitem>
6865 <para>action: a pointer to the method which CalledForAction
6866 provides.</para>
6867 </listitem>
6868 <listitem>
6869 <para>CalledForGuard: the type on which the guard method will be
6870 called. It can be either a state of the containing state
6871 machine or the state machine itself.</para>
6872 </listitem>
6873 <listitem>
6874 <para>guard: a pointer to the method which CalledForGuard
6875 provides.</para>
6876 </listitem>
6877 </itemizedlist>
6878 </para>
6879 </refsect3>
6880 </refsect2>
6881 </refsect1>
6882 <refsect1>
6883 <title>msm/front/state_machine_def.hpp</title>
6884 <para>This header provides the implementation of the <command
6885 xlink:href="#basic-front-end">basic front-end</command>. It contains one
6886 type, <code>state_machine_def</code></para>
6887 <refsect2>
6888 <title>state_machine_def definition</title>
6889 <para>This type is the basic class for a basic (or possibly any other)
6890 front-end. It provides the standard row types (which includes internal
6891 transitions) and a default implementation of the required methods and
6892 typedefs.</para>
6893 <classsynopsis>
6894 <ooclass>
6895 <classname>template &lt;class Derived,class BaseState =
6896 default_base_state> state_machine_def</classname>
6897 </ooclass>
6898 </classsynopsis>
6899 <refsect3>
6900 <title>typedefs</title>
6901 <para>
6902 <itemizedlist>
6903 <listitem>
6904 <para>flag_list: by default, no flag is set in the state
6905 machine</para>
6906 </listitem>
6907 <listitem>
6908 <para>deferred_events: by default, no event is deferred.</para>
6909 </listitem>
6910 <listitem>
6911 <para>configuration: by default, no configuration customization
6912 is done.</para>
6913 </listitem>
6914 </itemizedlist>
6915 </para>
6916 </refsect3>
6917 <refsect3>
6918 <title>row methods</title>
6919 <para>Like any other front-end, the following transition row types
6920 implements the two necessary static functions for action and guard call.
6921 Each function receives as parameter the (deepest-level) state machine
6922 processsing the event, the event itself, the source and target states
6923 and all the states contained in a state machine (ignored).</para>
6924 <funcsynopsis>
6925 <funcprototype>
6926 <funcdef>template &lt;class Fsm,class SourceState,class TargetState,
6927 class AllStates> static void action_call</funcdef>
6928 <paramdef>
6929 <funcparams>Fsm&amp; fsm,Event const&amp;
6930 evt,SourceState&amp;,TargetState,AllStates&amp;</funcparams>
6931 </paramdef>
6932 </funcprototype>
6933 </funcsynopsis>
6934 <funcsynopsis>
6935 <funcprototype>
6936 <funcdef>template &lt;class Fsm,class SourceState,class TargetState,
6937 class AllStates> static bool guard_call</funcdef>
6938 <paramdef>
6939 <funcparams>Fsm&amp; fsm,Event const&amp;
6940 evt,SourceState&amp;,TargetState,AllStates&amp;</funcparams>
6941 </paramdef>
6942 </funcprototype>
6943 </funcsynopsis>
6944 </refsect3>
6945 <refsect3>
6946 <title>a_row</title>
6947 <para>This is a transition with action and without guard.</para>
6948 <para><ooclass>
6949 <classname>template&lt; class Source, class Event, class Target,
6950 void (Derived::*action)(Event const&amp;) > a_row</classname>
6951 </ooclass><itemizedlist>
6952 <listitem>
6953 <para>Event: the event triggering the transition.</para>
6954 </listitem>
6955 <listitem>
6956 <para>Source: the source state of the transition.</para>
6957 </listitem>
6958 <listitem>
6959 <para>Target: the target state of the transition.</para>
6960 </listitem>
6961 <listitem>
6962 <para>action: a pointer to the method provided by the concrete
6963 front-end (represented by <code>Derived</code>).</para>
6964 </listitem>
6965 </itemizedlist></para>
6966 </refsect3>
6967 <refsect3>
6968 <title>g_row</title>
6969 <para>This is a transition with guard and without action.</para>
6970 <para><ooclass>
6971 <classname>template&lt; class Source, class Event, class Target,
6972 bool (Derived::*guard)(Event const&amp;) > g_row</classname>
6973 </ooclass><itemizedlist>
6974 <listitem>
6975 <para>Event: the event triggering the transition.</para>
6976 </listitem>
6977 <listitem>
6978 <para>Source: the source state of the transition.</para>
6979 </listitem>
6980 <listitem>
6981 <para>Target: the target state of the transition.</para>
6982 </listitem>
6983 <listitem>
6984 <para>guard: a pointer to the method provided by the concrete
6985 front-end (represented by <code>Derived</code>).</para>
6986 </listitem>
6987 </itemizedlist></para>
6988 </refsect3>
6989 <refsect3>
6990 <title>row</title>
6991 <para>This is a transition with guard and action.</para>
6992 <para><ooclass>
6993 <classname>template&lt; class Source, class Event, class Target,
6994 void (Derived::*action)(Event const&amp;), bool
6995 (Derived::*guard)(Event const&amp;) > row</classname>
6996 </ooclass><itemizedlist>
6997 <listitem>
6998 <para>Event: the event triggering the transition.</para>
6999 </listitem>
7000 <listitem>
7001 <para>Source: the source state of the transition.</para>
7002 </listitem>
7003 <listitem>
7004 <para>Target: the target state of the transition.</para>
7005 </listitem>
7006 <listitem>
7007 <para>action: a pointer to the method provided by the concrete
7008 front-end (represented by <code>Derived</code>).</para>
7009 </listitem>
7010 <listitem>
7011 <para>guard: a pointer to the method provided by the concrete
7012 front-end (represented by <code>Derived</code>).</para>
7013 </listitem>
7014 </itemizedlist></para>
7015 </refsect3>
7016 <refsect3>
7017 <title>_row</title>
7018 <para>This is a transition without action or guard. The state machine only
7019 changes active state.</para>
7020 <para><ooclass>
7021 <classname>template&lt; class Source, class Event, class Target >
7022 _row</classname>
7023 </ooclass><itemizedlist>
7024 <listitem>
7025 <para>Event: the event triggering the transition.</para>
7026 </listitem>
7027 <listitem>
7028 <para>Source: the source state of the transition.</para>
7029 </listitem>
7030 <listitem>
7031 <para>Target: the target state of the transition.</para>
7032 </listitem>
7033 </itemizedlist></para>
7034 </refsect3>
7035 <refsect3>
7036 <title>a_irow</title>
7037 <para>This is an internal transition for use inside a transition table, with
7038 action and without guard.</para>
7039 <para><ooclass>
7040 <classname>template&lt; class Source, class Event, void
7041 (Derived::*action)(Event const&amp;) > a_irow</classname>
7042 </ooclass><itemizedlist>
7043 <listitem>
7044 <para>Event: the event triggering the transition.</para>
7045 </listitem>
7046 <listitem>
7047 <para>Source: the source state of the transition.</para>
7048 </listitem>
7049 <listitem>
7050 <para>action: a pointer to the method provided by the concrete
7051 front-end (represented by <code>Derived</code>).</para>
7052 </listitem>
7053 </itemizedlist></para>
7054 </refsect3>
7055 <refsect3>
7056 <title>g_irow</title>
7057 <para>This is an internal transition for use inside a transition table, with
7058 guard and without action.</para>
7059 <para><ooclass>
7060 <classname>template&lt; class Source, class Event, bool
7061 (Derived::*guard)(Event const&amp;) > g_irow</classname>
7062 </ooclass><itemizedlist>
7063 <listitem>
7064 <para>Event: the event triggering the transition.</para>
7065 </listitem>
7066 <listitem>
7067 <para>Source: the source state of the transition.</para>
7068 </listitem>
7069 <listitem>
7070 <para>guard: a pointer to the method provided by the concrete
7071 front-end (represented by <code>Derived</code>).</para>
7072 </listitem>
7073 </itemizedlist></para>
7074 </refsect3>
7075 <refsect3>
7076 <title>irow</title>
7077 <para>This is an internal transition for use inside a transition table, with
7078 guard and action.</para>
7079 <para><ooclass>
7080 <classname>template&lt; class Source, class Event, void
7081 (Derived::*action)(Event const&amp;), bool
7082 (Derived::*guard)(Event const&amp;) > irow</classname>
7083 </ooclass><itemizedlist>
7084 <listitem>
7085 <para>Event: the event triggering the transition.</para>
7086 </listitem>
7087 <listitem>
7088 <para>Source: the source state of the transition.</para>
7089 </listitem>
7090 <listitem>
7091 <para>action: a pointer to the method provided by the concrete
7092 front-end (represented by <code>Derived</code>).</para>
7093 </listitem>
7094 <listitem>
7095 <para>guard: a pointer to the method provided by the concrete
7096 front-end (represented by <code>Derived</code>).</para>
7097 </listitem>
7098 </itemizedlist></para>
7099 </refsect3>
7100 <refsect3>
7101 <title>_irow</title>
7102 <para>This is an internal transition without action or guard. As it does
7103 nothing, it means "ignore event".</para>
7104 <para><ooclass>
7105 <classname>template&lt; class Source, class Event >
7106 _irow</classname>
7107 </ooclass><itemizedlist>
7108 <listitem>
7109 <para>Event: the event triggering the transition.</para>
7110 </listitem>
7111 <listitem>
7112 <para>Source: the source state of the transition.</para>
7113 </listitem>
7114 </itemizedlist></para>
7115 </refsect3>
7116 <refsect3>
7117 <title>methods</title>
7118 <para><code>state_machine_def</code> provides a default implementation in
7119 case of an event which cannot be processed by a state machine (no
7120 transition found). The implementation is using a
7121 <code>BOOST_ASSERT</code> so that the error will only be noticed in
7122 debug mode. Overwrite this method in your implementation to change the
7123 behavior.</para>
7124 <para>
7125 <funcsynopsis>
7126 <funcprototype>
7127 <funcdef>template &lt;class Fsm,class Event> static void
7128 no_transition</funcdef>
7129 <paramdef>
7130 <funcparams>Event const&amp; ,Fsm&amp;, int
7131 state</funcparams>
7132 </paramdef>
7133 </funcprototype>
7134 </funcsynopsis>
7135 </para>
7136 <para><code>state_machine_def</code> provides a default implementation in
7137 case an exception is thrown by a state (entry/exit) or transition
7138 (action/guard) behavior. The implementation is using a
7139 <code>BOOST_ASSERT</code> so that the error will only be noticed in
7140 debug mode. Overwrite this method in your implementation to change the
7141 behavior. This method will be called only if exception handling is not
7142 deactivated (default) by defining
7143 <code>has_no_message_queue</code>.</para>
7144 <para>
7145 <funcsynopsis>
7146 <funcprototype>
7147 <funcdef>template &lt;class Fsm,class Event> static void
7148 exception_caught</funcdef>
7149 <paramdef>
7150 <funcparams>Event const&amp; ,Fsm&amp;,
7151 std::exception&amp;</funcparams>
7152 </paramdef>
7153 </funcprototype>
7154 </funcsynopsis>
7155 </para>
7156 </refsect3>
7157 </refsect2>
7158 </refsect1>
7159 <refsect1>
7160 <title>msm/front/states.hpp </title>
7161 <para>This header provides the different states (except state machines) for the
7162 basic front-end (or mixed with other front-ends).</para>
7163 <refsect2>
7164 <title>types</title>
7165 <para>This header provides the following types:</para>
7166 <refsect3>
7167 <title>no_sm_ptr</title>
7168 <para>deprecated: default policy for states. It means that states do not
7169 need to save a pointer to their containing state machine.</para>
7170 </refsect3>
7171 <refsect3>
7172 <title>sm_ptr</title>
7173 <para>deprecated: state policy. It means that states need to save a pointer
7174 to their containing state machine. When seeing this flag, the back-end
7175 will call set_sm_ptr(fsm*) and give itself as argument.</para>
7176 </refsect3>
7177 <refsect3>
7178 <title>state</title>
7179 <para>Basic type for simple states. Inherit from this type to define a
7180 simple state. The first argument is needed if you want your state (and
7181 all others used in a concrete state machine) to inherit a basic type for
7182 logging or providing a common behavior.</para>
7183 <classsynopsis>
7184 <ooclass>
7185 <classname>template&lt;class Base = default_base_state,class
7186 SMPtrPolicy = no_sm_ptr> state</classname>
7187 </ooclass>
7188 </classsynopsis>
7189 </refsect3>
7190 <refsect3>
7191 <title>terminate_state</title>
7192 <para>Basic type for terminate states. Inherit from this type to define a
7193 terminate state. The first argument is needed if you want your state
7194 (and all others used in a concrete state machine) to inherit a basic
7195 type for logging or providing a common behavior.</para>
7196 <classsynopsis>
7197 <ooclass>
7198 <classname>template&lt;class Base = default_base_state,class
7199 SMPtrPolicy = no_sm_ptr> terminate_state</classname>
7200 </ooclass>
7201 </classsynopsis>
7202 </refsect3>
7203 <refsect3>
7204 <title>interrupt_state</title>
7205 <para>Basic type for interrupt states. Interrupt states prevent any further
7206 event handling until EndInterruptEvent is sent. Inherit from this type
7207 to define a terminate state. The first argument is the name of the event
7208 ending the interrupt. The second argument is needed if you want your
7209 state (and all others used in a concrete state machine) to inherit a
7210 basic type for logging or providing a common behavior.</para>
7211 <para>The EndInterruptEvent can also be a sequence of events:
7212 mpl::vector&lt;EndInterruptEvent,EndInterruptEvent2>.</para>
7213 <classsynopsis>
7214 <ooclass>
7215 <classname>template&lt;class EndInterruptEvent,class Base =
7216 default_base_state,</classname>
7217 </ooclass>
7218 </classsynopsis>
7219 <classsynopsis>
7220 <ooclass>
7221 <classname>class SMPtrPolicy = no_sm_ptr>
7222 interrupt_state</classname>
7223 </ooclass>
7224 </classsynopsis>
7225 </refsect3>
7226 <refsect3>
7227 <title>explicit_entry</title>
7228 <para>Inherit from this type <emphasis role="underline">in
7229 addition</emphasis> to the desired state type to enable this state
7230 for direct entering. The template parameter gives the region id of the
7231 state (regions are numbered in the order of the
7232 <code>initial_state</code> typedef).</para>
7233 <classsynopsis>
7234 <ooclass>
7235 <classname>template &lt;int ZoneIndex=-1> explicit_entry</classname>
7236 </ooclass>
7237 </classsynopsis>
7238 </refsect3>
7239 <refsect3>
7240 <title>entry_pseudo_state</title>
7241 <para>Basic type for entry pseudo states. Entry pseudo states are an
7242 predefined entry into a submachine and connect two transitions. The
7243 first argument is the id of the region entered by this state (regions
7244 are numbered in the order of the <code>initial_state</code> typedef).
7245 The second argument is needed if you want your state (and all others
7246 used in a concrete state machine) to inherit a basic type for logging or
7247 providing a common behavior.</para>
7248 <classsynopsis>
7249 <ooclass>
7250 <classname>template&lt;int RegionIndex=-1,class Base =
7251 default_base_state,</classname>
7252 </ooclass>
7253 </classsynopsis>
7254 <classsynopsis>
7255 <ooclass>
7256 <classname>class SMPtrPolicy = no_sm_ptr>
7257 entry_pseudo_state</classname>
7258 </ooclass>
7259 </classsynopsis>
7260 </refsect3>
7261 <refsect3>
7262 <title>exit_pseudo_state</title>
7263 <para>Basic type for exit pseudo states. Exit pseudo states are an
7264 predefined exit from a submachine and connect two transitions. The first
7265 argument is the name of the event which will be "thrown" out of the exit
7266 point. This event does not need to be the same as the one sent by the
7267 inner region but must be convertible from it. The second argument is
7268 needed if you want your state (and all others used in a concrete state
7269 machine) to inherit a basic type for logging or providing a common
7270 behavior.</para>
7271 <classsynopsis>
7272 <ooclass>
7273 <classname>template&lt;class Event,class Base =
7274 default_base_state,</classname>
7275 </ooclass>
7276 </classsynopsis>
7277 <classsynopsis>
7278 <ooclass>
7279 <classname>class SMPtrPolicy = no_sm_ptr>
7280 exit_pseudo_state</classname>
7281 </ooclass>
7282 </classsynopsis>
7283 </refsect3>
7284 </refsect2>
7285 </refsect1>
7286 <refsect1>
7287 <title>msm/front/euml/euml.hpp</title>
7288 <para>This header includes all of eUML except the STL functors.</para>
7289 </refsect1>
7290 <refsect1>
7291 <title>msm/front/euml/stl.hpp</title>
7292 <para>This header includes all the functors for STL support in eUML. These <command
7293 xlink:href="#eUML-STL-all">tables</command> show a full description.</para>
7294 </refsect1>
7295 <refsect1>
7296 <title>msm/front/euml/algorithm.hpp</title>
7297 <para>This header includes all the functors for STL algorithms support in eUML.
7298 These <command xlink:href="#eUML-STL-all">tables</command> show a full
7299 description.</para>
7300 </refsect1>
7301 <refsect1>
7302 <title>msm/front/euml/iteration.hpp</title>
7303 <para>This header includes iteration functors for STL support in eUML. This <command
7304 xlink:href="#eUML-STL-iteration">tables</command> shows a full
7305 description.</para>
7306 </refsect1>
7307 <refsect1>
7308 <title>msm/front/euml/querying.hpp</title>
7309 <para>This header includes querying functors for STL support in eUML. This <command
7310 xlink:href="#eUML-STL-querying">tables</command> shows a full
7311 description.</para>
7312 </refsect1>
7313 <refsect1>
7314 <title>msm/front/euml/transformation.hpp</title>
7315 <para>This header includes transformation functors for STL support in eUML. This
7316 <command xlink:href="#eUML-STL-transformation">tables</command> shows a full
7317 description.</para>
7318 </refsect1>
7319 <refsect1>
7320 <title>msm/front/euml/container.hpp</title>
7321 <para>This header includes container functors for STL support in eUML (functors
7322 calling container methods). This <command xlink:href="#eUML-STL-container"
7323 >tables</command> shows a full description. It also provides npos for
7324 strings.</para>
7325 <refsect2>
7326 <title>Npos_&lt;container type></title>
7327 <para>Functor returning npos for transition or state behaviors. Like all
7328 constants, only the functor form exists, so parenthesis are necessary.
7329 Example:</para>
7330 <para><code>string_find_(event_(m_song),Char_&lt;'S'>(),Size_t_&lt;0>()) !=
7331 Npos_&lt;string>() // compare result of string::find with
7332 npos</code></para>
7333 </refsect2>
7334 </refsect1>
7335 <refsect1>
7336 <title>msm/front/euml/stt_grammar.hpp</title>
7337 <para>This header provides the transition table grammars. This includes internal
7338 transition tables.</para>
7339 <refsect2>
7340 <title>functions</title>
7341 <refsect3>
7342 <title>build_stt</title>
7343 <para>The function build_stt evaluates the grammar-conform expression as
7344 parameter. It returns a transition table, which is a mpl::vector of
7345 transitions (rows) or, if the expression is ill-formed (does not match
7346 the grammar), the type <code>invalid_type</code>, which will lead to a
7347 compile-time static assertion when this transition table is passed to a
7348 state machine. </para>
7349 <funcsynopsis>
7350 <funcprototype>
7351 <funcdef>template&lt;class Expr> [mpl::vector&lt;...> /
7352 msm::front::euml::invalid_type] build_stt</funcdef>
7353 <paramdef>Expr const&amp; expr</paramdef>
7354 </funcprototype>
7355 </funcsynopsis>
7356 </refsect3>
7357 <refsect3>
7358 <title>build_internal_stt</title>
7359 <para>The function build_internal_stt evaluates the grammar-conform
7360 expression as parameter. It returns a transition table, which is a
7361 mpl::vector of transitions (rows) or, if the expression is ill-formed
7362 (does not match the grammar), the type <code>invalid_type</code>, which
7363 will lead to a compile-time static assertion when this transition table
7364 is passed to a state machine. </para>
7365 <funcsynopsis>
7366 <funcprototype>
7367 <funcdef>template&lt;class Expr> [mpl::vector&lt;...> /
7368 msm::front::euml::invalid_type] build_internal_stt</funcdef>
7369 <paramdef>Expr const&amp; expr</paramdef>
7370 </funcprototype>
7371 </funcsynopsis>
7372 </refsect3>
7373 </refsect2>
7374 <refsect2>
7375 <title>grammars</title>
7376 <refsect3>
7377 <title><command xml:id="reference-stt-grammar">transition
7378 table</command></title>
7379 <para>The transition table accepts the following grammar:</para>
7380 <programlisting>Stt := Row | (Stt ',' Stt)
7381 Row := (Target '==' (SourcePlusEvent)) /* first syntax*/
7382 | ( (SourcePlusEvent) '==' Target ) /* second syntax*/
7383 | (SourcePlusEvent) /* internal transitions */
7384 SourcePlusEvent := (BuildSource '+' BuildEvent)/* standard transition*/
7385 | (BuildSource) /* anonymous transition */
7386 BuildSource := state_tag | (state_tag '/' Action) | (state_tag '[' Guard ']')
7387 | (state_tag '[' Guard ']' '/' Action)
7388 BuildEvent := event_tag | (event_tag '/' Action) | (event_tag '[' Guard ']')
7389 | (event_tag '[' Guard ']' '/' Action)</programlisting>
7390 <para>The grammars Action and Guard are defined in state_grammar.hpp and
7391 guard_grammar.hpp respectively. state_tag and event_tag are inherited
7392 from euml_state (or other state variants) and euml_event respectively.
7393 For example, following declarations are possible:</para>
7394 <programlisting>target == source + event [guard] / action,
7395 source + event [guard] / action == target,
7396 source + event [guard] / (action1,action2) == target,
7397 target == source + event [guard] / (action1,action2),
7398 target == source + event,
7399 source + event == target,
7400 target == source + event [guard],
7401 source + event [guard] == target,
7402 target == source + event / action,
7403 source + event /action == target,
7404 source / action == target, /*anonymous transition*/
7405 target == source / action, /*anonymous transition*/
7406 source + event /action, /* internal transition*/</programlisting>
7407 </refsect3>
7408 <refsect3>
7409 <title>internal transition table</title>
7410 <para>The internal transition table accepts the following grammar:</para>
7411 <programlisting>IStt := BuildEvent | (IStt ',' IStt)</programlisting>
7412 <para>BuildEvent being defined for both internal and standard transition
7413 tables.</para>
7414 </refsect3>
7415 </refsect2>
7416 </refsect1>
7417 <refsect1>
7418 <title>msm/front/euml/guard_grammar.hpp</title>
7419 <para>This header contains the <code>Guard</code> grammar used in the previous
7420 section. This grammar is long but pretty simple:</para>
7421 <programlisting>Guard := action_tag | (Guard '&amp;&amp;' Guard)
7422 | (Guard '||' Guard) | ... /* operators*/
7423 | (if_then_else_(Guard,Guard,Guard)) | (function (Action,...Action))</programlisting>
7424 <para>Most C++ operators are supported (address-of is not). With
7425 <code>function</code> is meant any eUML predefined function or any self-made
7426 (using <code>MSM_EUML_METHOD</code> or <code>MSM_EUML_FUNCTION</code>). Action
7427 is a grammar defined in state_grammar.hpp.</para>
7428 </refsect1>
7429 <refsect1>
7430 <title>msm/front/euml/state_grammar.hpp</title>
7431 <para>This header provides the grammar for actions and the different grammars and
7432 functions to build states using eUML.</para>
7433 <refsect2>
7434 <title>action grammar</title>
7435 <para>Like the guard grammar, this grammar supports relevant C++ operators and
7436 eUML functions:</para>
7437 <programlisting>Action := action_tag | (Action '+' Action)
7438 | ('--' Action) | ... /* operators*/
7439 | if_then_else_(Guard,Action,Action) | if_then_(Action)
7440 | while_(Guard,Action)
7441 | do_while_(Guard,Action) | for_(Action,Guard,Action,Action)
7442 | (function(Action,...Action))
7443 ActionSequence := Action | (Action ',' Action)</programlisting>
7444 <para>Relevant operators are: ++ (post/pre), -- (post/pre), dereferencing, +
7445 (unary/binary), - (unary/binary), *, /, %, &amp;(bitwise), | (bitwise),
7446 ^(bitwise), +=, -=, *=, /=, %=, &lt;&lt;=, >>=, &lt;&lt;, >>, =, [].</para>
7447 </refsect2>
7448 <refsect2>
7449 <title>attributes</title>
7450 <para>This grammar is used to add attributes to states (or state machines) or
7451 events: It evaluates to a fusion::map. You can use two forms:<itemizedlist>
7452 <listitem>
7453 <para><code>attributes_ &lt;&lt; no_attributes_</code></para>
7454 </listitem>
7455 <listitem>
7456 <para><code>attributes_ &lt;&lt; attribute_1 &lt;&lt; ... &lt;&lt;
7457 attribute_n</code></para>
7458 </listitem>
7459 </itemizedlist></para>
7460 <para>Attributes can be of any default-constructible type (fusion
7461 requirement).</para>
7462 </refsect2>
7463 <refsect2>
7464 <title>configure</title>
7465 <para>This grammar also has two forms:<itemizedlist>
7466 <listitem>
7467 <para><code>configure_ &lt;&lt; no_configure_</code></para>
7468 </listitem>
7469 <listitem>
7470 <para><code>configure_ &lt;&lt; type_1 &lt;&lt; ... &lt;&lt;
7471 type_n</code></para>
7472 </listitem>
7473 </itemizedlist></para>
7474 <para>This grammar is used to create inside one syntax:<itemizedlist>
7475 <listitem>
7476 <para>flags: <code>configure_ &lt;&lt; some_flag</code> where
7477 some_flag inherits from <code>euml_flag&lt;some_flag></code> or
7478 is defined using BOOST_MSM_EUML_FLAG.</para>
7479 </listitem>
7480 <listitem>
7481 <para>deferred events: <code>configure_ &lt;&lt; some_event</code>
7482 where some_event inherits from
7483 <code>euml_event&lt;some_event></code> or is defined using
7484 BOOST_MSM_EUML_EVENT or
7485 BOOST_MSM_EUML_EVENT_WITH_ATTRIBUTES.</para>
7486 </listitem>
7487 <listitem>
7488 <para>configuration (message queue, manual deferring, exception
7489 handling): <code>configure_ &lt;&lt; some_config</code> where
7490 some_config inherits from
7491 <code>euml_config&lt;some_config></code>. At the moment,
7492 three predefined objects exist (in msm//front/euml/common.hpp):<itemizedlist>
7493 <listitem>
7494 <para>no_exception: disable catching exceptions</para>
7495 </listitem>
7496 <listitem>
7497 <para>no_msg_queue: disable message queue</para>
7498 </listitem>
7499 <listitem>
7500 <para>deferred_events: manually enable handling of
7501 deferred events</para>
7502 </listitem>
7503 </itemizedlist></para>
7504 </listitem>
7505 </itemizedlist></para>
7506 </refsect2>
7507 <refsect2>
7508 <title>initial states</title>
7509 <para>The grammar to define initial states for a state machine is: <code>init_
7510 &lt;&lt; state_1 &lt;&lt; ... &lt;&lt; state_n</code> where
7511 state_1...state_n inherit from euml_state or is defined using
7512 BOOST_MSM_EUML_STATE, BOOST_MSM_EUML_INTERRUPT_STATE,
7513 BOOST_MSM_EUML_TERMINATE_STATE, BOOST_MSM_EUML_EXPLICIT_ENTRY_STATE,
7514 BOOST_MSM_EUML_ENTRY_STATE or BOOST_MSM_EUML_EXIT_STATE.</para>
7515 </refsect2>
7516 <refsect2>
7517 <title>functions</title>
7518 <refsect3>
7519 <title>build_sm</title>
7520 <para>This function has several overloads. The return type is not relevant
7521 to you as only decltype (return type) is what one needs.</para>
7522 <para>Defines a state machine without entry or exit:</para>
7523 <funcsynopsis>
7524 <funcprototype>
7525 <funcdef>template &lt;class StateNameTag,class Stt,class Init>
7526 func_state_machine&lt;...> build_sm</funcdef>
7527 <paramdef>Stt ,Init</paramdef>
7528 </funcprototype>
7529 </funcsynopsis>
7530 <para>Defines a state machine with entry behavior:</para>
7531 <funcsynopsis>
7532 <funcprototype>
7533 <funcdef>template &lt;class StateNameTag,class Stt,class Init,class
7534 Expr1> func_state_machine&lt;...> build_sm</funcdef>
7535 <paramdef>Stt ,Init,Expr1 const&amp;</paramdef>
7536 </funcprototype>
7537 </funcsynopsis>
7538 <para>Defines a state machine with entry and exit behaviors:</para>
7539 <funcsynopsis>
7540 <funcprototype>
7541 <funcdef>template &lt;class StateNameTag,class Stt,class Init,class
7542 Expr1, class Expr2> func_state_machine&lt;...>
7543 build_sm</funcdef>
7544 <paramdef>Stt ,Init,Expr1 const&amp;,Expr2 const&amp;</paramdef>
7545 </funcprototype>
7546 </funcsynopsis>
7547 <para>Defines a state machine with entry, exit behaviors and
7548 attributes:</para>
7549 <funcsynopsis>
7550 <funcprototype>
7551 <funcdef>template &lt;class StateNameTag,class Stt,class Init,class
7552 Expr1, class Expr2, class Attributes> func_state_machine&lt;...>
7553 build_sm</funcdef>
7554 <paramdef>Stt ,Init,Expr1 const&amp;, Expr2 const&amp;, Attributes
7555 const&amp;</paramdef>
7556 </funcprototype>
7557 </funcsynopsis>
7558 <para>Defines a state machine with entry, exit behaviors, attributes and
7559 configuration (deferred events, flags):</para>
7560 <funcsynopsis>
7561 <funcprototype>
7562 <funcdef>template &lt;class StateNameTag,class Stt,class Init,class
7563 Expr1, class Expr2, class Attributes, class Configure>
7564 func_state_machine&lt;...> build_sm</funcdef>
7565 <paramdef>Stt ,Init,Expr1 const&amp;, Expr2 const&amp;, Attributes
7566 const&amp;, Configure const&amp;</paramdef>
7567 </funcprototype>
7568 </funcsynopsis>
7569 <para>Defines a state machine with entry, exit behaviors, attributes,
7570 configuration (deferred events, flags) and a base state:</para>
7571 <funcsynopsis>
7572 <funcprototype>
7573 <funcdef>template &lt;class StateNameTag,class Stt,class Init,class
7574 Expr1, class Expr2, class Attributes, class Configure, class
7575 Base> func_state_machine&lt;...> build_sm</funcdef>
7576 <paramdef>Stt ,Init,Expr1 const&amp;, Expr2 const&amp;, Attributes
7577 const&amp;, Configure const&amp;, Base</paramdef>
7578 </funcprototype>
7579 </funcsynopsis>
7580 <para>Notice that this function requires the extra parameter class
7581 StateNameTag to disambiguate state machines having the same parameters
7582 but still being different.</para>
7583 </refsect3>
7584 <refsect3>
7585 <title>build_state</title>
7586 <para>This function has several overloads. The return type is not relevant
7587 to you as only decltype (return type) is what one needs.</para>
7588 <para>Defines a simple state without entry or exit:</para>
7589 <funcsynopsis>
7590 <funcprototype>
7591 <funcdef>func_state&lt;class StateNameTag,...> build_state</funcdef>
7592 <paramdef/>
7593 </funcprototype>
7594 </funcsynopsis>
7595 <para>Defines a simple state with entry behavior:</para>
7596 <funcsynopsis>
7597 <funcprototype>
7598 <funcdef>template &lt;class StateNameTag,class Expr1>
7599 func_state&lt;...> build_state</funcdef>
7600 <paramdef>Expr1 const&amp;</paramdef>
7601 </funcprototype>
7602 </funcsynopsis>
7603 <para>Defines a simple state with entry and exit behaviors:</para>
7604 <funcsynopsis>
7605 <funcprototype>
7606 <funcdef>template &lt;class StateNameTag,class Expr1, class Expr2>
7607 func_state&lt;...> build_state</funcdef>
7608 <paramdef>Expr1 const&amp;,Expr2 const&amp;</paramdef>
7609 </funcprototype>
7610 </funcsynopsis>
7611 <para>Defines a simple state with entry, exit behaviors and
7612 attributes:</para>
7613 <funcsynopsis>
7614 <funcprototype>
7615 <funcdef>template &lt;class StateNameTag,class Expr1, class Expr2,
7616 class Attributes> func_state&lt;...> build_state</funcdef>
7617 <paramdef>Expr1 const&amp;, Expr2 const&amp;, Attributes
7618 const&amp;</paramdef>
7619 </funcprototype>
7620 </funcsynopsis>
7621 <para>Defines a simple state with entry, exit behaviors, attributes and
7622 configuration (deferred events, flags):</para>
7623 <funcsynopsis>
7624 <funcprototype>
7625 <funcdef>template &lt;class StateNameTag,class Expr1, class Expr2,
7626 class Attributes, class Configure> func_state&lt;...>
7627 build_state</funcdef>
7628 <paramdef>Expr1 const&amp;, Expr2 const&amp;, Attributes const&amp;,
7629 Configure const&amp;</paramdef>
7630 </funcprototype>
7631 </funcsynopsis>
7632 <para>Defines a simple state with entry, exit behaviors, attributes,
7633 configuration (deferred events, flags) and a base state:</para>
7634 <funcsynopsis>
7635 <funcprototype>
7636 <funcdef>template &lt;class StateNameTag,class Expr1, class Expr2,
7637 class Attributes, class Configure, class Base>
7638 func_state&lt;...> build_state</funcdef>
7639 <paramdef>Expr1 const&amp;, Expr2 const&amp;, Attributes const&amp;,
7640 Configure const&amp;, Base</paramdef>
7641 </funcprototype>
7642 </funcsynopsis>
7643 <para>Notice that this function requires the extra parameter class
7644 StateNameTag to disambiguate states having the same parameters but still
7645 being different.</para>
7646 </refsect3>
7647 <refsect3>
7648 <title>build_terminate_state</title>
7649 <para>This function has the same overloads as build_state.</para>
7650 </refsect3>
7651 <refsect3>
7652 <title>build_interrupt_state</title>
7653 <para>This function has several overloads. The return type is not relevant
7654 to you as only decltype (return type) is what one needs.</para>
7655 <para>Defines an interrupt state without entry or exit:</para>
7656 <funcsynopsis>
7657 <funcprototype>
7658 <funcdef>template &lt;class StateNameTag,class EndInterruptEvent>
7659 func_state&lt;...> build_interrupt_state</funcdef>
7660 <paramdef>EndInterruptEvent const&amp;</paramdef>
7661 </funcprototype>
7662 </funcsynopsis>
7663 <para>Defines an interrupt state with entry behavior:</para>
7664 <funcsynopsis>
7665 <funcprototype>
7666 <funcdef>template &lt;class StateNameTag,class
7667 EndInterruptEvent,class Expr1> func_state&lt;...>
7668 build_interrupt_state</funcdef>
7669 <paramdef>EndInterruptEvent const&amp;,Expr1 const&amp;</paramdef>
7670 </funcprototype>
7671 </funcsynopsis>
7672 <para>Defines an interrupt state with entry and exit behaviors:</para>
7673 <funcsynopsis>
7674 <funcprototype>
7675 <funcdef>template &lt;class StateNameTag,class
7676 EndInterruptEvent,class Expr1, class Expr2> func_state&lt;...>
7677 build_interrupt_state</funcdef>
7678 <paramdef>EndInterruptEvent const&amp;,Expr1 const&amp;,Expr2
7679 const&amp;</paramdef>
7680 </funcprototype>
7681 </funcsynopsis>
7682 <para>Defines an interrupt state with entry, exit behaviors and
7683 attributes:</para>
7684 <funcsynopsis>
7685 <funcprototype>
7686 <funcdef>template &lt;class StateNameTag,class
7687 EndInterruptEvent,class Expr1, class Expr2, class Attributes>
7688 func_state&lt;...> build_interrupt_state</funcdef>
7689 <paramdef>EndInterruptEvent const&amp;,Expr1 const&amp;, Expr2
7690 const&amp;, Attributes const&amp;</paramdef>
7691 </funcprototype>
7692 </funcsynopsis>
7693 <para>Defines an interrupt state with entry, exit behaviors, attributes and
7694 configuration (deferred events, flags):</para>
7695 <funcsynopsis>
7696 <funcprototype>
7697 <funcdef>template &lt;class StateNameTag,class
7698 EndInterruptEvent,class Expr1, class Expr2, class Attributes,
7699 class Configure> func_state&lt;...>
7700 build_interrupt_state</funcdef>
7701 <paramdef>EndInterruptEvent const&amp;,Expr1 const&amp;, Expr2
7702 const&amp;, Attributes const&amp;, Configure
7703 const&amp;</paramdef>
7704 </funcprototype>
7705 </funcsynopsis>
7706 <para>Defines an interrupt state with entry, exit behaviors, attributes,
7707 configuration (deferred events, flags) and a base state:</para>
7708 <funcsynopsis>
7709 <funcprototype>
7710 <funcdef>template &lt;class StateNameTag,class
7711 EndInterruptEvent,class Expr1, class Expr2, class Attributes,
7712 class Configure, class Base> func_state&lt;...>
7713 build_interrupt_state</funcdef>
7714 <paramdef>EndInterruptEvent const&amp;,Expr1 const&amp;, Expr2
7715 const&amp;, Attributes const&amp;, Configure const&amp;,
7716 Base</paramdef>
7717 </funcprototype>
7718 </funcsynopsis>
7719 <para>Notice that this function requires the extra parameter class
7720 StateNameTag to disambiguate states having the same parameters but still
7721 being different.</para>
7722 </refsect3>
7723 <refsect3>
7724 <title>build_entry_state</title>
7725 <para>This function has several overloads. The return type is not relevant
7726 to you as only decltype (return type) is what one needs.</para>
7727 <para>Defines an entry pseudo state without entry or exit:</para>
7728 <funcsynopsis>
7729 <funcprototype>
7730 <funcdef>template &lt;class StateNameTag,int RegionIndex>
7731 entry_func_state&lt;...> build_entry_state</funcdef>
7732 <paramdef/>
7733 </funcprototype>
7734 </funcsynopsis>
7735 <para>Defines an entry pseudo state with entry behavior:</para>
7736 <funcsynopsis>
7737 <funcprototype>
7738 <funcdef>template &lt;class StateNameTag,int RegionIndex,class
7739 Expr1> entry_func_state&lt;...> build_entry_state</funcdef>
7740 <paramdef>Expr1 const&amp;</paramdef>
7741 </funcprototype>
7742 </funcsynopsis>
7743 <para>Defines an entry pseudo state with entry and exit behaviors:</para>
7744 <funcsynopsis>
7745 <funcprototype>
7746 <funcdef>template &lt;class StateNameTag,int RegionIndex,class
7747 Expr1, class Expr2> entry_func_state&lt;...>
7748 build_entry_state</funcdef>
7749 <paramdef>Expr1 const&amp;,Expr2 const&amp;</paramdef>
7750 </funcprototype>
7751 </funcsynopsis>
7752 <para>Defines an entry pseudo state with entry, exit behaviors and
7753 attributes:</para>
7754 <funcsynopsis>
7755 <funcprototype>
7756 <funcdef>template &lt;class StateNameTag,int RegionIndex,class
7757 Expr1, class Expr2, class Attributes> entry_func_state&lt;...>
7758 build_entry_state</funcdef>
7759 <paramdef>Expr1 const&amp;, Expr2 const&amp;, Attributes
7760 const&amp;</paramdef>
7761 </funcprototype>
7762 </funcsynopsis>
7763 <para>Defines an entry pseudo state with entry, exit behaviors, attributes
7764 and configuration (deferred events, flags):</para>
7765 <funcsynopsis>
7766 <funcprototype>
7767 <funcdef>template &lt;class StateNameTag,int RegionIndex,class
7768 Expr1, class Expr2, class Attributes, class Configure>
7769 entry_func_state&lt;...> build_entry_state</funcdef>
7770 <paramdef>Expr1 const&amp;, Expr2 const&amp;, Attributes const&amp;,
7771 Configure const&amp;</paramdef>
7772 </funcprototype>
7773 </funcsynopsis>
7774 <para>Defines an entry pseudo state with entry, exit behaviors, attributes,
7775 configuration (deferred events, flags) and a base state:</para>
7776 <funcsynopsis>
7777 <funcprototype>
7778 <funcdef>template &lt;class StateNameTag,int RegionIndex,class
7779 Expr1, class Expr2, class Attributes, class Configure, class
7780 Base> entry_func_state&lt;...> build_entry_state</funcdef>
7781 <paramdef>Expr1 const&amp;, Expr2 const&amp;, Attributes const&amp;,
7782 Configure const&amp;, Base</paramdef>
7783 </funcprototype>
7784 </funcsynopsis>
7785 <para>Notice that this function requires the extra parameter class
7786 StateNameTag to disambiguate states having the same parameters but still
7787 being different.</para>
7788 </refsect3>
7789 <refsect3>
7790 <title>build_exit_state</title>
7791 <para>This function has several overloads. The return type is not relevant
7792 to you as only decltype (return type) is what one needs.</para>
7793 <para>Defines an exit pseudo state without entry or exit:</para>
7794 <funcsynopsis>
7795 <funcprototype>
7796 <funcdef>template &lt;class StateNameTag,class Event>
7797 exit_func_state&lt;...> build_exit_state</funcdef>
7798 <paramdef>Event const&amp;</paramdef>
7799 </funcprototype>
7800 </funcsynopsis>
7801 <para>Defines an exit pseudo state with entry behavior:</para>
7802 <funcsynopsis>
7803 <funcprototype>
7804 <funcdef>template &lt;class StateNameTag,class Event,class Expr1>
7805 exit_func_state&lt;...> build_exit_state</funcdef>
7806 <paramdef>Event const&amp;,Expr1 const&amp;</paramdef>
7807 </funcprototype>
7808 </funcsynopsis>
7809 <para>Defines an exit pseudo state with entry and exit behaviors:</para>
7810 <funcsynopsis>
7811 <funcprototype>
7812 <funcdef>template &lt;class StateNameTag,class Event,class Expr1,
7813 class Expr2> exit_func_state&lt;...> build_exit_state</funcdef>
7814 <paramdef>Event const&amp;,Expr1 const&amp;,Expr2
7815 const&amp;</paramdef>
7816 </funcprototype>
7817 </funcsynopsis>
7818 <para>Defines an exit pseudo state with entry, exit behaviors and
7819 attributes:</para>
7820 <funcsynopsis>
7821 <funcprototype>
7822 <funcdef>template &lt;class StateNameTag,class Event,class Expr1,
7823 class Expr2, class Attributes> exit_func_state&lt;...>
7824 build_exit_state</funcdef>
7825 <paramdef>Event const&amp;,Expr1 const&amp;, Expr2 const&amp;,
7826 Attributes const&amp;</paramdef>
7827 </funcprototype>
7828 </funcsynopsis>
7829 <para>Defines an exit pseudo state with entry, exit behaviors, attributes
7830 and configuration (deferred events, flags):</para>
7831 <funcsynopsis>
7832 <funcprototype>
7833 <funcdef>template &lt;class StateNameTag,class Event,class Expr1,
7834 class Expr2, class Attributes, class Configure>
7835 exit_func_state&lt;...> build_exit_state</funcdef>
7836 <paramdef>Event const&amp;,Expr1 const&amp;, Expr2 const&amp;,
7837 Attributes const&amp;, Configure const&amp;</paramdef>
7838 </funcprototype>
7839 </funcsynopsis>
7840 <para>Defines an exit pseudo state with entry, exit behaviors, attributes,
7841 configuration (deferred events, flags) and a base state:</para>
7842 <funcsynopsis>
7843 <funcprototype>
7844 <funcdef>template &lt;class StateNameTag,class Event,class Expr1,
7845 class Expr2, class Attributes, class Configure, class Base>
7846 exit_func_state&lt;...> build_exit_state</funcdef>
7847 <paramdef>Event const&amp;,Expr1 const&amp;, Expr2 const&amp;,
7848 Attributes const&amp;, Configure const&amp;, Base</paramdef>
7849 </funcprototype>
7850 </funcsynopsis>
7851 <para>Notice that this function requires the extra parameter class
7852 StateNameTag to disambiguate states having the same parameters but still
7853 being different.</para>
7854 </refsect3>
7855 <refsect3>
7856 <title>build_explicit_entry_state</title>
7857 <para>This function has the same overloads as build_entry_state and
7858 explicit_entry_func_state as return type.</para>
7859 </refsect3>
7860 </refsect2>
7861 </refsect1>
7862 <refsect1>
7863 <title>msm/front/euml/common.hpp</title>
7864 <refsect2>
7865 <title>types</title>
7866 <refsect3>
7867 <title>euml_event</title>
7868 <para>The basic type for events with eUML.</para>
7869 <classsynopsis>
7870 <ooclass>
7871 <classname>template &lt;class EventName> euml_event;</classname>
7872 </ooclass>
7873 </classsynopsis>
7874 <programlisting>struct play : euml_event&lt;play>{};</programlisting>
7875 </refsect3>
7876 <refsect3>
7877 <title>euml_state</title>
7878 <para>The basic type for states with eUML. You will usually not use this
7879 type directly as it is easier to use BOOST_MSM_EUML_STATE,
7880 BOOST_MSM_EUML_INTERRUPT_STATE, BOOST_MSM_EUML_TERMINATE_STATE,
7881 BOOST_MSM_EUML_EXPLICIT_ENTRY_STATE, BOOST_MSM_EUML_ENTRY_STATE or
7882 BOOST_MSM_EUML_EXIT_STATE.</para>
7883 <classsynopsis>
7884 <ooclass>
7885 <classname>template &lt;class StateName> euml_state;</classname>
7886 </ooclass>
7887 </classsynopsis>
7888 <para>You can however use this type directly if you want to provide your
7889 state with extra functions or provide entry or exit behaviors without
7890 functors, for example:</para>
7891 <programlisting>struct Empty : public msm::front::state&lt;> , public euml_state&lt;Empty>
7892 {
7893 void foo() {...}
7894 template &lt;class Event,class Fsm>
7895 void on_entry(Event const&amp; evt,Fsm&amp; fsm){...}
7896 };</programlisting>
7897 </refsect3>
7898 <refsect3>
7899 <title>euml_flag</title>
7900 <para>The basic type for flags with eUML.</para>
7901 <classsynopsis>
7902 <ooclass>
7903 <classname>template &lt;class FlagName> euml_flag;</classname>
7904 </ooclass>
7905 </classsynopsis>
7906 <programlisting>struct PlayingPaused: euml_flag&lt;PlayingPaused>{};</programlisting>
7907 </refsect3>
7908 <refsect3>
7909 <title>euml_action</title>
7910 <para>The basic type for state or transition behaviors and guards with
7911 eUML.</para>
7912 <classsynopsis>
7913 <ooclass>
7914 <classname>template &lt;class AcionName> euml_action;</classname>
7915 </ooclass>
7916 </classsynopsis>
7917 <programlisting>struct close_drawer : euml_action&lt;close_drawer>
7918 {
7919 template &lt;class Fsm,class Evt,class SourceState,class TargetState>
7920 void operator()(Evt const&amp; , Fsm&amp;, SourceState&amp; ,TargetState&amp; ) {...}
7921 };</programlisting>
7922 <para>Or, as state entry or exit behavior:</para>
7923 <programlisting>struct Playing_Entry : euml_action&lt;Playing_Entry>
7924 {
7925 template &lt;class Event,class Fsm,class State>
7926 void operator()(Event const&amp;,Fsm&amp; fsm,State&amp; ){...}
7927 };</programlisting>
7928 </refsect3>
7929 <refsect3>
7930 <title>euml_config</title>
7931 <para>The basic type for configuration possibilities with eUML.</para>
7932 <classsynopsis>
7933 <ooclass>
7934 <classname>template &lt;class ConfigName> euml_config;</classname>
7935 </ooclass>
7936 </classsynopsis>
7937 <para>You normally do not use this type directly but instead the instances
7938 of predefined configuration:<itemizedlist>
7939 <listitem>
7940 <para>no_exception: disable catching exceptions</para>
7941 </listitem>
7942 <listitem>
7943 <para>no_msg_queue: disable message queue. The message queue
7944 allows you to send an event for procesing while in an event
7945 processing.</para>
7946 </listitem>
7947 <listitem>
7948 <para>deferred_events: manually enable handling of deferred
7949 events</para>
7950 </listitem>
7951 </itemizedlist></para>
7952 </refsect3>
7953 <refsect3>
7954 <title>invalid_type</title>
7955 <para>Type returned by grammar parsers if the grammar is invalid. Seeing
7956 this type will result in a static assertion.</para>
7957 </refsect3>
7958 <refsect3>
7959 <title>no_action</title>
7960 <para>Placeholder type for use in entry/exit or transition behaviors, which
7961 does absolutely nothing.</para>
7962 </refsect3>
7963 <refsect3>
7964 <title>source_</title>
7965 <para>Generic object or function for the source state of a given transition:<itemizedlist>
7966 <listitem>
7967 <para>as object: returns by reference the source state of a
7968 transition, usually to be used by another function (usually
7969 one created by MSM_EUML_METHOD or MSM_EUML_FUNCTION).</para>
7970 <para>Example:
7971 <programlisting>some_user_function_(source_)</programlisting></para>
7972 </listitem>
7973 <listitem>
7974 <para>as function: returns by reference the attribute passed as
7975 parameter.</para>
7976 <para>Example:
7977 <programlisting>source_(m_counter)++</programlisting></para>
7978 </listitem>
7979 </itemizedlist></para>
7980 </refsect3>
7981 <refsect3>
7982 <title>target_</title>
7983 <para>Generic object or function for the target state of a given transition:<itemizedlist>
7984 <listitem>
7985 <para>as object: returns by reference the target state of a
7986 transition, usually to be used by another function (usually
7987 one created by MSM_EUML_METHOD or MSM_EUML_FUNCTION).</para>
7988 <para>Example:
7989 <programlisting>some_user_function_(target_)</programlisting></para>
7990 </listitem>
7991 <listitem>
7992 <para>as function: returns by reference the attribute passed as
7993 parameter.</para>
7994 <para>Example:
7995 <programlisting>target_(m_counter)++</programlisting></para>
7996 </listitem>
7997 </itemizedlist></para>
7998 </refsect3>
7999 <refsect3>
8000 <title>state_</title>
8001 <para>Generic object or function for the state of a given entry / exit
8002 behavior. state_ means source_ while in the context of an exit behavior
8003 and target_ in the context of an entry behavior:<itemizedlist>
8004 <listitem>
8005 <para>as object: returns by reference the current state, usually
8006 to be used by another function (usually one created by
8007 MSM_EUML_METHOD or MSM_EUML_FUNCTION).</para>
8008 <para>Example:
8009 <programlisting>some_user_function_(state_) // calls some_user_function on the current state</programlisting></para>
8010 </listitem>
8011 <listitem>
8012 <para>as function: returns by reference the attribute passed as
8013 parameter.</para>
8014 <para>Example:
8015 <programlisting>state_(m_counter)++</programlisting></para>
8016 </listitem>
8017 </itemizedlist></para>
8018 </refsect3>
8019 <refsect3>
8020 <title>event_</title>
8021 <para>Generic object or function for the event triggering a given transition
8022 (valid in a transition behavior, as well as in state entry/exit behaviors):<itemizedlist>
8023 <listitem>
8024 <para>as object: returns by reference the event of a transition,
8025 usually to be used by another function (usually one created
8026 by MSM_EUML_METHOD or MSM_EUML_FUNCTION).</para>
8027 <para>Example:
8028 <programlisting>some_user_function_(event_)</programlisting></para>
8029 </listitem>
8030 <listitem>
8031 <para>as function: returns by reference the attribute passed as
8032 parameter.</para>
8033 <para>Example:
8034 <programlisting>event_(m_counter)++</programlisting></para>
8035 </listitem>
8036 </itemizedlist></para>
8037 </refsect3>
8038 <refsect3>
8039 <title>fsm_</title>
8040 <para>Generic object or function for the state machine containing a given transition:<itemizedlist>
8041 <listitem>
8042 <para>as object: returns by reference the event of a transition,
8043 usually to be used by another function (usually one created
8044 by MSM_EUML_METHOD or MSM_EUML_FUNCTION).</para>
8045 <para>Example:
8046 <programlisting>some_user_function_(fsm_)</programlisting></para>
8047 </listitem>
8048 <listitem>
8049 <para>as function: returns by reference the attribute passed as
8050 parameter.</para>
8051 <para>Example:
8052 <programlisting>fsm_(m_counter)++</programlisting></para>
8053 </listitem>
8054 </itemizedlist></para>
8055 </refsect3>
8056 <refsect3>
8057 <title>substate_</title>
8058 <para>Generic object or function returning a state of a given state machine:<itemizedlist>
8059 <listitem>
8060 <para>with 1 parameter: returns by reference the state passed as
8061 parameter, usually to be used by another function (usually
8062 one created by MSM_EUML_METHOD or MSM_EUML_FUNCTION).</para>
8063 <para>Example:
8064 <programlisting>some_user_function_(substate_(my_state))</programlisting></para>
8065 </listitem>
8066 <listitem>
8067 <para>with 2 parameters: returns by reference the state passed
8068 as first parameter from the state machine passed as second
8069 parameter, usually to be used by another function (usually
8070 one created by MSM_EUML_METHOD or MSM_EUML_FUNCTION). This
8071 makes sense when used in combination with attribute_.</para>
8072 <para>Example (equivalent to the previous example):
8073 <programlisting>some_user_function_(substate_(my_state,fsm_))</programlisting></para>
8074 </listitem>
8075 </itemizedlist></para>
8076 </refsect3>
8077 <refsect3>
8078 <title>attribute_</title>
8079 <para>Generic object or function returning the attribute passed (by name) as
8080 second parameter of the thing passed as first (a state, event or state
8081 machine). Example: </para>
8082 <para>
8083 <programlisting>attribute_(substate_(my_state),cd_name_attribute)++</programlisting>
8084 </para>
8085 </refsect3>
8086 <refsect3>
8087 <title>True_</title>
8088 <para>Functor returning true for transition or state behaviors. Like all
8089 constants, only the functor form exists, so parenthesis are necessary.
8090 Example:</para>
8091 <para>
8092 <programlisting>if_then_(True_(),/* some action always called*/)</programlisting>
8093 </para>
8094 </refsect3>
8095 <refsect3>
8096 <title>False_</title>
8097 <para>Functor returning false for transition or state behaviors. Like all
8098 constants, only the functor form exists, so parenthesis are necessary.
8099 Example:</para>
8100 <para>
8101 <programlisting>if_then_(False_(),/* some action never called */)</programlisting>
8102 </para>
8103 </refsect3>
8104 <refsect3>
8105 <title>Int_&lt;int value></title>
8106 <para>Functor returning an integer value for transition or state behaviors.
8107 Like all constants, only the functor form exists, so parenthesis are
8108 necessary. Example:</para>
8109 <para>
8110 <programlisting>target_(m_ringing_cpt) = Int_&lt;RINGING_TIME>() // RINGING_TIME is a constant</programlisting>
8111 </para>
8112 </refsect3>
8113 <refsect3>
8114 <title>Char_&lt;char value></title>
8115 <para>Functor returning a char value for transition or state behaviors. Like
8116 all constants, only the functor form exists, so parenthesis are
8117 necessary. Example:</para>
8118 <para>
8119 <programlisting>// look for 'S' in event.m_song
8120 [string_find_(event_(m_song),Char_&lt;'S'>(),Size_t_&lt;0>()) != Npos_&lt;string>()]</programlisting>
8121 </para>
8122 </refsect3>
8123 <refsect3>
8124 <title>Size_t_&lt;size_t value></title>
8125 <para>Functor returning a size_t value for transition or state behaviors.
8126 Like all constants, only the functor form exists, so parenthesis are
8127 necessary. Example:</para>
8128 <para>
8129 <programlisting>substr_(event_(m_song),Size_t_&lt;1>()) // returns a substring of event.m_song</programlisting>
8130 </para>
8131 </refsect3>
8132 <refsect3>
8133 <title>String_ &lt; mpl::string ></title>
8134 <para>Functor returning a string for transition or state behaviors. Like all
8135 constants, only the functor form exists, so parenthesis are necessary.
8136 Requires boost >= 1.40 for mpl::string.</para>
8137 <para>Example:</para>
8138 <para>
8139 <programlisting>// adds "Let it be" to fsm.m_src_container
8140 push_back_(fsm_(m_src_container), String_&lt;mpl::string&lt;'Let','it ','be'> >())</programlisting>
8141 </para>
8142 </refsect3>
8143 <refsect3>
8144 <title>Predicate_ &lt; some_stl_compatible_functor ></title>
8145 <para>This functor eUML-enables a STL functor (for use in an algorithm).
8146 This is necessary because all what is in the transition table must be a
8147 eUML terminal.</para>
8148 <para>Example:</para>
8149 <programlisting>//equivalent to:
8150 //std::accumulate(fsm.m_vec.begin(),fsm.m_vec.end(),1,std::plus&lt;int>())== 1
8151 accumulate_(begin_(fsm_(m_vec)),end_(fsm_(m_vec)),Int_&lt;1>(),
8152 Predicate_&lt;std::plus&lt;int> >()) == Int_&lt;1>())</programlisting>
8153 </refsect3>
8154 <refsect3>
8155 <title>process_</title>
8156 <para>This function sends an event to up to 4 state machines by calling
8157 <code>process_event</code> on them:<itemizedlist>
8158 <listitem>
8159 <para><code>process_(some_event)</code> : processes an event in
8160 the current (containing) state machine.</para>
8161 </listitem>
8162 <listitem>
8163 <para><code>process_(some_event [,fsm1...fsm4] )</code> :
8164 processes the same event in the 1-4 state machines passed as
8165 argument.</para>
8166 </listitem>
8167 </itemizedlist></para>
8168 </refsect3>
8169 <refsect3>
8170 <title>process2_</title>
8171 <para>This function sends an event to up to 3 state machines by calling
8172 <code>process_event</code> on them and copy-constructing the event
8173 from the data passed as second parameter:<itemizedlist>
8174 <listitem>
8175 <para><code>process2_(some_event, some_data)</code> : processes
8176 an event in the current (containing) state machine.</para>
8177 </listitem>
8178 <listitem>
8179 <para><code>process2_(some_event, some_data [,fsm1...fsm3]
8180 )</code> : processes the same event in the 1-3 state
8181 machines passed as argument.</para>
8182 </listitem>
8183 </itemizedlist></para>
8184 <para>Example: </para>
8185 <para>
8186 <programlisting>// processes NotFound on current state machine,
8187 // copy-constructed with event.m_song
8188 process2_(NotFound,event_(m_song))</programlisting>
8189 </para>
8190 <para>With the following definitions:</para>
8191 <programlisting>BOOST_MSM_EUML_DECLARE_ATTRIBUTE(std::string,m_song)//declaration of m_song
8192 NotFound (const string&amp; data) // copy-constructor of NotFound</programlisting>
8193 </refsect3>
8194 <refsect3>
8195 <title>is_flag_</title>
8196 <para>This function tells if a flag is active by calling
8197 <code>is_flag_active</code> on the current state machine or one
8198 passed as parameter:<itemizedlist>
8199 <listitem>
8200 <para><code>is_flag_(some_flag)</code> : calls
8201 <code>is_flag_active</code> on the current (containing)
8202 state machine.</para>
8203 </listitem>
8204 <listitem>
8205 <para><code>is_flag_(some_flag, some_fsm)</code> :calls
8206 <code>is_flag_active</code> on the state machine.passed
8207 as argument.</para>
8208 </listitem>
8209 </itemizedlist></para>
8210 </refsect3>
8211 <refsect3>
8212 <title>defer_</title>
8213 <para>This object defers the current event by calling
8214 <code>defer_event</code> on the current state machine.
8215 Example:</para>
8216 <programlisting>Empty() + play() / defer_</programlisting>
8217 </refsect3>
8218 <refsect3>
8219 <title>explicit_(submachine-name,state-name)</title>
8220 <para>Used as transition's target, causes an explicit entry into the given
8221 state from the given submachine. Several explicit_ as targets, separated
8222 by commas, means a fork. The state must have been declared as such using
8223 BOOST_MSM_EUML_EXPLICIT_ENTRY_STATE.</para>
8224 </refsect3>
8225 <refsect3>
8226 <title>entry_pt_(submachine-name,state-name)</title>
8227 <para>Used as transition's target from a containing state machine, causes
8228 submachine-name to be entered using the given entry pseudo-state. This
8229 state must have been declared as pseudo entry using
8230 BOOST_MSM_EUML_ENTRY_STATE.</para>
8231 </refsect3>
8232 <refsect3>
8233 <title>exit_pt_(submachine-name,state-name)</title>
8234 <para>Used as transition's source from a containing state machine, causes
8235 submachine-name to be left using the given exit pseudo-state. This state
8236 must have been declared as pseudo exit using
8237 BOOST_MSM_EUML_EXIT_STATE.</para>
8238 </refsect3>
8239 <refsect3>
8240 <title>MSM_EUML_FUNCTION</title>
8241 <para>This macro creates a eUML function and a functor for use with the
8242 functor front-end, based on a free function:<itemizedlist>
8243 <listitem>
8244 <para>first parameter: the name of the functor</para>
8245 </listitem>
8246 <listitem>
8247 <para>second parameter: the underlying function</para>
8248 </listitem>
8249 <listitem>
8250 <para>third parameter: the eUML function name</para>
8251 </listitem>
8252 <listitem>
8253 <para>fourth parameter: the return type if used in a transition
8254 behavior</para>
8255 </listitem>
8256 <listitem>
8257 <para>fifth parameter: the return type if used in a state
8258 behavior (entry/exit)</para>
8259 </listitem>
8260 </itemizedlist> Note that the function itself can take up to 5
8261 arguments.</para>
8262 <para>Example:</para>
8263 <para>
8264 <programlisting>MSM_EUML_FUNCTION(BinarySearch_,std::binary_search,binary_search_,bool,bool)</programlisting>
8265 </para>
8266 <para>Can be used like:</para>
8267 <para>
8268 <programlisting>binary_search_(begin_(fsm_(m_var)),end_(fsm_(m_var)),Int_&lt;9>())</programlisting>
8269 </para>
8270 </refsect3>
8271 <refsect3>
8272 <title>MSM_EUML_METHOD</title>
8273 <para>This macro creates a eUML function and a functor for use with the
8274 functor front-end, based on a method:<itemizedlist>
8275 <listitem>
8276 <para>first parameter: the name of the functor</para>
8277 </listitem>
8278 <listitem>
8279 <para>second parameter: the underlying function</para>
8280 </listitem>
8281 <listitem>
8282 <para>third parameter: the eUML function name</para>
8283 </listitem>
8284 <listitem>
8285 <para>fourth parameter: the return type if used in a transition
8286 behavior</para>
8287 </listitem>
8288 <listitem>
8289 <para>fifth parameter: the return type if used in a state
8290 behavior (entry/exit)</para>
8291 </listitem>
8292 </itemizedlist> Note that the method itself can take up to 4 arguments
8293 (5 like for a free function - 1 for the object on which the method is
8294 called).</para>
8295 <para>Example:</para>
8296 <programlisting>struct Empty : public msm::front::state&lt;> , public euml_state&lt;Empty>
8297 {
8298 void activate_empty() {std::cout &lt;&lt; "switching to Empty " &lt;&lt; std::endl;}
8299 ...
8300 };
8301 MSM_EUML_METHOD(ActivateEmpty_,activate_empty,activate_empty_,void,void)</programlisting>
8302 <para>Can be used like:</para>
8303 <para>
8304 <programlisting>Empty == Open + open_close / (close_drawer , activate_empty_(target_))</programlisting>
8305 </para>
8306 </refsect3>
8307 <refsect3>
8308 <title>BOOST_MSM_EUML_ACTION(action-instance-name)</title>
8309 <para>This macro declares a behavior type and a const instance for use in
8310 state or transition behaviors. The action implementation itself follows
8311 the macro declaration, for example:</para>
8312 <programlisting>BOOST_MSM_EUML_ACTION(good_disk_format)
8313 {
8314 template &lt;class Fsm,class Evt,class SourceState,class TargetState>
8315 void/bool operator()(Evt const&amp; evt,Fsm&amp;,SourceState&amp; ,TargetState&amp; ){...}
8316 };</programlisting>
8317 </refsect3>
8318 <refsect3>
8319 <title>BOOST_MSM_EUML_FLAG(flag-instance-name)</title>
8320 <para>This macro declares a flag type and a const instance for use in
8321 behaviors.</para>
8322 </refsect3>
8323 <refsect3>
8324 <title>BOOST_MSM_EUML_FLAG_NAME(flag-instance-name)</title>
8325 <para>This macro returns the name of the flag type generated by
8326 BOOST_MSM_EUML_FLAG. You need this where the type is required (usually
8327 with the back-end method is_flag_active). For example:</para>
8328 <programlisting>fsm.is_flag_active&lt;BOOST_MSM_EUML_FLAG_NAME(CDLoaded)>()</programlisting>
8329 </refsect3>
8330 <refsect3>
8331 <title>BOOST_MSM_EUML_DECLARE_ATTRIBUTE(event-type,event-name)</title>
8332 <para>This macro declares an attribute called event-name of type event-type.
8333 This attribute can then be made part of an attribute list using
8334 BOOST_MSM_EUML_ATTRIBUTES.</para>
8335 </refsect3>
8336 <refsect3>
8337 <title>BOOST_MSM_EUML_ATTRIBUTES(attributes-expression,attributes-name)</title>
8338 <para>This macro declares an attribute list called attributes-name based on
8339 the expression as first argument. These attributes can then be made part
8340 of an event using BOOST_MSM_EUML_EVENT_WITH_ATTRIBUTES, of a state as
8341 3rd parameter of BOOST_MSM_EUML_STATE or of a state machine as 5th
8342 parameter of BOOST_MSM_EUML_DECLARE_STATE_MACHINE.</para>
8343 <para>Attributes are added using left-shift, for example:</para>
8344 <programlisting>// m_song is of type std::string
8345 BOOST_MSM_EUML_DECLARE_ATTRIBUTE(std::string,m_song)
8346 // contains one attribute, m_song
8347 BOOST_MSM_EUML_ATTRIBUTES((attributes_ &lt;&lt; m_song ), FoundDef)</programlisting>
8348 </refsect3>
8349 <refsect3>
8350 <title>BOOST_MSM_EUML_EVENT(event-instance name)</title>
8351 <para>This macro defines an event type (event-instance-name_helper) and
8352 declares a const instance of this event type called event-instance-name
8353 for use in a transition table or state behaviors.</para>
8354 </refsect3>
8355 <refsect3>
8356 <title>BOOST_MSM_EUML_EVENT_WITH_ATTRIBUTES(event-instance-name,attributes)</title>
8357 <para>This macro defines an event type (event-instance-name_helper) and
8358 declares a const instance of this event type called event-instance-name
8359 for use in a transition table or state behaviors. The event will have as
8360 attributes the ones passed by the second argument:</para>
8361 <para><code>BOOST_MSM_EUML_EVENT_WITH_ATTRIBUTES(Found,FoundDef)</code>
8362 </para>
8363 <para>The created event instance supports operator()(attributes) so that
8364 <programlisting>my_back_end.process_event(Found(some_string))</programlisting>
8365 is possible.</para>
8366 </refsect3>
8367 <refsect3>
8368 <title>BOOST_MSM_EUML_EVENT_NAME(event-instance-name)</title>
8369 <para>This macro returns the name of the event type generated by
8370 BOOST_MSM_EUML_EVENT or BOOST_MSM_EUML_EVENT_WITH_ATTRIBUTES. You need
8371 this where the type is required (usually inside a back-end definition).
8372 For example:</para>
8373 <para>
8374 <programlisting>typedef msm::back::state_machine&lt;Playing_,
8375 msm::back::ShallowHistory&lt;mpl::vector&lt;BOOST_MSM_EUML_EVENT_NAME(end_pause)
8376 > > > Playing_type;</programlisting>
8377 </para>
8378 </refsect3>
8379 <refsect3>
8380 <title>BOOST_MSM_EUML_STATE(build-expression,state-instance-name)</title>
8381 <para>This macro defines a state type (state-instance-name_helper) and
8382 declares a const instance of this state type called state-instance-name
8383 for use in a transition table or state behaviors.</para>
8384 <para>There are several possibilitites for the expression syntax:<itemizedlist>
8385 <listitem>
8386 <para>(): state without entry or exit action.</para>
8387 </listitem>
8388 <listitem>
8389 <para>(Expr1): state with entry but no exit action.</para>
8390 </listitem>
8391 <listitem>
8392 <para>(Expr1,Expr2): state with entry and exit action.</para>
8393 </listitem>
8394 <listitem>
8395 <para>(Expr1,Expr2,Attributes): state with entry and exit
8396 action, defining some attributes.</para>
8397 </listitem>
8398 <listitem>
8399 <para>(Expr1,Expr2,Attributes,Configure): state with entry and
8400 exit action, defining some attributes and flags (standard
8401 MSM flags) or deferred events (standard MSM deferred
8402 events).</para>
8403 </listitem>
8404 <listitem>
8405 <para>(Expr1,Expr2,Attributes,Configure,Base): state with entry
8406 and exit action, defining some attributes, flags and
8407 deferred events (plain msm deferred events) and a
8408 non-default base state (as defined in standard MSM).</para>
8409 </listitem>
8410 </itemizedlist></para>
8411 </refsect3>
8412 <refsect3>
8413 <title>BOOST_MSM_EUML_INTERRUPT_STATE(build-expression,state-instance-name)</title>
8414 <para>This macro defines an interrupt state type
8415 (state-instance-name_helper) and declares a const instance of this state
8416 type called state-instance-name for use in a transition table or state
8417 behaviors.</para>
8418 <para>There are several possibilitites for the expression syntax. In all of
8419 them, the first argument is the name of the event (generated by one of
8420 the previous macros) ending the interrupt:<itemizedlist>
8421 <listitem>
8422 <para>(end_interrupt_event): interrupt state without entry or
8423 exit action.</para>
8424 </listitem>
8425 <listitem>
8426 <para>(end_interrupt_event,Expr1): interrupt state with entry
8427 but no exit action.</para>
8428 </listitem>
8429 <listitem>
8430 <para>(end_interrupt_event,Expr1,Expr2): interrupt state with
8431 entry and exit action.</para>
8432 </listitem>
8433 <listitem>
8434 <para>(end_interrupt_event,Expr1,Expr2,Attributes): interrupt
8435 state with entry and exit action, defining some
8436 attributes.</para>
8437 </listitem>
8438 <listitem>
8439 <para>(end_interrupt_event,Expr1,Expr2,Attributes,Configure):
8440 interrupt state with entry and exit action, defining some
8441 attributes and flags (standard MSM flags) or deferred events
8442 (standard MSM deferred events).</para>
8443 </listitem>
8444 <listitem>
8445 <para>(end_interrupt_event,Expr1,Expr2,Attributes,Configure,Base):
8446 interrupt state with entry and exit action, defining some
8447 attributes, flags and deferred events (plain msm deferred
8448 events) and a non-default base state (as defined in standard
8449 MSM).</para>
8450 </listitem>
8451 </itemizedlist></para>
8452 </refsect3>
8453 <refsect3>
8454 <title>BOOST_MSM_EUML_TERMINATE_STATE(build-expression,state-instance-name)</title>
8455 <para>This macro defines a terminate pseudo-state type
8456 (state-instance-name_helper) and declares a const instance of this state
8457 type called state-instance-name for use in a transition table or state
8458 behaviors.</para>
8459 <para>There are several possibilitites for the expression syntax:<itemizedlist>
8460 <listitem>
8461 <para>(): terminate pseudo-state without entry or exit
8462 action.</para>
8463 </listitem>
8464 <listitem>
8465 <para>(Expr1): terminate pseudo-state with entry but no exit
8466 action.</para>
8467 </listitem>
8468 <listitem>
8469 <para>(Expr1,Expr2): terminate pseudo-state with entry and exit
8470 action.</para>
8471 </listitem>
8472 <listitem>
8473 <para>(Expr1,Expr2,Attributes): terminate pseudo-state with
8474 entry and exit action, defining some attributes.</para>
8475 </listitem>
8476 <listitem>
8477 <para>(Expr1,Expr2,Attributes,Configure): terminate pseudo-state
8478 with entry and exit action, defining some attributes and
8479 flags (standard MSM flags) or deferred events (standard MSM
8480 deferred events).</para>
8481 </listitem>
8482 <listitem>
8483 <para>(Expr1,Expr2,Attributes,Configure,Base): terminate
8484 pseudo-state with entry and exit action, defining some
8485 attributes, flags and deferred events (plain msm deferred
8486 events) and a non-default base state (as defined in standard
8487 MSM).</para>
8488 </listitem>
8489 </itemizedlist></para>
8490 </refsect3>
8491 <refsect3>
8492 <title>BOOST_MSM_EUML_EXIT_STATE(build-expression,state-instance-name)</title>
8493 <para>This macro defines an exit pseudo-state type
8494 (state-instance-name_helper) and declares a const instance of this state
8495 type called state-instance-name for use in a transition table or state
8496 behaviors.</para>
8497 <para>There are several possibilitites for the expression syntax:<itemizedlist>
8498 <listitem>
8499 <para>(forwarded_event):exit pseudo-state without entry or exit
8500 action.</para>
8501 </listitem>
8502 <listitem>
8503 <para>(forwarded_event,Expr1): exit pseudo-state with entry but
8504 no exit action.</para>
8505 </listitem>
8506 <listitem>
8507 <para>(forwarded_event,Expr1,Expr2): exit pseudo-state with
8508 entry and exit action.</para>
8509 </listitem>
8510 <listitem>
8511 <para>(forwarded_event,Expr1,Expr2,Attributes): exit
8512 pseudo-state with entry and exit action, defining some
8513 attributes.</para>
8514 </listitem>
8515 <listitem>
8516 <para>(forwarded_event,Expr1,Expr2,Attributes,Configure): exit
8517 pseudo-state with entry and exit action, defining some
8518 attributes and flags (standard MSM flags) or deferred events
8519 (standard MSM deferred events).</para>
8520 </listitem>
8521 <listitem>
8522 <para>(forwarded_event,Expr1,Expr2,Attributes,Configure,Base):
8523 exit pseudo-state with entry and exit action, defining some
8524 attributes, flags and deferred events (plain msm deferred
8525 events) and a non-default base state (as defined in standard
8526 MSM).</para>
8527 </listitem>
8528 </itemizedlist></para>
8529 <para>Note that the forwarded_event must be constructible from the event
8530 sent by the submachine containing the exit point.</para>
8531 </refsect3>
8532 <refsect3>
8533 <title>BOOST_MSM_EUML_ENTRY_STATE(int
8534 region-index,build-expression,state-instance-name)</title>
8535 <para>This macro defines an entry pseudo-state type
8536 (state-instance-name_helper) and declares a const instance of this state
8537 type called state-instance-name for use in a transition table or state
8538 behaviors.</para>
8539 <para>There are several possibilitites for the expression syntax:<itemizedlist>
8540 <listitem>
8541 <para>(): entry pseudo-state without entry or exit
8542 action.</para>
8543 </listitem>
8544 <listitem>
8545 <para>(Expr1): entry pseudo-state with entry but no exit
8546 action.</para>
8547 </listitem>
8548 <listitem>
8549 <para>(Expr1,Expr2): entry pseudo-state with entry and exit
8550 action.</para>
8551 </listitem>
8552 <listitem>
8553 <para>(Expr1,Expr2,Attributes): entry pseudo-state with entry
8554 and exit action, defining some attributes.</para>
8555 </listitem>
8556 <listitem>
8557 <para>(Expr1,Expr2,Attributes,Configure): entry pseudo-state
8558 with entry and exit action, defining some attributes and
8559 flags (standard MSM flags) or deferred events (standard MSM
8560 deferred events).</para>
8561 </listitem>
8562 <listitem>
8563 <para>(Expr1,Expr2,Attributes,Configure,Base): entry
8564 pseudo-state with entry and exit action, defining some
8565 attributes, flags and deferred events (plain msm deferred
8566 events) and a non-default base state (as defined in standard
8567 MSM).</para>
8568 </listitem>
8569 </itemizedlist></para>
8570 </refsect3>
8571 <refsect3>
8572 <title>BOOST_MSM_EUML_EXPLICIT_ENTRY_STATE(int
8573 region-index,build-expression,state-instance-name)</title>
8574 <para>This macro defines a submachine's substate type
8575 (state-instance-name_helper), which can be explicitly entered and also
8576 declares a const instance of this state type called state-instance-name
8577 for use in a transition table or state behaviors.</para>
8578 <para>There are several possibilitites for the expression syntax:<itemizedlist>
8579 <listitem>
8580 <para>(): state without entry or exit action.</para>
8581 </listitem>
8582 <listitem>
8583 <para>(Expr1): state with entry but no exit action.</para>
8584 </listitem>
8585 <listitem>
8586 <para>(Expr1,Expr2): state with entry and exit action.</para>
8587 </listitem>
8588 <listitem>
8589 <para>(Expr1,Expr2,Attributes): state with entry and exit
8590 action, defining some attributes.</para>
8591 </listitem>
8592 <listitem>
8593 <para>(Expr1,Expr2,Attributes,Configure): state with entry and
8594 exit action, defining some attributes and flags (standard
8595 MSM flags) or deferred events (standard MSM deferred
8596 events).</para>
8597 </listitem>
8598 <listitem>
8599 <para>(Expr1,Expr2,Attributes,Configure,Base): state with entry
8600 and exit action, defining some attributes, flags and
8601 deferred events (plain msm deferred events) and a
8602 non-default base state (as defined in standard MSM).</para>
8603 </listitem>
8604 </itemizedlist></para>
8605 </refsect3>
8606 <refsect3>
8607 <title>BOOST_MSM_EUML_STATE_NAME(state-instance-name)</title>
8608 <para>This macro returns the name of the state type generated by
8609 BOOST_MSM_EUML_STATE or other state macros. You need this where the type
8610 is required (usually using a backend function). For example:</para>
8611 <para>
8612 <programlisting>fsm.get_state&lt;BOOST_MSM_EUML_STATE_NAME(StringFind)&amp;>().some_state_function();</programlisting>
8613 </para>
8614 </refsect3>
8615 <refsect3>
8616 <title>BOOST_MSM_EUML_DECLARE_STATE(build-expression,state-instance-name)</title>
8617 <para>Like BOOST_MSM_EUML_STATE but does not provide an instance, simply a
8618 type declaration.</para>
8619 </refsect3>
8620 <refsect3>
8621 <title>BOOST_MSM_EUML_DECLARE_INTERRUPT_STATE(build-expression,state-instance-name)</title>
8622 <para>Like BOOST_MSM_EUML_INTERRUPT_STATE but does not provide an instance,
8623 simply a type declaration.</para>
8624 </refsect3>
8625 <refsect3>
8626 <title>BOOST_MSM_EUML_DECLARE_TERMINATE_STATE(build-expression,state-instance-name)</title>
8627 <para>Like BOOST_MSM_EUML_TERMINATE_STATE but does not provide an instance,
8628 simply a type declaration.</para>
8629 </refsect3>
8630 <refsect3>
8631 <title>BOOST_MSM_EUML_DECLARE_EXIT_STATE(build-expression,state-instance-name)</title>
8632 <para>Like BOOST_MSM_EUML_EXIT_STATE but does not provide an instance,
8633 simply a type declaration.</para>
8634 </refsect3>
8635 <refsect3>
8636 <title>BOOST_MSM_EUML_DECLARE_ENTRY_STATE(int
8637 region-index,build-expression,state-instance-name)</title>
8638 <para>Like BOOST_MSM_EUML_ENTRY_STATE but does not provide an instance,
8639 simply a type declaration.</para>
8640 </refsect3>
8641 <refsect3>
8642 <title>BOOST_MSM_EUML_DECLARE_EXPLICIT_ENTRY_STATE(int
8643 region-index,build-expression,state-instance-name)</title>
8644 <para>Like BOOST_MSM_EUML_EXPLICIT_ENTRY_STATE but does not provide an
8645 instance, simply a type declaration.</para>
8646 </refsect3>
8647 <refsect3>
8648 <title>BOOST_MSM_EUML_TRANSITION_TABLE(expression,
8649 table-instance-name)</title>
8650 <para>This macro declares a transition table type and also declares a const
8651 instance of the table which can then be used in a state machine
8652 declaration (see BOOST_MSM_EUML_DECLARE_STATE_MACHINE).The expression
8653 must follow the <command xlink:href="#reference-stt-grammar">transition
8654 table grammar</command>.</para>
8655 </refsect3>
8656 <refsect3>
8657 <title>BOOST_MSM_EUML_DECLARE_TRANSITION_TABLE(iexpression,table-instance-name)</title>
8658 <para>Like BOOST_MSM_EUML_TRANSITION_TABLE but does not provide an instance,
8659 simply a type declaration.</para>
8660 </refsect3>
8661 <refsect3>
8662 <title>BOOST_MSM_EUML_INTERNAL_TRANSITION_TABLE(expression,
8663 table-instance-name)</title>
8664 <para>This macro declares a transition table type and also declares a const
8665 instance of the table.The expression must follow the <command
8666 xlink:href="#reference-stt-grammar">transition table
8667 grammar</command>. For the moment, this macro is not used.</para>
8668 </refsect3>
8669 <refsect3>
8670 <title>BOOST_MSM_EUML_DECLARE_INTERNAL_TRANSITION_TABLE(iexpression,table-instance-name)</title>
8671 <para>Like BOOST_MSM_EUML_TRANSITION_TABLE but does not provide an instance,
8672 simply a type declaration. This is currently the only way to declare an
8673 internal transition table with eUML. For example:</para>
8674 <programlisting>BOOST_MSM_EUML_DECLARE_STATE((Open_Entry,Open_Exit),Open_def)
8675 struct Open_impl : public Open_def
8676 {
8677 BOOST_MSM_EUML_DECLARE_INTERNAL_TRANSITION_TABLE((
8678 open_close [internal_guard1] / internal_action1 ,
8679 open_close [internal_guard2] / internal_action2
8680 ))
8681 }; </programlisting>
8682 </refsect3>
8683 </refsect2>
8684 </refsect1>
8685 </refentry>
8686 </part>
8687 </book>