-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreference.html
3594 lines (2878 loc) · 126 KB
/
reference.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="GENERATOR" content="Microsoft FrontPage 12.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<link rel="stylesheet" type="text/css" href="../../../boost.css">
<title>The Boost Statechart Library - Reference</title>
<style type="text/css">
.style1
{
width: 45%;
}
</style>
</head>
<body link="#0000FF" vlink="#800080">
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
"header">
<tr>
<td valign="top" width="300">
<h3><a href="../../../index.htm"><img alt="C++ Boost" src=
"../../../boost.png" border="0" width="277" height="86"></a></h3>
</td>
<td valign="top">
<h1 align="center">The Boost Statechart Library</h1>
<h2 align="center">Reference</h2>
</td>
</tr>
</table>
<hr>
<h2>Contents</h2>
<dl class="page-index">
<dt><a href="#Concepts">Concepts</a></dt>
<dd><a href="#Scheduler">Scheduler</a></dd>
<dd><a href="#FifoWorker">FifoWorker</a></dd>
<dd><a href="#ExceptionTranslator">ExceptionTranslator</a></dd>
<dd><a href="#StateBase">StateBase</a></dd>
<dd><a href="#SimpleState">SimpleState</a></dd>
<dd><a href="#State">State</a></dd>
<dd><a href="#Event">Event</a></dd>
<dt><a href="#state_machine.hpp">state_machine.hpp</a></dt>
<dd><a href="#ClassTemplatestate_machine">Class template
<code>state_machine</code></a></dd>
<dt><a href=
"#asynchronous_state_machine.hpp">asynchronous_state_machine.hpp</a></dt>
<dd><a href="#ClassTemplateasynchronous_state_machine">Class template
<code>asynchronous_state_machine</code></a></dd>
<dt><a href="#event_processor.hpp">event_processor.hpp</a></dt>
<dd><a href="#ClassTemplateevent_processor">Class template
<code>event_processor</code></a></dd>
<dt><a href="#fifo_scheduler.hpp">fifo_scheduler.hpp</a></dt>
<dd><a href="#ClassTemplatefifo_scheduler">Class template
<code>fifo_scheduler</code></a></dd>
<dt><a href="#exception_translator.hpp">exception_translator.hpp</a></dt>
<dd><a href="#ClassTemplateexception_translator">Class template
<code>exception_translator</code></a></dd>
<dt><a href=
"#null_exception_translator.hpp">null_exception_translator.hpp</a></dt>
<dd><a href="#Classnull_exception_translator">Class
<code>null_exception_translator</code></a></dd>
<dt> </dt>
<dt><a href="#simple_state.hpp">simple_state.hpp</a></dt>
<dd><a href="#Enumhistory_mode">Enum <code>history_mode</code></a></dd>
<dd><a href="#ClassTemplatesimple_state">Class template
<code>simple_state</code></a></dd>
<dt><a href="#state.hpp">state.hpp</a></dt>
<dd><a href="#ClassTemplatestate">Class template
<code>state</code></a></dd>
<dt><a href="#shallow_history.hpp">shallow_history.hpp</a></dt>
<dd><a href="#ClassTemplateshallow_history">Class template
<code>shallow_history</code></a></dd>
<dt><a href="#deep_history.hpp">deep_history.hpp</a></dt>
<dd><a href="#ClassTemplatedeep_history">Class template
<code>deep_history</code></a></dd>
<dt> </dt>
<dt><a href="#event_base.hpp">event_base.hpp</a></dt>
<dd><a href="#Classevent_base">Class <code>event_base</code></a></dd>
<dt><a href="#event.hpp">event.hpp</a></dt>
<dd><a href="#ClassTemplateevent">Class template
<code>event</code></a></dd>
<dt> </dt>
<dt><a href="#transition.hpp">transition.hpp</a></dt>
<dd><a href="#ClassTemplatetransition">Class template
<code>transition</code></a></dd>
<dt><a href="#in_state_reaction.hpp">in_state_reaction.hpp</a></dt>
<dd><a href="#ClassTemplatein_state_reaction">Class template
in_state_reaction</a></dd>
<dt><a href="#termination.hpp">termination.hpp</a></dt>
<dd><a href="#ClassTemplatetermination">Class template
<code>termination</code></a></dd>
<dt><a href="#deferral.hpp">deferral.hpp</a></dt>
<dd><a href="#ClassTemplatedeferral">Class template
<code>deferral</code></a></dd>
<dt><a href="#custom_reaction.hpp">custom_reaction.hpp</a></dt>
<dd><a href="#ClassTemplatecustom_reaction">Class template
<code>custom_reaction</code></a></dd>
<dt><a href="#result.hpp">result.hpp</a></dt>
<dd><a href="#Classresult">Class <code>result</code></a></dd>
</dl>
<hr>
<h1><a name="Concepts" id="Concepts">Concepts</a></h1>
<h2><a name="Scheduler" id="Scheduler">Scheduler</a> concept</h2>
<p>A Scheduler type defines the following:</p>
<ul>
<li>What is passed to the constructors of <code><a href=
"#ClassTemplateevent_processor">event_processor<></a></code>
subtypes and how the lifetime of such objects is managed</li>
<li>Whether or not multiple <code>event_processor<></code> subtype
objects can share the same queue and scheduler thread</li>
<li>How events are added to the schedulers' queue</li>
<li>Whether and how to wait for new events when the schedulers' queue
runs empty</li>
<li>Whether and what type of locking is used to ensure thread-safety</li>
<li>Whether it is possible to queue events for no longer existing
<code>event_processor<></code> subtype objects and what happens
when such an event is processed</li>
<li>What happens when one of the serviced
<code>event_processor<></code> subtype objects propagates an
exception</li>
</ul>
<p>For a Scheduler type <code>S</code> and an object <code>cpc</code> of
type <code>const S::processor_context</code> the following expressions must
be well-formed and have the indicated results:</p>
<table border="3" cellpadding="2" width="100%" summary="Scheduler concept">
<tr>
<td><b>Expression</b></td>
<td><b>Type</b></td>
<td><b>Result</b></td>
</tr>
<tr>
<td><code>cpc.my_scheduler()</code></td>
<td><code>S &</code></td>
<td>A reference to the scheduler</td>
</tr>
<tr>
<td><code>cpc.my_handle()</code></td>
<td><code>S::processor_handle</code></td>
<td>The handle identifying the
<code>event_processor<></code> subtype object</td>
</tr>
</table>
<p>To protect against abuse, all members of
<code>S::processor_context</code> should be declared private. As a result,
<code>event_processor<></code> must be a friend of
<code>S::processor_context</code>.</p>
<h2><a name="FifoWorker" id="FifoWorker">FifoWorker</a> concept</h2>
<p>A FifoWorker type defines the following:</p>
<ul>
<li>Whether and how to wait for new work items when the internal work
queue runs empty</li>
<li>Whether and what type of locking is used to ensure thread-safety</li>
</ul>
<p>For a FifoWorker type <code>F</code>, an object <code>f</code> of that
type, a <code>const</code> object <code>cf</code> of that type, a
parameterless function object <code>w</code> of arbitrary type and an
<code>unsigned long</code> value <code>n</code> the following
expressions/statements must be well-formed and have the indicated
results:</p>
<table border="3" cellpadding="2" width="100%" summary=
"FifoWorker concept">
<tr>
<td><b>Expression/Statement</b></td>
<td><b>Type</b></td>
<td><b>Effects/Result</b></td>
</tr>
<tr>
<td><code>F::work_item</code></td>
<td><code>boost::function0< void ></code></td>
<td> </td>
</tr>
<tr>
<td><code>F()</code> or <code>F( false )</code></td>
<td><code>F</code></td>
<td>Constructs a <b>non-blocking</b> (see below) object of
the FifoWorker type. In single-threaded builds the second expression is
not well-formed</td>
</tr>
<tr>
<td><code>F( true )</code></td>
<td><code>F</code></td>
<td>Constructs a <b>blocking</b> (see below) object of the
FifoWorker type. Not well-formed in single-threaded builds</td>
</tr>
<tr>
<td><code>f.queue_work_item( w );</code></td>
<td> </td>
<td>Constructs and queues an object of type
<code>F::work_item</code>, passing <code>w</code> as the only
argument</td>
</tr>
<tr>
<td><code>f.terminate();</code></td>
<td> </td>
<td>Creates and queues an object of type
<code>F::work_item</code> that, when later executed in
<code>operator()()</code>, leads to a modification of internal state so
that <code>terminated()</code> henceforth returns
<code>true</code></td>
</tr>
<tr>
<td><code>cf.terminated();</code></td>
<td><code>bool</code></td>
<td><code>true</code> if <code>terminate()</code> has been
called and the resulting work item has been executed in
<code>operator()()</code>. Returns <code>false</code> otherwise<br>
<br>
<b>Must only be called from the thread that also calls
<code>operator()()</code></b></td>
</tr>
<tr>
<td><code>f( n );</code></td>
<td><code>unsigned long</code></td>
<td>
Enters a loop that, with each cycle, dequeues and calls
<code>operator()()</code> on the oldest work item in the queue.
<p>The loop is left and the number of executed work items returned if
one or more of the following conditions are met:</p>
<ul>
<li><code>f.terminated() == true</code></li>
<li>The application is single-threaded and the internal queue is
empty</li>
<li>The application is multi-threaded and the internal queue is
empty and the worker was created as non-blocking</li>
<li><code>n != 0</code> and the number of work items that have been
processed since <code>operator()()</code> was called equals
<code>n</code></li>
</ul>
<p>If the queue is empty and none of the above conditions are met
then the thread calling <code>operator()()</code> is put into a wait
state until <code>f.queue_work_item()</code> is called from another
thread.<br>
<br>
<b>Must only be called from exactly one thread</b></p>
</td>
</tr>
<tr>
<td><code>f();</code></td>
<td><code>unsigned long</code></td>
<td>Has exactly the same semantics as <code>f( n );</code>
with <code>n == 0</code> (see above)</td>
</tr>
</table>
<h2><a name="ExceptionTranslator" id=
"ExceptionTranslator">ExceptionTranslator</a> concept</h2>
<p>An ExceptionTranslator type defines how C++ exceptions occurring during
state machine operation are translated to exception events.</p>
<p>For an ExceptionTranslator object <code>et</code>, a parameterless
function object <code>a</code> of arbitrary type returning <code><a href=
"#Classresult">result</a></code> and a function object <code>eh</code> of
arbitrary type taking a <code>const <a href=
"#Classevent_base">event_base</a> &</code> parameter and returning
<code><a href="#Classresult">result</a></code> the following expression
must be well-formed and have the indicated results:</p>
<table border="3" cellpadding="2" width="100%" summary=
"ExceptionTranslator concept">
<tr>
<td><b>Expression</b></td>
<td><b>Type</b></td>
<td><b>Effects/Result</b></td>
</tr>
<tr>
<td><code>et( a, eh );</code></td>
<td><code>result</code></td>
<td>
<ol>
<li>Attempts to execute <code>return a();</code></li>
<li>If <code>a()</code> propagates an exception, the exception is
caught</li>
<li>Inside the catch block calls <code>eh</code>, passing a
suitable stack-allocated model of the <a href="#Event">Event</a>
concept</li>
<li>Returns the result returned by <code>eh</code></li>
</ol>
</td>
</tr>
</table>
<h2><a name="StateBase" id="StateBase">StateBase</a> concept</h2>
<p>A StateBase type is the common base of all states of a given state
machine type. <code>state_machine<>::state_base_type</code> is a
model of the StateBase concept.</p>
<p>For a StateBase type <code>S</code> and a <code>const</code> object
<code>cs</code> of that type the following expressions must be well-formed
and have the indicated results:</p>
<table border="3" cellpadding="2" width="100%" summary="StateBase concept">
<tr>
<td><b>Expression</b></td>
<td><b>Type</b></td>
<td><b>Result</b></td>
</tr>
<tr>
<td><code>cs.outer_state_ptr()</code></td>
<td><code>const S *</code></td>
<td><code>0</code> if <code>cs</code> is an <a href=
"definitions.html#OutermostState">outermost state</a>, a pointer to the
direct outer state of <code>cs</code> otherwise</td>
</tr>
<tr>
<td><code>cs.dynamic_type()</code></td>
<td><code>S::id_type</code></td>
<td>A value unambiguously identifying the most-derived type
of <code>cs</code>. <code>S::id_type</code> values are comparable with
<code>operator==()</code> and <code>operator!=()</code>. An unspecified
collating order can be established with <code>std::less< S::id_type
></code>. In contrast to <code>typeid( cs )</code>, this function is
available even on platforms that do not support C++ RTTI (or have been
configured to not support it)</td>
</tr>
<tr>
<td><code>cs.custom_dynamic_type_ptr<<br>
Type >()</code></td>
<td><code>const Type *</code></td>
<td>A pointer to the custom type identifier or
<code>0</code>. If <code>!= 0</code>, <code>Type</code> must match the
type of the previously set pointer. This function is only available if
<a href=
"configuration.html#ApplicationDefinedMacros">BOOST_STATECHART_USE_NATIVE_RTTI</a>
is not defined</td>
</tr>
</table>
<h2><a name="SimpleState" id="SimpleState">SimpleState</a> concept</h2>
<p>A SimpleState type defines one state of a particular state machine.</p>
<p>For a SimpleState type <code>S</code> and a pointer <code>pS</code>
pointing to an object of type <code>S</code> allocated with
<code>new</code> the following expressions/statements must be well-formed
and have the indicated effects/results:</p>
<table border="3" cellpadding="2" width="100%" summary=
"SimpleState concept">
<tr>
<td><b>Expression/Statement</b></td>
<td><b>Type</b></td>
<td><b>Effects/Result/Notes</b></td>
</tr>
<tr>
<td><code><a href=
"#ClassTemplatesimple_state">simple_state</a><<br>
S, C, I, h > * pB =<br>
pS;</code></td>
<td> </td>
<td><code>simple_state< S, C, I, h ></code> must be
an unambiguous public base of <code>S</code>. See <code><a href=
"#ClassTemplatesimple_state">simple_state<></a></code>
documentation for the requirements and semantics of <code>C</code>,
<code>I</code> and <code>h</code></td>
</tr>
<tr>
<td><code>new S()</code></td>
<td><code>S *</code></td>
<td>Enters the state <code>S</code>. Certain functions must
not be called from <code>S::S()</code>, see <a href=
"#ClassTemplatesimple_state"><code>simple_state<></code></a>
documentation for more information</td>
</tr>
<tr>
<td><code>pS->exit();</code></td>
<td> </td>
<td>Exits the state <code>S</code> (first stage). The
definition of an <code>exit</code> member function within models of the
SimpleState concept is optional since <code>simple_state<></code>
already defines the following public member: <code>void exit()
{}</code>. <code>exit()</code> is not called when a state is exited
while an exception is pending, see <code><a href=
"#simple_state::terminate">simple_state<>::terminate()</a></code>
for more information</td>
</tr>
<tr>
<td><code>delete pS;</code></td>
<td> </td>
<td>Exits the state <code>S</code> (second stage)</td>
</tr>
<tr>
<td><code>S::reactions</code></td>
<td>An <code>mpl::list<></code> that is either empty
or contains instantiations of the <code><a href=
"#ClassTemplatecustom_reaction">custom_reaction</a></code>,
<code><a href=
"#ClassTemplatein_state_reaction">in_state_reaction</a></code>,
<code><a href="#ClassTemplatedeferral">deferral</a></code>,
<code><a href="#ClassTemplatetermination">termination</a></code> or
<code><a href="#ClassTemplatetransition">transition</a></code> class
templates. If there is only a single reaction then it can also be
<code>typedef</code>ed directly, without wrapping it into an
<code>mpl::list<></code></td>
<td>The declaration of a <code>reactions</code> member
<code>typedef</code> within models of the SimpleState concept is
optional since <code>simple_state<></code> already defines the
following public member: <code>typedef mpl::list<>
reactions;</code></td>
</tr>
</table>
<h2><a name="State" id="State">State</a> concept</h2>
<p>A State is a <b>refinement</b> of <a href="#SimpleState">SimpleState</a>
(that is, except for the default constructor a State type must also satisfy
SimpleState requirements). For a State type <code>S</code>, a pointer
<code>pS</code> of type <code>S *</code> pointing to an object of type
<code>S</code> allocated with <code>new</code>, and an object
<code>mc</code> of type <code>state< S, C, I, h
></code><code>::my_context</code> the following expressions/statements
must be well-formed:</p>
<table border="3" cellpadding="2" width="100%" summary="State concept">
<tr>
<td><b>Expression/Statement</b></td>
<td><b>Type</b></td>
<td><b>Effects/Result/Notes</b></td>
</tr>
<tr>
<td><code><a href="#ClassTemplatestate">state</a>< S, C, I, h > *<br>
pB = pS;</code></td>
<td> </td>
<td><code>state< S, C, I, h ></code> must be an
unambiguous public base of <code>S</code>. See <code><a href=
"#ClassTemplatestate">state<></a></code> documentation for the
requirements and semantics of <code>C</code>, <code>I</code> and
<code>h</code></td>
</tr>
<tr>
<td><code>new S( mc )</code></td>
<td><code>S *</code></td>
<td>Enters the state <code>S</code>. No restrictions exist
regarding the functions that can be called from <code>S::S()</code> (in
contrast to the constructors of models of the SimpleState concept).
<code>mc</code> must be forwarded to <code>state< S, C, I, h
>::state()</code></td>
</tr>
</table>
<h2><a name="Event" id="Event">Event</a> concept</h2>
<p>A Event type defines an event for which state machines can define
reactions.</p>
<p>For a Event type <code>E</code> and a pointer <code>pCE</code> of type
<code>const E *</code> pointing to an object of type <code>E</code>
allocated with <code>new</code> the following expressions/statements must
be well-formed and have the indicated effects/results:</p>
<table border="3" cellpadding="2" width="100%" summary="Event concept">
<tr>
<td><b>Expression/Statement</b></td>
<td><b>Type</b></td>
<td><b>Effects/Result/Notes</b></td>
</tr>
<tr>
<td><code>const <a href="#ClassTemplateevent">event</a><
E > * pCB = pCE;</code></td>
<td> </td>
<td><code>event< E ></code> must be an unambiguous
public base of <code>E</code></td>
</tr>
<tr>
<td><code>new E( *pCE )</code></td>
<td><code>E *</code></td>
<td>Makes a copy of <code>pE</code></td>
</tr>
</table>
<h1>Header <boost/statechart/<a name="state_machine.hpp" id=
"state_machine.hpp">state_machine.hpp</a>></h1>
<h2><a name="ClassTemplatestate_machine" id=
"ClassTemplatestate_machine">Class template
<code>state_machine</code></a></h2>
<p>This is the base class template of all synchronous state machines.</p>
<h3>Class template <code>state_machine</code> parameters</h3>
<table border="3" cellpadding="2" width="100%" summary=
"state_machine parameters">
<tr>
<td><b>Template parameter</b></td>
<td><b>Requirements</b></td>
<td><b>Semantics</b></td>
<td><b>Default</b></td>
</tr>
<tr>
<td><code>MostDerived</code></td>
<td>The most-derived subtype of this class template</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><code>InitialState</code></td>
<td>A model of the <a href="#SimpleState">SimpleState</a>
or <a href="#State">State</a> concepts. The <code>Context</code>
argument passed to the <code><a href=
"#ClassTemplatesimple_state">simple_state<></a></code> or
<code><a href="#ClassTemplatestate">state<></a></code> base
of <code>InitialState</code> must be <code>MostDerived</code>.
That is, <code>InitialState</code> must be an <a href=
"definitions.html#OutermostState">outermost state</a> of this state
machine</td>
<td>The state that is entered when
<code>state_machine<><br>
::initiate()</code> is called</td>
<td> </td>
</tr>
<tr>
<td><code>Allocator</code></td>
<td>A model of the standard Allocator concept</td>
<td><code>Allocator::rebind<>::other</code> is used
to allocate and deallocate all <code>simple_state</code> subtype
objects and internal objects of dynamic storage duration</td>
<td><code>std::allocator< void ></code></td>
</tr>
<tr>
<td><code>ExceptionTranslator</code></td>
<td>A model of the ExceptionTranslator concept</td>
<td>see <a href=
"#ExceptionTranslator">ExceptionTranslator</a> concept</td>
<td><code>null_exception_translator</code></td>
</tr>
</table>
<h3>Class template <code>state_machine</code> synopsis</h3>
<pre>
namespace boost
{
namespace statechart
{
template<
class MostDerived,
class InitialState,
class Allocator = std::allocator< void >,
class ExceptionTranslator = null_exception_translator >
class state_machine : noncopyable
{
public:
typedef MostDerived outermost_context_type;
void <a href="#initiate">initiate</a>();
void <a href="#terminate">terminate</a>();
bool <a href="#terminated">terminated</a>() const;
void <a href="#process_event">process_event</a>( const <a href=
"#Classevent_base">event_base</a> & );
template< class Target >
Target <a href="#state_cast">state_cast</a>() const;
template< class Target >
Target <a href="#state_downcast">state_downcast</a>() const;
// a model of the <a href="#StateBase">StateBase</a> concept
typedef <i>implementation-defined</i> state_base_type;
// a model of the standard Forward Iterator concept
typedef <i>implementation-defined</i> state_iterator;
state_iterator <a href="#state_begin">state_begin</a>() const;
state_iterator <a href="#state_end">state_end</a>() const;
void <a href="#unconsumed_event">unconsumed_event</a>( const <a href=
"#Classevent_base">event_base</a> & ) {}
protected:
<a href="#state_machine">state_machine</a>();
<a href="#state_machinedtor">~state_machine</a>();
void <a href="#post_event2">post_event</a>(
const intrusive_ptr< const <a href=
"#Classevent_base">event_base</a> > & );
void <a href="#post_event3">post_event</a>( const <a href=
"#Classevent_base">event_base</a> & );
const event_base * <a href="#triggering_event1">triggering_event</a>() const;
};
}
}
</pre>
<h3>Class template <code>state_machine</code> constructor and
destructor</h3>
<pre>
<a name="state_machine" id="state_machine">state_machine</a>();
</pre>
<p><b>Effects</b>: Constructs a non-running state machine</p>
<pre>
<a name="state_machinedtor" id="state_machinedtor">~state_machine</a>();
</pre>
<p><b>Effects</b>: Destructs the currently active outermost state and all
its direct and indirect inner states. Innermost states are destructed
first. Other states are destructed as soon as all their direct and indirect
inner states have been destructed. The inner states of each state are
destructed according to the number of their orthogonal region. The state in
the orthogonal region with the highest number is always destructed first,
then the state in the region with the second-highest number and so on<br>
<b>Note</b>: Does not attempt to call any <code>exit</code> member
functions</p>
<h3>Class template <code>state_machine</code> modifier functions</h3>
<pre>
void <a name="initiate" id="initiate">initiate</a>();
</pre>
<p><b>Effects</b>:</p>
<ol>
<li>Calls <code>terminate()</code></li>
<li>Constructs a function object <code>action</code> with a
parameter-less <code>operator()()</code> returning <code><a href=
"#Classresult">result</a></code> that
<ol type="a">
<li>enters (constructs) the state specified with the
<code>InitialState</code> template parameter</li>
<li>enters the tree formed by the direct and indirect inner initial
states of <code>InitialState</code> depth first. The inner states of
each state are entered according to the number of their orthogonal
region. The state in orthogonal region 0 is always entered first,
then the state in region 1 and so on</li>
</ol>
</li>
<li>Constructs a function object <code>exceptionEventHandler</code> with
an <code>operator()()</code> returning <code>result</code> and accepting
an exception event parameter that processes the passed exception event,
with the following differences to the processing of normal events:
<ul type="disc">
<li>From the moment when the exception has been thrown until right
after the execution of the exception event reaction, states that need
to be exited are only destructed but no <code>exit</code> member
functions are called</li>
<li><a href="definitions.html#Reaction">Reaction</a> search always
starts with the outermost <a href=
"definitions.html#UnstableState">unstable state</a></li>
<li>As for normal events, reaction search moves outward when the
current state cannot handle the event. However, if there is no outer
state (an <a href="definitions.html#OutermostState">outermost
state</a> has been reached) the reaction search is considered
unsuccessful. That is, exception events will never be dispatched to
orthogonal regions other than the one that caused the exception
event</li>
<li>Should an exception be thrown during exception event reaction
search or reaction execution then the exception is propagated out of
the <code>exceptionEventHandler</code> function object (that is,
<code>ExceptionTranslator</code> is <b>not</b> used to translate
exceptions thrown while processing an exception event)</li>
<li>If no reaction could be found for the exception event or if the
state machine is not stable after processing the exception event, the
original exception is rethrown. Otherwise, a <code><a href=
"#Classresult">result</a></code> object is returned equal to the one
returned by <code>simple_state<>::discard_event()</code></li>
</ul>
</li>
<li>Passes <code>action</code> and <code>exceptionEventHandler</code> to
<code>ExceptionTranslator::operator()()</code>. If
<code>ExceptionTranslator::operator()()</code> throws an exception, the
exception is propagated to the caller. If the caller catches the
exception, the currently active outermost state and all its direct and
indirect inner states are destructed. Innermost states are destructed
first. Other states are destructed as soon as all their direct and
indirect inner states have been destructed. The inner states of each
state are destructed according to the number of their orthogonal region.
The state in the orthogonal region with the highest number is always
destructed first, then the state in the region with the second-highest
number and so on. Continues with step 5 otherwise (the return value is
discarded)</li>
<li>Processes all posted events (see <code>process_event()</code>).
Returns to the caller if there are no more posted events</li>
</ol>
<p><b>Throws</b>: Any exceptions propagated from
<code>ExceptionTranslator::operator()()</code>. Exceptions never originate
in the library itself but only in code supplied through template
parameters:</p>
<ul>
<li><code>Allocator::rebind<>::other::allocate()</code></li>
<li>state constructors</li>
<li><code>react</code> member functions</li>
<li><code>exit</code> member functions</li>
<li>transition-actions</li>
</ul>
<pre>
void <a name="terminate" id="terminate">terminate</a>();
</pre>
<p><b>Effects</b>:</p>
<ol>
<li>Constructs a function object <code>action</code> with a
parameter-less <code>operator()()</code> returning <code><a href=
"#Classresult">result</a></code> that <a href=
"#simple_state::terminate">terminates</a> the currently active outermost
state, discards all remaining events and clears all history
information</li>
<li>Constructs a function object <code>exceptionEventHandler</code> with
an <code>operator()()</code> returning <code><a href=
"#Classresult">result</a></code> and accepting an exception event
parameter that processes the passed exception event, with the following
differences to the processing of normal events:
<ul type="disc">
<li>From the moment when the exception has been thrown until right
after the execution of the exception event reaction, states that need
to be exited are only destructed but no <code>exit</code> member
functions are called</li>
<li><a href="definitions.html#Reaction">Reaction</a> search always
starts with the outermost <a href=
"definitions.html#UnstableState">unstable state</a></li>
<li>As for normal events, reaction search moves outward when the
current state cannot handle the event. However, if there is no outer
state (an <a href="definitions.html#OutermostState">outermost
state</a> has been reached) the reaction search is considered
unsuccessful. That is, exception events will never be dispatched to
orthogonal regions other than the one that caused the exception
event</li>
<li>Should an exception be thrown during exception event reaction
search or reaction execution then the exception is propagated out of
the <code>exceptionEventHandler</code> function object (that is,
<code>ExceptionTranslator</code> is <b>not</b> used to translate
exceptions thrown while processing an exception event)</li>
<li>If no reaction could be found for the exception event or if the
state machine is not stable after processing the exception event, the
original exception is rethrown. Otherwise, a <code><a href=
"#Classresult">result</a></code> object is returned equal to the one
returned by <code>simple_state<>::discard_event()</code></li>
</ul>
</li>
<li>Passes <code>action</code> and <code>exceptionEventHandler</code> to
<code>ExceptionTranslator::operator()()</code>. If
<code>ExceptionTranslator::operator()()</code> throws an exception, the
exception is propagated to the caller. If the caller catches the
exception, the currently active outermost state and all its direct and
indirect inner states are destructed. Innermost states are destructed
first. Other states are destructed as soon as all their direct and
indirect inner states have been destructed. The inner states of each
state are destructed according to the number of their orthogonal region.
The state in the orthogonal region with the highest number is always
destructed first, then the state in the region with the second-highest
number and so on. Otherwise, returns to the caller</li>
</ol>
<p><b>Throws</b>: Any exceptions propagated from
<code>ExceptionTranslator::operator()</code>. Exceptions never originate in
the library itself but only in code supplied through template
parameters:</p>
<ul>
<li><code>Allocator::rebind<>::other::allocate()</code></li>
<li>state constructors</li>
<li><code>react</code> member functions</li>
<li><code>exit</code> member functions</li>
<li>transition-actions</li>
</ul>
<pre>
void <a name="process_event" id=
"process_event">process_event</a>( const <a href=
"#Classevent_base">event_base</a> & );
</pre>
<p><b>Effects</b>:</p>
<ol>
<li>Selects the passed event as the current event (henceforth referred to
as <code>currentEvent</code>)</li>
<li>Starts a new <a href="definitions.html#Reaction">reaction</a>
search</li>
<li>Selects an arbitrary but in this reaction search not yet visited
state from all the currently active <a href=
"definitions.html#InnermostState">innermost states</a>. If no such state
exists then continues with step 10</li>
<li>Constructs a function object <code>action</code> with a
parameter-less <code>operator()()</code> returning <code><a href=
"#Classresult">result</a></code> that does the following:
<ol type="a">
<li>Searches a reaction suitable for <code>currentEvent</code>,
starting with the current innermost state and moving outward until a
state defining a reaction for the event is found. Returns
<code>simple_state<>::forward_event()</code> if no reaction has
been found</li>
<li>Executes the found reaction. If the reaction result is equal to