C++ Boost

Boost Statechart 庫

Reference 參考


Contents 目錄

Concepts 概念
Scheduler 調度器
FifoWorker 先入先出工作者
ExceptionTranslator 異常轉換器
StateBase 狀態基
SimpleState 簡單狀態
State 狀態
Event 事件
state_machine.hpp
Class template state_machine
asynchronous_state_machine.hpp
Class template asynchronous_state_machine
event_processor.hpp
Class template event_processor
fifo_scheduler.hpp
Class template fifo_scheduler
exception_translator.hpp
Class template exception_translator
null_exception_translator.hpp
Class null_exception_translator
 
simple_state.hpp
Enum history_mode
Class template simple_state
state.hpp
Class template state
shallow_history.hpp
Class template shallow_history
deep_history.hpp
Class template deep_history
 
event_base.hpp
Class event_base
event.hpp
Class template event
 
transition.hpp
Class template transition
in_state_reaction.hpp
Class template in_state_reaction
termination.hpp
Class template termination
deferral.hpp
Class template deferral
custom_reaction.hpp
Class template custom_reaction
result.hpp
Class result

Concepts 概念

Scheduler concept 調度器概念

A Scheduler type defines the following:
調度器類型定義以下內容:

For a Scheduler type S and an object cpc of type const S::processor_context the following expressions must be well-formed and have the indicated results:
對於一個調度器類型 S 以及 const S::processor_context 類型的一個對像 cpc, 以下表達式必須是有效的,並且有所示結果:

Expression 表達式 Type 類型 Result 結果
cpc.my_scheduler() S & A reference to the scheduler
引向調度器的一個引用
cpc.my_handle() S::processor_handle The handle identifying the event_processor<> subtype object
標識 event_processor<> 子類型對象的句柄

To protect against abuse, all members of S::processor_context should be declared private. As a result, event_processor<> must be a friend of S::processor_context.
為預防濫用,S::processor_context 的所有成員均被聲明為私有。因此,event_processor<> 必須是 S::processor_context 的友元。

FifoWorker concept 先入先出工作者概念

A FifoWorker type defines the following:
先入先出工作者的類型定義了以下內容:

For a FifoWorker type F, an object f of that type, a const object cf of that type, a parameterless function object w of arbitrary type and an unsigned long value n the following expressions/statements must be well-formed and have the indicated results:
對於一個先入先出工作者類型 F, 該類型的一個對像 f, 該類型的一個 const 對像 cf, 一個任意類型的無參函數對像 w 以及一個 unsigned longn,以下表達式/語句必須有效,並且具有所示結果:

Expression/Statement 表達式/語句 Type 類型 Effects/Result 作用/結果
F::work_item boost::function0<
  void >
 
F() or F( false ) F Constructs a non-blocking (see below) object of the FifoWorker type. In single-threaded builds the second expression is not well-formed
構造先入先出工作者類型的一個非阻塞(見 後)對象。在單線程構建中,第二個表達式是無效的
F( true ) F Constructs a blocking (see below) object of the FifoWorker type. Not well-formed in single-threaded builds
構造先入先出工作者類型的一個阻塞(見 後)對象。在單線程構建中該表達式無效
f.queue_work_item( w );   Constructs and queues an object of type F::work_item, passing w as the only argument
構造 F::work_item 類型的一個對象並排隊,以 w 作為唯一的參數
f.terminate();   Creates and queues an object of type F::work_item that, when later executed in operator()(), leads to a modification of internal state so that terminated() henceforth returns true
創建
F::work_item 類型的一個對象並排隊,稍後在 operator()() 中執行時,引起內部狀態的改變,使得 terminated() 返回 true
cf.terminated(); bool true if terminate() has been called and the resulting work item has been executed in operator()(). Returns false otherwise
如果 terminate() 已被調用且得到的工作項已在 operator()() 中執行,則返回 true。否則返回false

Must only be called from the thread that also calls operator()()
必須從調用 operator()() 的線程進行調用
f( n ); unsigned long Enters a loop that, with each cycle, dequeues and calls operator()() on the oldest work item in the queue.
進入一個循環,在該循環的每個週期中,將工作項從隊列中取出並以之調用 operator()().

The loop is left and the number of executed work items returned if one or more of the following conditions are met:
如果遇到以下條件中的一個或多個,循環停止並返回已執行的工作項數量:

  • f.terminated() == true
  • The application is single-threaded and the internal queue is empty
    應用程序為單線程且內部隊列為空
  • The application is multi-threaded and the internal queue is empty and the worker was created as non-blocking
    應用程序為多線程且內部隊列為空且工作者是以非阻塞方式創建
  • n != 0 and the number of work items that have been processed since operator()() was called equals n
    n != 0 且從 operator()() 被調用以來已處理的工作項數量等於 n

If the queue is empty and none of the above conditions are met then the thread calling operator()() is put into a wait state until f.queue_work_item() is called from another thread.
如果隊列為空且以上條件都不滿足,則調用 operator()() 的線程將進入等待狀態,直至從另一個線程調用 f.queue_work_item() 為止。

Must only be called from exactly one thread
必須只從一個線程進行調用

f(); unsigned long Has exactly the same semantics as f( n ); with n == 0 (see above)
f( n ); 其中 n == 0 (見上)具有完全相同的語義

ExceptionTranslator concept 異常轉換器概念

An ExceptionTranslator type defines how C++ exceptions occurring during state machine operation are translated to exception events.
異常轉換器類型定義了在狀態機操作期間發生的C++異常如何被轉換為異常事件。

For an ExceptionTranslator object et, a parameterless function object a of arbitrary type returning result and a function object eh of arbitrary type taking a const event_base & parameter and returning result the following expression must be well-formed and have the indicated results:
對於一個異常轉換器對像 et, 一個返回 result 的任意類型的無參函數對像 a 以及一個接受 const event_base & 參數並返回 result 的任意類型的函數對像 eh,以下表達式必須是有效的,並且具有所示的結果:

Expression 表達式 Type 類型 Effects/Result 作用/結果
et( a, eh ); result
  1. Attempts to execute return a();
    嘗試執行 return a();
  2. If a() propagates an exception, the exception is caught
    如果 a() 拋出一個異常,則捕獲該異常
  3. Inside the catch block calls eh, passing a suitable stack-allocated model of the Event concept
    在 catch 塊中調用 eh, 傳入一個適當的、在棧上分配的、符合 事件 概念的對象
  4. Returns the result returned by eh
    返回 eh 返回的結果

StateBase concept 狀態基概念

A StateBase type is the common base of all states of a given state machine type. state_machine<>::state_base_type is a model of the StateBase concept.
狀態基類型是一個給定的狀態機類型的所有狀態的公共基類。state_machine<>::state_base_type 符合 StateBase 概念。

For a StateBase type S and a const object cs of that type the following expressions must be well-formed and have the indicated results:
對於一個狀態基類型 S 以及該類型的一個 const 對像 cs,以下表達式必須是有效的,並且具有所示的結果:

Expression 表達式 Type 類型 Result 結果
cs.outer_state_ptr() const S * 0 if cs is an outermost state, a pointer to the direct outer state of cs otherwise
為 0
如果 cs最外層狀態, 否則為指向 cs 的直接外層狀態的指針
cs.dynamic_type() S::id_type A value unambiguously identifying the most-derived type of cs. S::id_type values are comparable with operator==() and operator!=(). An unspecified collating order can be established with std::less< S::id_type >. In contrast to typeid( cs ), this function is available even on platforms that do not support C++ RTTI (or have been configured to not support it)
一個明確標識 cs 的最底層類型的值。S::id_type 的值可以用 operator==()operator!=() 來比較。未指定的比較順序可以由 std::less< S::id_type > 制定。與 typeid( cs ) 相比,這個函數在不支持 C++ RTTI (或被配置為不支持它)的平台上也可以使用
cs.custom_dynamic_type_ptr<
  Type >()
const Type * A pointer to the custom type identifier or 0. If != 0, Type must match the type of the previously set pointer. This function is only available if BOOST_STATECHART_USE_NATIVE_RTTI is not defined
一個指向定制的類型標識符的指針或為 0. 如果 != 0, 則 Type 必須與之前設置的指針類型匹配。該函數只有在 BOOST_STATECHART_USE_NATIVE_RTTI 未定義時有效

SimpleState concept 簡單狀態概念

A SimpleState type defines one state of a particular state machine.
簡單狀態類型定義了特定狀態機的一個狀態。

For a SimpleState type S and a pointer pS pointing to an object of type S allocated with new the following expressions/statements must be well-formed and have the indicated effects/results:
對於一個簡單狀態類型 S 以及指向一個用 new 分配的 S 類型對象的一個指針 pS,以 下表達式必須有效,並且具有所示的作用/結果:

Expression/Statement 表達式/語句 Type 類型 Effects/Result/Notes 作用/結果/說明
simple_state<
  S, C, I, h > * pB =
    pS;
  simple_state< S, C, I, h > must be an unambiguous public base of S. See simple_state<> documentation for the requirements and semantics of C, I and h
simple_state< S, C, I, h > 必須是 S 的一個明確的公有基類。有關 C, Ih 的要求和語義請見 simple_state<> 的文檔
new S() S * Enters the state S. Certain functions must not be called from S::S(), see simple_state<> documentation for more information
進入狀態 S. 某些函數必須不能由 S::S() 調用,更多信息請見 simple_state<> 的文檔
pS->exit();   Exits the state S (first stage). The definition of an member function within models of the SimpleState concept is optional since simple_state<> already defines the following public member: void exit() {}. exit() is not called when a state is exited while an exception is pending, see simple_state<>::terminate() for more information
退出狀態 S (第一階段)。符合簡單狀態概念的類型的 exit 成員函數是可選定義的,因為 simple_state<> 已經定義了以下公有成員:void exit() {}. 當一個狀態已退出而有一個異常未決時,exit() 不會被調用,更多信息請見 simple_state<>::terminate()
delete pS;   Exits the state S (second stage)
退出狀態 S (第二階段)
S::reactions An mpl::list<> that is either empty or contains instantiations of the custom_reaction, in_state_reaction, deferral, termination or transition class templates. If there is only a single reaction then it can also be typedefed directly, without wrapping it into an mpl::list<>
一個 mpl::list<>, 要麼為空,要麼包含 custom_reaction, in_state_reaction, deferral, terminationtransition 類模板的實例。如果只有一個反應,則它也可以直接被 typedef,而無需用 mpl::list<> 來包裝
The declaration of a reactions member typedef within models of the SimpleState concept is optional since simple_state<> already defines the following public member: typedef mpl::list<> reactions;
對符合簡單狀態的概念聲明一個 reactions 成員 typedef,這是可選的,因為 simple_state<> 已經定義了以下公有成員:typedef mpl::list<> reactions;

State concept 狀態概念

A State is a refinement of SimpleState (that is, except for the default constructor a State type must also satisfy SimpleState requirements). For a State type S, a pointer pS of type S * pointing to an object of type S allocated with new, and an object mc of type state< S, C, I, h >::my_context the following expressions/statements must be well-formed:
狀態是 簡單狀態 的精化(除了缺省構造函數以外,狀態類型必須滿足簡單狀態的所有要求)。對於一個狀態類型 S,& nbsp;指向一個由 new 分配的 S 類型對象的類型為 S * 的一個指針 pS, 以及 state< S, C, I, h >::my_context 類型的一個對像 mc,以下表達式/語句必須有效:

Expression/Statement 表達式/語句 Type 類型 Effects/Result/Notes 作用/結果/說明
state< S, C, I, h > *
  pB = pS;
  state< S, C, I, h > must be an unambiguous public base of S. See state<> documentation for the requirements and semantics of C, I and h
state< S, C, I, h > 必須是 S 的一個明確的公有基類。有關 C, Ih 的要求和語義請見 state<> 的文檔
new S( mc ) S * Enters the state S. No restrictions exist regarding the functions that can be called from S::S() (in contrast to the constructors of models of the SimpleState concept). mc must be forwarded to state< S, C, I, h >::state()
進入狀態 S. 對於可以在 S::S() 中調用的函數沒有限制(與簡單狀態概念的構造函數不同)。mc 必須被前轉至 state< S, C, I, h >::state()

Event concept 事件概念

A Event type defines an event for which state machines can define reactions.
事件類型定義了一個事件,狀態機可以為之定義反應。

For a Event type E and a pointer pCE of type const E * pointing to an object of type E allocated with new the following expressions/statements must be well-formed and have the indicated effects/results:
對於一個事件類型 E 以及指向一個由 new 分配的 E 類型對象的類型為 const E * 的一個指針 pCE,以下表達式/語句必須有效,並且具有所示的作用/結果:

Expression/Statement 表達式/語句 Type 類型 Effects/Result/Notes 作用/結果/說明
const event< E > * pCB = pCE;   event< E > must be an unambiguous public base of E
event< E > 必須是 E 的一個明確的公有基類
new E( *pCE ) E * Makes a copy of pE
構造 pE 的一個拷貝

Header <boost/statechart/state_machine.hpp>

Class template state_machine 類 模板 state_machine

This is the base class template of all synchronous state machines.
這是所有同步狀態機的基類模板。

Class template state_machine parameters 類模板 state_machine 的參數

Template parameter 模板參數 Requirements 要求 Semantics 語義 Default 缺省值
MostDerived The most-derived subtype of this class template
該類模板的最底層子類型
   
InitialState A model of the SimpleState or State concepts. The Context argument passed to the simple_state<> or state<> base of  InitialState must be MostDerived. That is, InitialState must be an outermost state of this state machine
符合 簡單狀態狀態 概念的類型。傳給  InitialStatesimple_state<> or state<> 基類的 Context 參數必須為 MostDerived. 即,InitialState 必須是該狀態機的一個 最外層狀態
The state that is entered when state_machine<>
::initiate()
is called
調用 state_machine<>
::initiate()
時進入的狀態
 
Allocator A model of the standard Allocator concept
符合標準分配器概念的類型
Allocator::rebind<>::other is used to allocate and deallocate all simple_state subtype objects and internal objects of dynamic storage duration
Allocator::rebind<>::other 被用於所有 simple_state 子類型對像以及動態存儲過程中的內部對象的分配和釋放
std::allocator< void >
ExceptionTranslator A model of the ExceptionTranslator concept
符合異常轉換器概念的類型
see ExceptionTranslator concept
請見 異常轉換器 概念
null_exception_translator

Class template state_machine synopsis 類模板 state_machine 摘要

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 initiate();
void terminate();
bool terminated() const;

void process_event( const event_base & );

template< class Target >
Target state_cast() const;
template< class Target >
Target state_downcast() const;

// a model of the StateBase concept
// 符合 狀態基 的概念
typedef implementation-defined state_base_type;
// a model of the standard Forward Iterator concept
// 符合標準的前向迭代器的概念
typedef implementation-defined state_iterator;

state_iterator state_begin() const;
state_iterator state_end() const;

void unconsumed_event( const event_base & ) {}

protected:
state_machine();
~state_machine();

void post_event(
const intrusive_ptr< const event_base > & );
void post_event( const event_base & );
};
}
}

Class template state_machine constructor and destructor 類模板 state_machine 的構造函數和析構函數

state_machine();

Effects: Constructs a non-running state machine
作用:構造一個未運行的狀態機

~state_machine();

Effects: 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
作用:析構當前活動的最外層狀態以及它的所有直接和間接內層狀態。最內層狀態首先被析構。其它狀態在其所有直接和 間接狀態被析構後立即析構。每個狀態的內層狀態按照它們的正交區域號碼順序來析構。具有最大號碼的正交區域中的狀態首先析構,然後析構次大號碼區域中的狀 態,依次類推

Note: Does not attempt to call any exit member functions
注意:不要試圖調用任何 exit 成員函數

Class template state_machine modifier functions 類模板 state_machine 的可寫函數

void initiate();

Effects:
作用:

  1. Calls terminate()
    調用 terminate()
  2. Constructs a function object action with a parameter-less operator()() returning result that
    構造一個函數對像 action,帶有一個返回 result 的無參 operator()() 滿足
    1. enters (constructs) the state specified with the InitialState template parameter
      進入(構造)由 InitialState 模板參數指定的狀態
    2. enters the tree formed by the direct and indirect inner initial states of InitialState 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
      進入以深度優先方式形成的 InitialState 的直接及間接初始狀態樹。每個狀態的內層狀態根據其正交區域號碼順序進入。正交區域0中的狀態首先被進入,然後是區域1,等等
  3. Constructs a function object exceptionEventHandler with an operator()() returning result and accepting an exception event parameter that processes the passed exception event, with the following differences to the processing of normal events:
    構造一個函數對像 exceptionEventHandler,帶 有一個返回 result 且接受一個異常事件參數的 operator()(), 它處理傳入的異常事件,與普通事件的處理有以下區別:
  4. Passes action and exceptionEventHandler to ExceptionTranslator::operator()(). If ExceptionTranslator::operator()() 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)
    actionexceptionEventHandler 傳給 ExceptionTranslator::operator()(). 如果 ExceptionTranslator::operator()() 拋出一個異常,則該異常被傳播給調用者。如果調用者捕獲了該異常,則當前活動的最外層狀態及其所有直接和間接內層狀態被析構。最內層狀態首先被析構。其它 狀態在其所有直接和間接內層狀態被析構後立即析構。每個狀態的內層狀態根據其正交區域號碼的順序進行析構。最大號碼的正交區域中的狀態首先被析構,然後是 次大號碼的區域中的狀態,依次類推。否則繼續第5步(返回值被忽略)
  5. Processes all posted events (see process_event()). Returns to the caller if there are no more posted events
    處理所有被發送的事件(請見 process_event())。 如果沒有其它事件,則返回至調用者

Throws: Any exceptions propagated from ExceptionTranslator::operator()(). Exceptions never originate in the library itself but only in code supplied through template parameters:
拋出:
ExceptionTranslator::operator()() 傳出的任意異常。庫本身不會引起異常,除了由模板參數所提供的代碼以外:

void terminate();

Effects:
作用:

  1. Constructs a function object action with a parameter-less operator()() returning result that terminates the currently active outermost state, discards all remaining events and clears all history information
    構造一個函數對像 action, 帶一個無參的 operator()(),返回 result終止當前活 動的最外層狀態,忽略所有剩餘的事件並清除所有歷史信息
  2. Constructs a function object exceptionEventHandler with an operator()() returning result and accepting an exception event parameter that processes the passed exception event, with the following differences to the processing of normal events:
    構造一個函數對像 exceptionEventHandler,帶 一個 operator()(),返回 result 且接受一個異常事件參數,它處理傳入的異常事件,與普通的事件處理有以下區別:
  3. Passes action and exceptionEventHandler to ExceptionTranslator::operator()(). If ExceptionTranslator::operator()() 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
    actionexceptionEventHandler 傳給 ExceptionTranslator::operator()(). 如果 ExceptionTranslator::operator()() 拋出一個異常,則該異常被傳播給調用者。如果調用者捕獲了該異常,則當前活動的最外層狀態及其所有直接和間接內層狀態被析構。最內層狀態首先被析構。其它 狀態在其所有直接和間接內層狀態被析構後立即析構。每個狀態的內層狀態根據其正交區域號碼的順序進行析構。最大號碼的正交區域中的狀態首先被析構,然後是 次大號碼的區域中的狀態,依次類推。否則返回到調用者

Throws: Any exceptions propagated from ExceptionTranslator::operator(). Exceptions never originate in the library itself but only in code supplied through template parameters:
拋出:
ExceptionTranslator::operator()() 傳出的任意異常。庫本身不會引起異常,除了由模板參數所提供的代碼以外:

void process_event( const event_base & );

Effects:
作用:

  1. Selects the passed event as the current event (henceforth referred to as currentEvent)
    將傳入的事件選定為當前事件(自此被 currentEvent 所引向)
  2. Starts a new reaction search
    開始一個新的反應查 找
  3. Selects an arbitrary but in this reaction search not yet visited state from all the currently active innermost states. If no such state exists then continues with step 10
    從所有當前活動的 最內層狀態 中選擇任意一個本次反應查找未訪問過的狀態。如果不存在這樣的狀態,則跳至第10步
  4. Constructs a function object action with a parameter-less operator()() returning result that does the following:
    構造一個函數對像 action, 帶一個無參的 operator()(),返回 result, 做 以下事情:
    1. Searches a reaction suitable for currentEvent, starting with the current innermost state and moving outward until a state defining a reaction for the event is found. Returns simple_state<>::forward_event() if no reaction has been found
      查找一個適用於 currentEvent 的反應,從當前最內層狀態開始向外層移動,直至找到一個對該事件定義了反應的狀態。如果找不到反應則返回 simple_state<>::forward_event()
    2. Executes the found reaction. If the reaction result is equal to the return value of simple_state<>::forward_event() then resumes the reaction search (step a). Returns the reaction result otherwise
      執行找到的反應。如果反應的執行結果等於 simple_state<>::forward_event() 的返回值,則重新開始反應查找(步驟a)。否則返回反應結果
  5. Constructs a function object exceptionEventHandler returning result and accepting an exception event parameter that processes the passed exception event, with the following differences to the processing of normal events:
    構造一個函數對像 exceptionEventHandler,返回 result 且接受一個異常事件參數,它處理傳入的異常事件,與普通的事件處理有以下區別:
  6. Passes action and exceptionEventHandler to ExceptionTranslator::operator()(). If ExceptionTranslator::operator()() 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 continues with step 7
    actionexceptionEventHandler 傳給 ExceptionTranslator::operator()(). 如果 ExceptionTranslator::operator()() 拋出一個異常,則該異常被傳播給調用者。如果調用者捕獲了該異常,則當前活動的最外層狀態及其所有直接和間接內層狀態被析構。最內層狀態首先被析構。其它 狀態在其所有直接和間接內層狀態被析構後立即析構。每個狀態的內層狀態根據其正交區域號碼的順序進行析構。最大號碼的正交區域中的狀態首先被析構,然後是 次大號碼的區域中的狀態,依次類推。否則繼續第7步
  7. If the return value of ExceptionTranslator::operator()() is equal to the one of simple_state<>::forward_event() then continues with step 3
    如果 ExceptionTranslator::operator()() 的返回值等於 simple_state<>::forward_event() 之一,就繼續步驟3
  8. If the return value of ExceptionTranslator::operator()() is equal to the one of simple_state<>::defer_event() then the return value of currentEvent.intrusive_from_this() is stored in a state-specific queue. Continues with step 11
    如果 ExceptionTranslator::operator()() 的返回值等於 simple_state<>::defer_event() 之一,則將 currentEvent.intrusive_from_this() 的返回值保存在一個狀態相關的隊列中。繼續步驟11
  9. If the return value of ExceptionTranslator::operator()() is equal to the one of simple_state<>::discard_event() then continues with step 11
    如果 ExceptionTranslator::operator()() 的返回值等於 simple_state<>::discard_event() 之一,則繼續步驟11
  10. Calls static_cast< MostDerived * >( this )->unconsumed_event( currentEvent ). If unconsumed_event() throws an exception, the exception is propagated to the caller. Such an exception never leads to the destruction of any states (in contrast to exceptions propagated from ExceptionTranslator::operator()())
    調 用 static_cast< MostDerived * >( this )->unconsumed_event( currentEvent ). 如果 unconsumed_event() 拋出異常,則該異常被傳播到調用者。這種異常不會導致任何狀態的析構(與由 ExceptionTranslator::operator()() 傳出的異常相比較而言)
  11. If the posted events queue is non-empty then dequeues the first event, selects it as currentEvent and continues with step 2. Returns to the caller otherwise
    如果事件隊列非空,則將第一個事件出 列,將它選為 currentEvent 並繼續步驟2。否則返回到調用者

Throws: Any exceptions propagated from MostDerived::unconsumed_event() or ExceptionTranslator::operator(). Exceptions never originate in the library itself but only in code supplied through template parameters:
拋出:
MostDerived::unconsumed_event()ExceptionTranslator::operator()() 傳出的任意異常。庫本身不會引起異常,除了由模板參數所提供的代碼以外:

void post_event(
const intrusive_ptr< const event_base > & );

Effects: Pushes the passed event into the posted events queue
作用:
將傳入的事件壓入事件隊列
Throws: Any exceptions propagated from Allocator::allocate()
拋出:Allocator::allocate() 傳出的任意異常

void post_event( const event_base & evt );

Effects: post_event( evt.intrusive_from_this() );
作用:
post_event( evt.intrusive_from_this() );
Throws: Any exceptions propagated from Allocator::allocate()
拋出:Allocator::allocate() 傳出的任意異常

void unconsumed_event( const event_base & evt );

Effects: None
作用:
Note: This function (or, if present, the equally named derived class member function) is called by process_event() whenever a dispatched event did not trigger a reaction, see process_event() effects, point 10 for more information.
注意:該函數(或派生類的同名成員函數,如果有的話)由 process_event() 在一個被分派事件沒有觸發反應時調用,更多信息請見 process_event() 作用的第10點。

Class template state_machine observer functions 類模板 state_machine observer 的函數

bool terminated() const;

Returns: true, if the machine is terminated. Returns false otherwise
返回:true, 如果狀態機已被終止。否則返回 false 
Note: Is equivalent to state_begin() == state_end()
說明:等價於 state_begin() == state_end()

template< class Target >
Target state_cast() const;

Returns: Depending on the form of Target either a reference or a pointer to const if at least one of the currently active states can successfully be dynamic_cast to Target. Returns 0 for pointer targets and throws std::bad_cast for reference targets otherwise. Target can take either of the following forms: const Class * or const Class &
返回:根據 Target 的形式,如果至少有一個當前活動的狀態可以成功地 dynamic_castTarget 則返回相應的 const 引用或 const 指針。否則,對於指針類型返回 0,而對於引用類型則拋出 std::bad_cast. Target 可以是以下形式:const Class *const Class &
Throws: std::bad_cast if Target is a reference type and none of the active states can be dynamic_cast to Target
拋出:
std::bad_cast 如果 Target 是引用類型且沒有一個活動狀態可以 dynamic_cast 為 Target
說明:查找的順序與 process_event() 相同

template< class Target >
Target state_downcast() const;

Requires: For reference targets the compiler must support partial specialization of class templates, otherwise a compile-time error will result. The type denoted by Target must be a model of the SimpleState or State concepts
要求:
對於引用類型的目標,編譯器必須支持類模板偏特化,否則會導致編譯期錯誤。Target 所代表的類型必須符合 簡單狀態狀態 概念
Returns: Depending on the form of Target either a reference or a pointer to const if Target is equal to the most-derived type of a currently active state. Returns 0 for pointer targets and throws std::bad_cast for reference targets otherwise. Target can take either of the following forms: const Class * or const Class &
返回:根據 Target 的形式,如果 Target 等於當前活動狀態的最底層類型,則返回相應的 const 引用或 const 指針。否則,對於指針類型返回 0,而對於引用類型則拋出 std::bad_cast. Target 可以是以下形式:const Class *const Class &
Throws: std::bad_cast if Target is a reference type and none of the active states has a most derived type equal to Target
拋出:
std::bad_cast 如果 Target 為引用類型且沒有一個活動狀態的最底層類型與 Target 相同
Note: The search sequence is the same as for process_event()
說明:查找的順序與 process_event() 相同

state_iterator state_begin() const;
state_iterator state_end() const;

Return: Iterator objects, the range [state_begin(), state_end()) refers to all currently active innermost states. For an object i of type state_iterator, *i returns a const state_base_type & and i.operator->() returns a const state_base_type *
返回:迭代器對象,區間 [state_begin(), state_end()) 引向所有當前活動的 最內層狀態。對於 state_iterator 類型的對象 i, *i 返回一個 const state_base_type &i.operator->() 返回一個 const state_base_type *
Note: The position of a given innermost state in the range is arbitrary. It may change with each call to a modifier function. Moreover, all iterators are invalidated whenever a modifier function is called
說明:給定的某個最內層狀態在該區間中的位置是任意的。該位置在每次調用可變函數時可能會改變。此外,在可變函數 被調用後,所有迭代器都會變為無效

Header <boost/statechart/
asynchronous_state_machine.hpp>

Class template asynchronous_state_machine 類模板 asynchronous_state_machine

This is the base class template of all asynchronous state machines.
這是所有異步狀態機的基類模板。

Class template asynchronous_state_machine parameters 類模板 asynchronous_state_machine 的參數

Template parameter 模板參數 Requirements 要求 Semantics 語義 Default 缺省值
MostDerived The most-derived subtype of this class template
該類模板的最底層子類型
   
InitialState A model of the SimpleState or State concepts. The Context argument passed to the simple_state<> or state<> base of InitialState must be MostDerived. That is, InitialState must be an outermost state of this state machine
符合 簡單狀態狀態 概念的類型。InitialStatesimple_state<>state<> 基類的 Context 參數必須為 MostDerived. 即,InitialState 必須是該狀態機的一個 最外層狀態
The state that is entered when the state machine is initiated through the Scheduler object
當狀態機被 Scheduler 對像初始化時進入的狀態
 
Scheduler A model of the Scheduler concept
符合調度器概念的類型
請見 調 度器 概念 fifo_scheduler<>
Allocator A model of the standard Allocator concept
符合標準分配器概念的類型
  std::allocator< void >
ExceptionTranslator A model of the ExceptionTranslator concept
符合異常轉換器概念的類型
see ExceptionTranslator concept
請見 異常轉換器 概念
null_exception_translator

Class template asynchronous_state_machine synopsis 類模板 asynchronous_state_machine 的摘要

namespace boost
{
namespace statechart
{
template<
class MostDerived,
class InitialState,
class Scheduler = fifo_scheduler<>,
class Allocator = std::allocator< void >,
class ExceptionTranslator = null_exception_translator >
class asynchronous_state_machine :
public state_machine<
MostDerived, InitialState, Allocator, ExceptionTranslator >,
public event_processor< Scheduler >
{
protected:
typedef asynchronous_state_machine my_base;

asynchronous_state_machine(
typename event_processor< Scheduler >::my_context ctx );
~asynchronous_state_machine();
};
}
}

Class template asynchronous_state_machine constructor and destructor 類模板 asynchronous_state_machine 的構造函數和析構函數

asynchronous_state_machine(
typename event_processor< Scheduler >::my_context ctx );

Effects: Constructs a non-running asynchronous state machine
作用:構造一個未運行的異步狀態機
Note: Users cannot create asynchronous_state_machine<> subtype objects directly. This can only be done through an object of the Scheduler class
說明:用戶不能直接創建 asynchronous_state_machine<> 子類型對象。只能通過 Scheduler 類的對象來完成這一工作

~asynchronous_state_machine();

Effects: Destructs the state machine
作用:析構一個狀態機
Note: Users cannot destruct asynchronous_state_machine<> subtype objects directly. This can only be done through an object of the Scheduler class
說明:用戶不能直接析構 asynchronous_state_machine<> 子類型對象。只能通過 Scheduler 類的對象來完成這一工作

Header <boost/statechart/event_processor.hpp>

Class template event_processor 類模板 event_processor

This is the base class template of all types that process events. asynchronous_state_machine<> is just one possible event processor implementation.
這是所有處理事件的類型的基類模板。asynchronous_state_machine<> 只是一個可能的事件處理器實現。

Class template event_processor parameters 類模板 event_processor 的參數

Template parameter 模板參數 Requirements 要求 Semantics 語義 Default 缺省值
Scheduler A model of the Scheduler concept
符合調度器概念的類型
see Scheduler concept
請見 Scheduler 概念
 

Class template event_processor synopsis 類模板 event_processor 的摘要

namespace boost
{
namespace statechart
{
template< class Scheduler >
class event_processor
{
public:
virtual ~event_processor();

Scheduler & my_scheduler() const;

typedef typename Scheduler::processor_handle
processor_handle;
processor_handle my_handle() const;

void initiate();
void process_event( const event_base & evt );
void terminate();

protected:
typedef const typename Scheduler::processor_context &
my_context;
event_processor( my_context ctx );

private:
virtual void initiate_impl() = 0;
virtual void process_event_impl(
const event_base & evt ) = 0;
virtual void terminate_impl() = 0;
};
}
}

Class template event_processor constructor and destructor 類模板 event_processor 的構造函數和析構函數

event_processor( my_context ctx );

Effects: Constructs an event processor object and stores copies of the reference returned by myContext.my_scheduler() and the object returned by myContext.my_handle()
作用:
構造一個事件處理器對象,並保存由 myContext.my_scheduler() 返回的引用和由 myContext.my_handle() 返回的對象的拷貝
Note: Users cannot create event_processor<> subtype objects directly. This can only be done through an object of the Scheduler class
說明:用戶不能直接創建 event_processor<> 子類型的對象。只能通過 Scheduler 類的對象來完成這一工作

virtual ~event_processor();

Effects: Destructs an event processor object
作用:析構一個事件處理器對像
Note: Users cannot destruct event_processor<> subtype objects directly. This can only be done through an object of the Scheduler class
說明:用戶不能直接析構 event_processor<> 子類型的對象。只能通過 Scheduler 類的對象來完成這一工作

Class template event_processor modifier functions 類模板 event_processor 的可變函數

void initiate();

Effects: initiate_impl();
作用:initiate_impl();
Throws: Any exceptions propagated from the implementation of initiate_impl()
拋出:initiate_impl() 的實現所傳出的任意異常

void process_event( const event_base & evt );

Effects: process_event_impl( evt );
作用:process_event_impl( evt );
Throws: Any exceptions propagated from the implementation of process_event_impl()
拋出:process_event_impl() 的實現所傳出的任意異常

void terminate();

Effects: terminate_impl();
作用:terminate_impl();
Throws: Any exceptions propagated from the implementation of terminate_impl()
拋出:terminate_impl() 的實現所傳出的任意異常

Class template event_processor observer functions 類模板 event_processor 的常性函數

Scheduler & my_scheduler() const;

Returns: The Scheduler reference obtained in the constructor
返回:由構造函數獲得的 Scheduler 引用

processor_handle my_handle() const;

Returns: The processor_handle object obtained in the constructor
返回:
由構造函數獲得的 processor_handle 對像

Header <boost/statechart/fifo_scheduler.hpp>

Class template fifo_scheduler 類模板 fifo_scheduler

This class template is a model of the Scheduler concept.
該類模板符合 調度器 概念。

Class template fifo_scheduler parameters 類模板 fifo_scheduler 的參數

Template parameter 模板參數 Requirements 要求 Semantics 語義 Default 缺省值
FifoWorker A model of the FifoWorker concept
符合先入先出工作者概念的類型
see FifoWorker concept
請見 先入先出工作者 概念
fifo_worker<>
Allocator A model of the standard Allocator concept
符合標準的分配器概念的類型
  std::allocator< void >

Class template fifo_scheduler synopsis 類模板 fifo_scheduler 的摘要

namespace boost
{
namespace statechart
{
template<
class FifoWorker = fifo_worker<>,
class Allocator = std::allocator< void > >
class fifo_scheduler : noncopyable
{
public:
fifo_scheduler( bool waitOnEmptyQueue = false );

typedef implementation-defined processor_handle;

class processor_context : noncopyable
{
processor_context(
fifo_scheduler & scheduler,
const processor_handle & theHandle );

fifo_scheduler & my_scheduler() const;
const processor_handle & my_handle() const;

friend class fifo_scheduler;
friend class event_processor< fifo_scheduler >;
};

template< class Processor >
processor_handle create_processor();
template< class Processor, typename Param1 >
processor_handle create_processor( Param1 param1 );

// More create_processor overloads 更多 create_processor 重載

void destroy_processor( processor_handle processor );

void initiate_processor( processor_handle processor );
void terminate_processor( processor_handle processor );

typedef intrusive_ptr< const event_base > event_ptr_type;

void queue_event(
const processor_handle & processor,
const event_ptr_type & pEvent );

typedef typename FifoWorker::work_item work_item;

void queue_work_item( const work_item & item );

void terminate();
bool terminated() const;

unsigned long operator()(
unsigned long maxEventCount = 0 );
};
}
}

Class template fifo_scheduler constructor 類模板 fifo_scheduler 的構造函數

fifo_scheduler( bool waitOnEmptyQueue = false );

Effects: Constructs a fifo_scheduler<> object. In multi-threaded builds, waitOnEmptyQueue is forwarded to the constructor of a data member of type FifoWorker. In single-threaded builds, the FifoWorker data member is default-constructed
作用:構造一個 fifo_scheduler<> 對象。在多線程構建中,waitOnEmptyQueue 被前轉至一個類型為 FifoWorker 的數據成員的構造函數。在單線程構建中,FifoWorker 數據成員是缺省構造的
Note: In single-threaded builds the fifo_scheduler<> constructor does not accept any parameters and operator()() thus always returns to the caller when the event queue is empty
說明:
在單線程構造中,fifo_scheduler<> 構造函數不接受任何參數,所以當事件隊列為空時,operator()() 總是返回至調用者

Class template fifo_scheduler modifier functions 類模板 fifo_scheduler 的可變函數

template< class Processor >
processor_handle create_processor();

Requires: The Processor type must be a direct or indirect subtype of the event_processor class template
要求:
類型 Processor 必須是 event_processor 類模板的直接或間接子類
Effects: Creates and passes to FifoWorker::queue_work_item() an object of type FifoWorker::work_item that, when later executed in FifoWorker::operator()(), leads to a call to the constructor of Processor, passing an appropriate processor_context object as the only argument
作用:創建一個 FifoWorker::work_item 類型的對象並傳遞給 FifoWorker::queue_work_item(),稍後執行 FifoWorker::operator()() 時,調用 Processor 的構造函數,傳入一個適當的 processor_context 對像作為唯一的參數
Returns: A processor_handle object that henceforth identifies the created event processor object
返回:一個 processor_handle 對象,用於標識被創建的事件處理器對像
Throws: Any exceptions propagated from FifoWorker::work_item() and FifoWorker::queue_work_item()
拋出:FifoWorker::work_item()FifoWorker::queue_work_item() 傳出的任意異常
Caution: The current implementation of this function makes an (indirect) call to global operator new(). Unless global operator new() is replaced, care must be taken when to call this function in applications with hard real-time requirements
警告:該函數的當前實現會(間接)調用全局的 operator new(). 除非全局 operator new() 被替換,否則在對實時性在嚴格要求的應用程序中必須小心調用該函數

template< class Processor, typename Param1 >
processor_handle create_processor( Param1 param1 );

Requires: The Processor type must be a direct or indirect subtype of the event_processor class template
要求:類型 Processor 必須是 event_processor 類模板的直接或間接子類
Effects: Creates and passes to FifoWorker::queue_work_item() an object of type FifoWorker::work_item that, when later executed in FifoWorker::operator()(), leads to a call to the constructor of Processor, passing an appropriate processor_context object and param1 as arguments
作用:創建一個 FifoWorker::work_item 類型的對象並傳遞給 FifoWorker::queue_work_item(),稍後執行 FifoWorker::operator()() 時,調用 Processor 的構造函數,傳入一個適當的 processor_context 對像和 param1 作為參數
Returns
: A processor_handle object that henceforth identifies the created event processor object
返回:一個 processor_handle 對象,用於標識被創建的事件處理器對像
Throws: Any exceptions propagated from FifoWorker::work_item() and FifoWorker::queue_work_item()
拋出:FifoWorker::work_item()FifoWorker::queue_work_item() 傳出的任意異常
Note
: boost::ref() and boost::cref() can be used to pass arguments by reference rather than by copy. fifo_scheduler<> has 5 additional create_processor<> overloads, allowing to pass up to 6 custom arguments to the constructors of event processors
說明:boost::ref()boost::cref() 可用於以引用方式而不是拷貝的方式傳遞參數。fifo_scheduler<> 有5個額外的 create_processor<> 重載,允許傳遞最多6個定制的參數給事件處理器的構造函數
Caution: The current implementation of this and all other overloads make (indirect) calls to global operator new(). Unless global operator new() is replaced, care must be taken when to call these overloads in applications with hard real-time requirements
警告:該函數及所有其它重載的當前實現會(間接)調用全局的 operator new(). 除非全局 operator new() 被替換,否則在對實時性在嚴格要求的應用程序中必須小心調用該函數

void destroy_processor( processor_handle processor );

Requires: processor was obtained from a call to one of the create_processor<>() overloads on the same fifo_scheduler<> object
要求:processor 是通過調用 create_processor<>() 的一個對於同一個 fifo_scheduler<> 對象的重載而獲得的
Effects: Creates and passes to FifoWorker::queue_work_item() an object of type FifoWorker::work_item that, when later executed in FifoWorker::operator()(), leads to a call to the destructor of the event processor object associated with processor. The object is silently discarded if the event processor object has been destructed before
作用:創建一個 FifoWorker::work_item 類型的對象並傳遞給 FifoWorker::queue_work_item(),稍後執行 FifoWorker::operator()() 時,引發對與 Processor 相關聯的事件處理器對象的析構函數的調用。如果事件處理器對像在這之前已析構,則忽略該對像
Throws: Any exceptions propagated from FifoWorker::work_item() and FifoWorker::queue_work_item()
拋出:FifoWorker::work_item()FifoWorker::queue_work_item() 傳出的任意異常
Caution: The current implementation of this function leads to an (indirect) call to global operator delete() (the call is made when the last processor_handle object associated with the event processor object is destructed). Unless global operator delete() is replaced, care must be taken when to call this function in applications with hard real-time requirements
警告:該函數及所有其它重載的當前實現會(間接)調用全局的 operator delete() (在最後一個與事件處理器對像相關聯的 processor_handle 對像被析構時調用)。除非全局 operator delete() 被替換,否則在對實時性在嚴格要求的應用程序中必須小心調用該函數

void initiate_processor( processor_handle processor );

Requires: processor was obtained from a call to one of the create_processor() overloads on the same fifo_scheduler<> object
要求:processor 是通過調用 create_processor<>() 的一個對於同一個 fifo_scheduler<> 對象的重載而獲得的
Effects: Creates and passes to FifoWorker::queue_work_item() an object of type FifoWorker::work_item that, when later executed in FifoWorker::operator()(), leads to a call to initiate() on the event processor object associated with processor. The object is silently discarded if the event processor object has been destructed before
作用:創建一個 FifoWorker::work_item 類型的對象並傳遞給 FifoWorker::queue_work_item(),稍後執行 FifoWorker::operator()() 時,引發對與 processor 相關聯的事件處理器的 initiate() 的調用。如果事件處理器對像在這之前已析構,則忽略該對像
Throws: Any exceptions propagated from FifoWorker::work_item() and FifoWorker::queue_work_item()
拋出:FifoWorker::work_item()FifoWorker::queue_work_item() 傳出的任意異常

void terminate_processor( processor_handle processor );

Requires: processor was obtained from a call to one of the create_processor<>() overloads on the same fifo_scheduler<> object
要求:processor 是通過調用 create_processor<>() 的一個對於同一個 fifo_scheduler<> 對象的重載而獲得的
Effects: Creates and passes to FifoWorker::queue_work_item() an object of type FifoWorker::work_item that, when later executed in FifoWorker::operator()(), leads to a call to terminate() on the event processor object associated with processor. The object is silently discarded if the event processor object has been destructed before
作用:創建一個 FifoWorker::work_item 類型的對象並傳遞給 FifoWorker::queue_work_item(),稍後執行 FifoWorker::operator()() 時,引發對與 processor 相關聯的事件處理器的 terminate() 的調用。如果事件處理器對像在這之前已析構,則忽略該對像
Throws: Any exceptions propagated from FifoWorker::work_item() and FifoWorker::queue_work_item()
拋出:FifoWorker::work_item()FifoWorker::queue_work_item() 傳出的任意異常

void queue_event(
const processor_handle & processor,
const event_ptr_type & pEvent );

Requires: pEvent.get() != 0 and processor was obtained from a call to one of the create_processor<>() overloads on the same fifo_scheduler<> object
作用:pEvent.get() != 0processor 是通過調用 create_processor<>() 的一個對於同一個 fifo_scheduler<> 對象的重載而獲得的
Effects: Creates and passes to FifoWorker::queue_work_item() an object of type FifoWorker::work_item that, when later executed in FifoWorker::operator()(), leads to a call to process_event( *pEvent ) on the event processor object associated with processor. The object is silently discarded if the event processor object has been destructed before
作用:創建一個 FifoWorker::work_item 類型的對象並傳遞給 FifoWorker::queue_work_item(),稍後執行 FifoWorker::operator()() 時,引發對與 processor 相關聯的事件處理器的 process_event( *pEvent ) 的調用。如果事件處理器對像在這之前已析構,則忽略該對像
Throws: Any exceptions propagated from FifoWorker::work_item() and FifoWorker::queue_work_item()
拋出:FifoWorker::work_item()FifoWorker::queue_work_item() 傳出的任意異常

void queue_work_item( const work_item & item );

Effects: FifoWorker::queue_work_item( item );
作用:FifoWorker::queue_work_item( item );
Throws: Any exceptions propagated from the above call
拋出:從以上調用中傳出的任意異常

void terminate();

Effects: FifoWorker::terminate()
作用:FifoWorker::terminate()
Throws: Any exceptions propagated from the above call
拋出:從以上調用中傳出的任意異常

unsigned long operator()( unsigned long maxEventCount = 0 );

Requires: Must only be called from exactly one thread
要求:只能用單個線程中調用
Effects: FifoWorker::operator()( maxEventCount )
作用:FifoWorker::operator()( maxEventCount )
Returns: The return value of the above call
返回:以上調用的返回值
Throws: Any exceptions propagated from the above call
拋出:從以上調用中傳出的任意異常

Class template fifo_scheduler observer functions 類模板 fifo_scheduler 的常性函數

bool terminated() const;

Requires: Must only be called from the thread that also calls operator()()
要求:只能從調用 operator()() 的線程中調用
Returns: FifoWorker::terminated();
返回:FifoWorker::terminated();

Header <boost/statechart/exception_translator.hpp>

Class template exception_translator 類模板 exception_translator

This class template is a model of the ExceptionTranslator concept.
這個類模板符合 異常轉換器 概念。

Class template exception_translator parameters 類模板 exception_translator 的參數

Template parameter 模板參數 Requirements 要求 Semantics 語義 Default 缺省值
ExceptionEvent A model of the Event concept
符合 事件 概念的類型
The type of event that is dispatched when an exception is propagated into the framework
當一個異常被傳播到框架內時被分派的事件類型
exception_thrown

Class template exception_translator synopsis & semantics 類模板 exception_translator 的摘要和語義

namespace boost
{
namespace statechart
{
class exception_thrown : public event< exception_thrown > {};

template< class ExceptionEvent = exception_thrown >
class exception_translator
{
public:
template< class Action, class ExceptionEventHandler >
result operator()(
Action action,
ExceptionEventHandler eventHandler )
{
try
{
return action();
}
catch( ... )
{
return eventHandler( ExceptionEvent() );
}
}
};
}
}

Header <boost/statechart/
null_exception_translator.hpp>

Class null_exception_translator 類 null_exception_translator

This class is a model of the ExceptionTranslator concept.
這個類符合 異常轉換器 概念。

Class null_exception_translator synopsis & semantics 類 null_exception_translator 的摘要和語義

namespace boost
{
namespace statechart
{
class null_exception_translator
{
public:
template< class Action, class ExceptionEventHandler >
result operator()(
Action action, ExceptionEventHandler )
{
return action();
}
};
}
}

Header <boost/statechart/simple_state.hpp>

Enum history_mode 枚舉 history_mode

Defines the history type of a state.
定義狀態的歷史類型。

namespace boost
{
namespace statechart
{
enum history_mode
{
has_no_history,
has_shallow_history,
has_deep_history,
has_full_history // shallow & deep 淺和深
};
}
}

Class template simple_state 類模板 simple_state

This is the base class template for all models of the SimpleState concept. Such models must not call any of the following simple_state<> member functions from their constructors:
這是所有符合 簡單狀態 概念的類型的基類模板。這些類型必須不能從它們的構造函數中調用以下任意一個 simple_state<> 成員函數:

void post_event(
const intrusive_ptr< const event_base > & );
void post_event( const event_base & );

template<
class HistoryContext,
implementation-defined-unsigned-integer-type
orthogonalPosition >
void clear_shallow_history();
template<
class HistoryContext,
implementation-defined-unsigned-integer-type
orthogonalPosition >
void clear_deep_history();

outermost_context_type & outermost_context();
const outermost_context_type & outermost_context() const;

template< class OtherContext >
OtherContext & context();
template< class OtherContext >
const OtherContext & context() const;

template< class Target >
Target state_cast() const;
template< class Target >
Target state_downcast() const;

state_iterator state_begin() const;
state_iterator state_end() const;

States that need to call any of these member functions from their constructors must derive from the state class template.
必須從其構造函數中調用以上某一個成員函數的狀態,必須派生自 state 類模板。

Class template simple_state parameters 類模板 simple_state 的參數

Template parameter 模板參數 Requirements 要求 Semantics 語義 Default 缺省值
MostDerived The most-derived subtype of this class template
這個類模板的最底層子類型
   
Context A most-derived direct or indirect subtype of the state_machine or asynchronous_state_machine class templates or a model of the SimpleState or State concepts or an instantiation of the simple_state<>::orthogonal class template. Must be a complete type
state_machineasynchronous_state_machine 類模板的一個最底層直接或間接子類,或者是符合 簡 單狀態狀態 概念的一個類型,或者是 simple_state<>::orthogonal 類模板的一個實例。必須是完整類型
Defines the states' position in the state hierarchy
定義了該狀態在狀態層次中的位置
 
InnerInitial An mpl::list<> containing models of the SimpleState or State concepts or instantiations of the shallow_history or deep_history class templates. If there is only a single inner initial state that is not a template instantiation then it can also be passed directly, without wrapping it into an mpl::list<>. The Context argument passed to the simple_state<> or state<> base of each state in the list must correspond to the orthogonal region it belongs to. That is, the first state in the list must pass MostDerived::orthogonal< 0 >, the second MostDerived::orthogonal< 1 > and so forth. MostDerived::orthogonal< 0 > and MostDerived are synonymous
一個 mpl::list<>,其中包含有符合 簡單狀態狀態 概念的類型或 shallow_historydeep_history 類模板的實例。如果只有單個內層初始狀態,且不是模板實例,那麼也可以直接傳遞該狀態而無需用 mpl::list<> 來包裝。列表中每個狀態的 simple_state<>state<> 基類的 Context 參數必須與其所屬的正交區域相符。即,列表中的第一個狀態必須傳入 MostDerived::orthogonal< 0 >, 第二個狀態必須傳入 MostDerived::orthogonal< 1 > 等等。 MostDerived::orthogonal< 0 >MostDerived 同義
Defines the inner initial state for each orthogonal region. By default, a state does not have inner states
定義每個正交區域的內層初始狀態。缺省情況下,一個狀態沒有內層狀態
unspecified
未指定
historyMode One of the values defined in the history_mode enumeration
history_mode 枚舉中定義的某個值
Defines whether the state saves shallow, deep or both histories upon exit
定義該狀態在退出時是否保存淺歷史、深歷史或兩者均保存
has_no_history

Class template simple_state synopsis 類模板 simple_state 的摘要

namespace boost
{
namespace statechart
{
template<
class MostDerived,
class Context,
class InnerInitial = unspecified,
history_mode historyMode = has_no_history >
class simple_state : implementation-defined
{
public:
// by default, a state has no reactions
// 缺省情況下,狀態不帶反應
typedef mpl::list<> reactions;
// see template parameters 見模板參數
template< implementation-defined-unsigned-integer-type
innerOrthogonalPosition >
struct orthogonal
{
// implementation-defined 由具體實現定義
};
typedef typename Context::outermost_context_type
outermost_context_type;
outermost_context_type & outermost_context();
const outermost_context_type & outermost_context() const;

template< class OtherContext >
OtherContext & context();
template< class OtherContext >
const OtherContext & context() const;

template< class Target >
Target state_cast() const;
template< class Target >
Target state_downcast() const;

// a model of the StateBase concept 符合狀態基概念
typedef implementation-defined state_base_type;
// a model of the standard Forward Iterator concept
// 符合標準的前向迭代器概念
typedef implementation-defined state_iterator;

state_iterator state_begin() const;
state_iterator state_end() const;

void post_event(
const intrusive_ptr< const event_base > & );
void post_event( const event_base & );

result discard_event();
result forward_event();
result defer_event();
template< class DestinationState >
result transit();
template<
class DestinationState,
class TransitionContext,
class Event >
result transit(
void ( TransitionContext::* )( const Event & ),
const Event & );
result terminate();

template<
class HistoryContext,
implementation-defined-unsigned-integer-type
orthogonalPosition >
void clear_shallow_history();
template<
class HistoryContext,
implementation-defined-unsigned-integer-type
orthogonalPosition >
void clear_deep_history();

static id_type static_type();

template< class CustomId >
static const CustomId * custom_static_type_ptr();

template< class CustomId >
static void custom_static_type_ptr( const CustomId * );

// see transit() or terminate() effects
// 見 transit() 或 terminate() 的作用
void exit() {}

protected:
simple_state();
~simple_state();
};
}
}

Class template simple_state constructor and destructor 類模板 simple_state 的構造函數和析構函數

simple_state();

Effects: Constructs a state object
作用:構造一個狀態對像

~simple_state();

Effects: Pushes all events deferred by the state into the posted events queue
作用:將所有被該狀態延遲的事件壓入事件隊列

Class template simple_state modifier functions 類模板 simple_state 的可變函數

void post_event(
const intrusive_ptr< const event_base > & pEvt );

Requires: If called from a constructor of a direct or indirect subtype then the most-derived type must directly or indirectly derive from the state class template. All direct and indirect callers must be exception-neutral
要求:如果從一個直接或間接子類的構造函數調用,則最底層類型必須直接或間接派生自 state 類模板。所有直接或間接的調用者都必須是異常中立的
Effects: outermost_context().post_event( pEvt );
作用:outermost_context().post_event( pEvt );
Throws: Whatever the above call throws
拋出:以上調用所拋出的任何異常

void post_event( const event_base & evt );

Requires: If called from a constructor of a direct or indirect subtype then the most-derived type must directly or indirectly derive from the state class template. All direct and indirect callers must be exception-neutral
要求:如果從一個直接或間接子類的構造函數調用,則最底層類型必須直接或間接派生自 state 類模板。所有直接或間接的調用者都必須是異常中立的
Effects
: outermost_context().post_event( evt );
作用:outermost_context().post_event( pEvt );
Throws: Whatever the above call throws
拋出:以上調用所拋出的任何異常

result discard_event();

Requires: Must only be called from within react member functions, which are called by custom_reaction<> instantiations. All direct and indirect callers must be exception-neutral
要求:只能從 react 成員函數內中調用,該成員函數由 custom_reaction<> 實例調用。所有直接或間接的調用者都必須是異常中立的
Effects: Instructs the state machine to discard the current event and to continue with the processing of the remaining events (see state_machine<>::process_event() for details)
作用:指示狀態機忽略當前事件,並繼續處理其餘事件(詳情請見 state_machine<>::process_event())
Returns: A result object. The user-supplied react member function must return this object to its caller
返回:一個 result 對象。用戶提供的 react 成員函數必須返回該對像給它的調用者

result forward_event();

Requires: Must only be called from within react member functions, which are called by custom_reaction<> instantiations. All direct and indirect callers must be exception-neutral
要求:只能從 react 成員函數內中調用,該成員函數由 custom_reaction<> 實例調用。所有直接或間接的調用者都必須是異常中立的
Effects: Instructs the state machine to forward the current event to the next state (see state_machine<>::process_event() for details)
作用:指示狀態機將當前事件前轉到下一個狀態(詳情請見 state_machine<>::process_event())
Returns: A result object. The user-supplied react member function must return this object to its caller
返回:一個 result 對象。用戶提供的 react 成員函數必須返回該對像給它的調用者

result defer_event();

Requires: Must only be called from within react member functions, which are called by custom_reaction<> instantiations. All direct and indirect callers must be exception-neutral
要求:只能從 react 成員函數內中調用,該成員函數由 custom_reaction<> 實例調用。所有直接或間接的調用者都必須是異常中立的
Effects: Instructs the state machine to defer the current event and to continue with the processing of the remaining events (see state_machine<>::process_event() for details)
作用:指示狀態機延遲當前事件,並繼續處理其餘事件(詳情請見 state_machine<>::process_event())
Returns: A result object. The user-supplied react member function must return this object to its caller
返回:一個 result 對象。用戶提供的 react 成員函數必須返回該對像給它的調用者
Throws: Any exceptions propagated from Allocator::rebind<>::other::allocate() (the template parameter passed to the base class of outermost_context_type)
拋出:Allocator::rebind<>::other::allocate() (傳給 outermost_context_type 的基類的模板參數)傳出的任何異常

template< class DestinationState >
result transit();

Requires: Must only be called from within react member functions, which are called by custom_reaction<> instantiations. All direct and indirect callers must be exception-neutral
要求:只能從 react 成員函數內中調用,該成員函數由 custom_reaction<> 實例調用。所有直接或間接的調用者都必須是異常中立的
Effects
作用:

  1. Exits all currently active direct and indirect inner states of the innermost common context of this state and DestinationState. Innermost states are exited first. Other states are exited as soon as all their direct and indirect inner states have been exited. The inner states of each state are exited according to the number of their orthogonal region. The state in the orthogonal region with the highest number is always exited first, then the state in the region with the second-highest number and so on.
    退出該狀態與 DestinationState 的最內層公共上下文的所有當前活動的直接及間接內層狀態。首先退出最內層的狀態。其它狀態在其所有直接及間接內層狀態退出後立即退出。每個狀態的內層狀態 根據 它們的正交區域號碼順序退出。最大號碼的正交區域中的狀態總是首先退出,然後是次大號碼區域中的狀態,依此類推。
    The process of exiting a state consists of the following steps:
    退出一個狀態的過程包含以下步驟:
    1. If there is an exception pending that has not yet been handled successfully then only step 5 is executed
      如果有未決異常尚未成功處理,則只執行步驟5
    2. Calls the exit member function (see synopsis) of the most-derived state object. If exit() throws then steps 3 and 4 are not executed
      調用最底層的狀態對象的 exit 成員函數(見 摘 要)。如果 exit() 拋出異常,則不執行步驟3和4
    3. If the state has shallow history then shallow history information is saved
      如果該狀態帶有淺歷史,則保存淺歷史信息
    4. If the state is an innermost state then deep history information is saved for all direct and indirect outer states that have deep history
      如果該狀態為最內層狀態,則為所有帶有深歷史的直接及間接外層狀態保存深歷史信息
    5. The state object is destructed
      該狀態對像被析構
  2. Enters (constructs) the state that is both a direct inner state of the innermost common context and either the DestinationState itself or a direct or indirect outer state of DestinationState
    進 入(構造)以下狀態,該狀態既是最內層公共上下文的直接內層狀態,同時也是 DestinationState 狀態本身或 DestinationState 的一個直接或間接外層狀態
  3. Enters (constructs) the tree formed by the direct and indirect inner states of the previously entered state down to the DestinationState and beyond 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
    進入(構造)由前一步所進入的狀態向下直至 DestinationState 的所有直接和間接內層狀態以深度優先方式所形成的樹。每個狀態的內層狀態依據其正交區域號碼的順序進入。正交區域0中的狀態總是首先進入,然後進入區域1 的狀態,等等
  4. Instructs the state machine to discard the current event and to continue with the processing of the remaining events (see state_machine<>::process_event() for details)
    指示狀態機忽略當前事件,並繼續處理其餘事件(詳情請見 state_machine<>::process_event())

Returns: A result object. The user-supplied react member function must return this object to its caller
返回:一個 result 對象。用戶提供的 react 成員函數必須返回該對像給它的調用者
Throws: Any exceptions propagated from:
拋出:從以下函數傳出的任何異常:

Caution: Inevitably destructs this state before returning to the calling react member function, which must therefore not attempt to access anything except stack objects before returning to its caller
警告:
在返回調用者 react 成員函數之前,該狀態不可避免要被析構,因此在返回其調用者之前,不要嘗試訪問除了棧對像以外的任何東西

template<
class DestinationState,
class TransitionContext,
class Event >
result transit(
void ( TransitionContext::* )( const Event & ),
const Event & );

Requires: Must only be called from within react member functions, which are called by custom_reaction<> instantiations. All direct and indirect callers must be exception-neutral
要求:只能從 react 成員函數內中調用,該成員函數由 custom_reaction<> 實例調用。所有直接或間接的調用者都必須是異常中立的
Effects:
作用:

  1. Exits all currently active direct and indirect inner states of the innermost common context of this state and DestinationState. Innermost states are exited first. Other states are exited as soon as all their direct and indirect inner states have been exited. The inner states of each state are exited according to the number of their orthogonal region. The state in the orthogonal region with the highest number is always exited first, then the state in the region with the second-highest number and so on.
    退出該狀態與 DestinationState 的最內層公共上下文的所有當前活動的直接及間接內層狀態。首先退出最內層的狀態。其它狀態在其所有直接及間接內層狀態退出後立即退出。每個狀態的內層狀態 根據 它們的正交區域號碼順序退出。最大號碼的正交區域中的狀態總是首先退出,然後是次大號碼區域中的狀態,依此類推。
    The process of exiting a state consists of the following steps:
    退出一個狀態的過程包含以下步驟:
    1. If there is an exception pending that has not yet been handled successfully then only step 5 is executed
      如果有未決異常尚未成功處理,則只執行步驟5
    2. Calls the exit member function (see synopsis) of the most-derived state object. If exit() throws then steps 3 and 4 are not executed
      調用最底層的狀態對象的 exit 成員函數(見 摘 要)。如果 exit() 拋出異常,則不執行步驟3和4
    3. If the state has shallow history then shallow history information is saved
      如果該狀態帶有淺歷史,則保存淺歷史信息
    4. If the state is an innermost state then deep history information is saved for all direct and indirect outer states that have deep history
      如果該狀態為最內層狀態,則為所有帶有深歷史的直接及間接外層狀態保存深歷史信息
    5. The state object is destructed
      該狀態對像被析構
  2. Executes the passed transition action, forwarding the passed event
    執行傳入的轉換動作,並前轉傳入的事件
  3. Enters (constructs) the state that is both a direct inner state of the innermost common context and either the DestinationState itself or a direct or indirect outer state of DestinationState
    進 入(構造)以下狀態,該狀態既是最內層公共上下文的直接內層狀態,同時也是 DestinationState 狀態本身或 DestinationState 的一個直接或間接外層狀態
  4. Enters (constructs) the tree formed by the direct and indirect inner states of the previously entered state down to the DestinationState and beyond 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
    進入(構造)由前一步所進入的狀態向下直至 DestinationState 的所有直接和間接內層狀態以深度優先方式所形成的樹。每個狀態的內層狀態依據其正交區域號碼的順序進入。正交區域0中的狀態總是首先進入,然後進入區域1 的狀態,等等
  5. Instructs the state machine to discard the current event and to continue with the processing of the remaining events (see state_machine<>::process_event() for details)
    指示狀態機忽略當前事件,並繼續處理其餘事件(詳情請見 state_machine<>::process_event())

Returns: A result object. The user-supplied react member function must return this object to its caller
返回:一個 result 對象。用戶提供的 react 成員函數必須返回該對像給它的調用者
Throws: Any exceptions propagated from:
拋出:從以下函數傳出的任何異常:

Caution: Inevitably destructs this state before returning to the calling react member function, which must therefore not attempt to access anything except stack objects before returning to its caller
警告:
在返回調用者 react 成員函數之前,該狀態不可避免要被析構,因此在返回其調用者之前,不要嘗試訪問除了棧對像以外的任何東西

result terminate();

Requires: Must only be called from within react member functions, which are called by custom_reaction<> instantiations. All direct and indirect callers must be exception-neutral
要求:只能從 react 成員函數內中調用,該成員函數由 custom_reaction<> 實例調用。所有直接或間接的調用者都必須是異常中立的
Effects: Exits this state and all its direct and indirect inner states. Innermost states are exited first. Other states are exited as soon as all their direct and indirect inner states have been exited. The inner states of each state are exited according to the number of their orthogonal region. The state in the orthogonal region with the highest number is always exited first, then the state in the region with the second-highest number and so on.
作用:退出該狀態及其所有直接及間接內層狀態。首先退出最內層的狀態。其它狀態在其所有直接及間接內層狀態退出後 立即退出。每個狀態的內層狀態根據 它們的正交區域號碼順序退出。最大號碼的正交區域中的狀態總是首先退出,然後是次大號碼區域中的狀態,依此類推。
The process of exiting a state consists of the following steps:
退出一個狀態的過程包含以下步驟:

  1. If there is an exception pending that has not yet been handled successfully then only step 5 is executed
    如果有未決異常尚未成功處理,則只執行步驟5
  2. Calls the exit member function (see synopsis) of the most-derived state object. If exit() throws then steps 3 and 4 are not executed
    調用最底層的狀態對象的 exit 成員函數(見 摘 要)。如果 exit() 拋出異常,則不執行步驟3和4
  3. If the state has shallow history then shallow history information is saved
    如果該狀態帶有淺歷史,則保存淺歷史信息
  4. If the state is an innermost state then deep history information is saved for all direct and indirect outer states that have deep history
    如果該狀態為最內層狀態,則為所有帶有深歷史的直接及間接外層狀態保存深歷史信息
  5. The state object is destructed
    該狀態對像被析構

Also instructs the state machine to discard the current event and to continue with the processing of the remaining events (see state_machine<>::process_event() for details)
並同時指示狀態機忽略當前事件,並繼續處理其餘事件(詳情請見 state_machine<>::process_event())
Returns: A result object. The user-supplied react member function must return this object to its caller
返回:一個 result 對象。用戶提供的 react 成員函數必須返回該對像給它的調用者
Throws: Any exceptions propagated from:
拋出:從以下函數傳出的任何異常:

Note: If this state is the only currently active inner state of its direct outer state then the direct outer state is terminated also. The same applies recursively for all indirect outer states
說明:如果該狀態是其直接外層狀態中唯一的當前活動內層狀態,則其直接外層狀態也將被終止。相同規則會被反覆應用 於所有間接外層狀態
Caution: Inevitably destructs this state before returning to the calling react member function, which must therefore not attempt to access anything except stack objects before returning to its caller
警告:
在返回調用者 react 成員函數之前,該狀態不可避免要被析構,因此在返回其調用者之前,不要嘗試訪問除了棧對像以外的任何東西

template<
class HistoryContext,
implementation-defined-unsigned-integer-type
orthogonalPosition >
void clear_shallow_history();

Requires: If called from a constructor of a direct or indirect subtype then the most-derived type must directly or indirectly derive from the state class template. The historyMode argument passed to the simple_state<> or state<> base of HistoryContext must be equal to has_shallow_history or has_full_history
要求:如果從一個直接或間接子類的構造函數調用,則最底層類型必須直接或間接派生自 state 類模板。傳給 HistoryContextsimple_state<>state<> 基類的 historyMode 參數必須等於 has_shallow_historyhas_full_history
Effects: Clears the shallow history of the orthogonal region specified by orthogonalPosition of the state specified by HistoryContext
作用:清除由 HistoryContext 指定的狀態的 orthogonalPosition 所指定的正交區域的淺歷史
Throws: Any exceptions propagated from Allocator::rebind<>::other::allocate() (the template parameter passed to the base class of outermost_context_type)
拋出:Allocator::rebind<>::other::allocate() (傳給 outermost_context_type 的基類的模板參數)傳出的任何異常

template<
class HistoryContext,
implementation-defined-unsigned-integer-type
orthogonalPosition >
void clear_deep_history();

Requires: If called from a constructor of a direct or indirect subtype then the most-derived type must directly or indirectly derive from the state class template. The historyMode argument passed to the simple_state<> or state<> base of HistoryContext must be equal to has_deep_history or has_full_history
要求:如果從一個直接或間接子類的構造函數調用,則最底層類型必須直接或間接派生自 state 類模板。傳給 HistoryContextsimple_state<>state<> 基類的 historyMode 參數必須等於 has_deep_historyhas_full_history
Effects: Clears the deep history of the orthogonal region specified by orthogonalPosition of the state specified by HistoryContext
作用:清除由 HistoryContext 指定的狀態的 orthogonalPosition 所指定的正交區域的深歷史
Throws: Any exceptions propagated from Allocator::rebind<>::other::allocate() (the template parameter passed to the base class of outermost_context_type)
拋出:Allocator::rebind<>::other::allocate() (傳給 outermost_context_type 的基類的模板參數)傳出的任何異常

Class template simple_state observer functions 類模板 simple_state 的常性函數

outermost_context_type & outermost_context();

Requires: If called from a constructor of a direct or indirect subtype then the most-derived type must directly or indirectly derive from the state class template. If called from a destructor of a direct or indirect subtype then the state_machine<> subclass portion must still exist
要求:如果從一個直接或間接子類的構造函數調用,則最底層類型必須直接或間接派生自 state 類模板。如果從一個直接或間接子類的析構函數調用,則 state_machine<> 的子類部分必須仍然存在。
Returns
: A reference to the outermost context, which is always the state machine this state belongs to
返回:引向最外層上下文的一個引用,該上下文總是本狀態所屬的狀態機

const outermost_context_type & outermost_context() const;

Requires: If called from a constructor of a direct or indirect subtype then the most-derived type must directly or indirectly derive from the state class template. If called from a destructor of a direct or indirect subtype then the state_machine<> subclass portion must still exist
要求:如果從一個直接或間接子類的構造函數調用,則最底層類型必須直接或間接派生自 state 類模板。如果從一個直接或間接子類的析構函數調用,則 state_machine<> 的子類部分必須仍然存在。
Returns
: A reference to the const outermost context, which is always the state machine this state belongs to
返回:引向 const 最外層上下文的一個引用,該上下文總是本狀態所屬的狀態機

template< class OtherContext >
OtherContext & context();

Requires: If called from a constructor of a direct or indirect subtype then the most-derived type must directly or indirectly derive from the state class template. If called from a destructor of a direct or indirect subtype with a state_machine<> subtype as argument then the state_machine<> subclass portion must still exist
要求:如果從一個直接或間接子類的構造函數調用,則最底層類型必須直接或間接派生自 state 類模板。如果從一個直接或間接子類的析構函數調用,則 state_machine<> 的子類部分必須仍然存在。
Returns
: A reference to a direct or indirect context
返回:引向直接或間接上下文的一個引用

template< class OtherContext >
const OtherContext & context() const;

Requires: If called from a constructor of a direct or indirect subtype then the most-derived type must directly or indirectly derive from the state class template. If called from a destructor of a direct or indirect subtype with a state_machine<> subtype as argument then the state_machine<> subclass portion must still exist
要求:如果從一個直接或間接子類的構造函數調用,則最底層類型必須直接或間接派生自 state 類模板。如果從一個直接或間接子類的析構函數調用,則 state_machine<> 的子類部分必須仍然存在。
Returns
: A reference to a const direct or indirect context
返回:引向 const 直接或間接上下文的一個引用

template< class Target >
Target state_cast() const;

Requires: If called from a constructor of a direct or indirect subtype then the most-derived type must directly or indirectly derive from the state class template
要求:如果從一個直接或間接子類的構造函數調用,則最底層類型必須直接或間接派生自 state 類模板。
Returns
: Has exactly the same semantics as state_machine<>::state_cast<>()
返回:具有與 state_machine<>::state_cast<>() 完全相同的語義
Throws: Has exactly the same semantics as state_machine<>::state_cast<>()
拋出:具有與 state_machine<>::state_cast<>() 完全相同的語義
Note: The result is unspecified if this function is called when the machine is unstable
說明:如果調用該函數時狀態機是 不穩定 的,則結果未有規定

template< class Target >
Target state_downcast() const;

Requires: If called from a constructor of a direct or indirect subtype then the most-derived type must directly or indirectly derive from the state class template. Moreover, state_machine<>::state_downcast<>() requirements also apply
要求:如果從一個直接或間接子類的構造函數調用,則最底層類型必須直接或間接派生自 state 類模板。此外,還要求具有 state_machine<>::state_downcast<>() 
Returns: Has exactly the same semantics as state_machine<>::state_downcast<>()
返回:具有與 state_machine<>::state_downcast<>() 完全相同的語義
Throws: Has exactly the same semantics as state_machine<>::state_downcast<>()
拋出:具有與 state_machine<>::state_downcast<>() 完全相同的語義
Note
: The result is unspecified if this function is called when the machine is unstable
說明:如果調用該函數時狀態機是 不穩定 的,則結果未有規定

state_iterator state_begin() const;
state_iterator state_end() const;

Require: If called from a constructor of a direct or indirect subtype then the most-derived type must directly or indirectly derive from the state class template
要求:如果從一個直接或間接子類的構造函數調用,則最底層類型必須直接或間接派生自 state 類模板。
Return
: Have exactly the same semantics as state_machine<>::state_begin() and state_machine<>::state_end()
返回:具有與 state_machine<>::state_begin()state_machine<>::state_end() 完全相同的語義
Note: The result is unspecified if these functions are called when the machine is unstable
說明:如果調用該函數時狀態機是 不穩定 的,則結果未有規定

Class template simple_state static functions 類模板 simple_state 的靜態函數

static id_type static_type();

Returns: A value unambiguously identifying the type of MostDerived
返回:一個明確標識出 MostDerived 類型的值
Note: id_type values are comparable with operator==() and operator!=(). An unspecified collating order can be established with std::less< id_type >
說明:id_type 值可以用 operator==()operator!=() 來進行比較。未指定的比較順序可以由 std::less< id_type > 制定

template< class CustomId >
static const CustomId * custom_static_type_ptr();

Requires: If a custom type identifier has been set then CustomId must match the type of the previously set pointer
要求:如果已經設置了定制的類型標識符,則 CustomId 必須與之前設置的指針相匹配
Returns: The pointer to the custom type identifier for MostDerived or 0
返回:指向 MostDerived 的定制類型標識符的指針,或返回 0
Note: This function is not available if BOOST_STATECHART_USE_NATIVE_RTTI is defined
說明:如果定義了 BOOST_STATECHART_USE_NATIVE_RTTI 則本函數不可用

template< class CustomId >
static void custom_static_type_ptr( const CustomId * );

Effects: Sets the pointer to the custom type identifier for MostDerived
作用:設置指向 MostDerived 的定制類型標識符的指針
Note: This function is not available if BOOST_STATECHART_USE_NATIVE_RTTI is defined
說明:如果定義了 BOOST_STATECHART_USE_NATIVE_RTTI 則本函數不可用

Header <boost/statechart/state.hpp>

Class template state 類模板 state

This is the base class template for all models of the State concept. Such models typically need to call at least one of the following simple_state<> member functions from their constructors:
這是所有符合 狀態 概念的類型的基類模板。這些類型通常需要從它們的構造函數中調用以下 simple_state<> 成員函數中的至少一個:

void post_event(
const intrusive_ptr< const event_base > & );
void post_event( const event_base & );

template<
class HistoryContext,
implementation-defined-unsigned-integer-type
orthogonalPosition >
void clear_shallow_history();
template<
class HistoryContext,
implementation-defined-unsigned-integer-type
orthogonalPosition >
void clear_deep_history();

outermost_context_type & outermost_context();
const outermost_context_type & outermost_context() const;

template< class OtherContext >
OtherContext & context();
template< class OtherContext >
const OtherContext & context() const;

template< class Target >
Target state_cast() const;
template< class Target >
Target state_downcast() const;

state_iterator state_begin() const;
state_iterator state_end() const;

States that do not need to call any of these member functions from their constructors should rather derive from the simple_state class template, what saves the implementation of the forwarding constructor.
不需要從構造函數中調用以上所有成員函數的狀態,應該從 simple_state 類模板進行派生,這樣可以節省前轉構造函數的實現。

Class template state synopsis 類模板 state 的摘要

namespace boost
{
namespace statechart
{
template<
class MostDerived,
class Context,
class InnerInitial = unspecified,
history_mode historyMode = has_no_history >
class state : public simple_state<
MostDerived, Context, InnerInitial, historyMode >
{
protected:
struct my_context
{
// implementation-defined 由實現定義
};
typedef state my_base;
state( my_context ctx );
~state();
};
}
}

Direct and indirect subtypes of state<> must provide a constructor with the same signature as the state<> constructor, forwarding the context parameter.
state<> 的直接和間接子類必須提供一個與 state<> 構造函數簽名相同的構造函數,用於前轉上下文參數。

Header <boost/statechart/shallow_history.hpp>

Class template shallow_history 類模板 shallow_history

This class template is used to specify a shallow history transition target or a shallow history inner initial state.
該類模板用於指定一個淺歷史的轉換目標或是一個淺歷史的內層初始狀態。

Class template shallow_history parameters 類模板 shallow_history 的參數

Template parameter 模板參數 Requirements 要求 Semantics 語義
DefaultState A model of the SimpleState or State concepts. The type passed as Context argument to the simple_state<> or state<> base of DefaultState must itself pass has_shallow_history or has_full_history as historyMode argument to its simple_state<> or state<> base
符合 簡單狀態狀態 概念。傳給 DefaultStatesimple_state<>state<> 基類的 Context 參數的類型必須以 has_shallow_historyhas_full_history 作為 historyMode 參數傳給其 simple_state<>state<> 基類
The state that is entered if shallow history is not available
在淺歷史不可用時將進入的狀態

Class template shallow_history synopsis 類模板 shallow_history 的摘要

namespace boost
{
namespace statechart
{
template< class DefaultState >
class shallow_history
{
// implementation-defined 由實現定義
};
}
}

Header <boost/statechart/deep_history.hpp>

Class template deep_history 類模板 deep_history

This class template is used to specify a deep history transition target or a deep history inner initial state. The current deep history implementation has some limitations.
該類模板用於指定一個深歷史轉換目標或一個深歷史的內層初始狀態。當前的深歷史實現有一些 局限

Class template deep_history parameters 類模板 deep_history 的參數

Template parameter 模板參數 Requirements 要求 Semantics 語義
DefaultState A model of the SimpleState or State concepts. The type passed as Context argument to the simple_state<> or state<> base of DefaultState must itself pass has_deep_history or has_full_history as historyMode argument to its simple_state<> or state<> base
符合 簡單狀態狀態 概念。傳給 DefaultStatesimple_state<>state<> 基類的 Context 參數的類型必須以 has_deep_historyhas_full_history 作為 historyMode 參數傳給其 simple_state<>state<> 基類
The state that is entered if deep history is not available
在深歷史不可用時將進入的狀態

Class template deep_history synopsis 類模板 deep_history 的摘要

namespace boost
{
namespace statechart
{
template< class DefaultState >
class deep_history
{
// implementation-defined 由實現定義
};
}
}

Header <boost/statechart/event_base.hpp>

Class event_base 類 event_base

This is the common base of all events.
這是所有事件的公共基類。

Class event_base synopsis 類 event_base 的摘要

namespace boost
{
namespace statechart
{
class event_base
{
public:
intrusive_ptr< const event_base >
intrusive_from_this() const;

typedef implementation-defined id_type;

id_type dynamic_type() const;

template< typename CustomId >
const CustomId * custom_dynamic_type_ptr() const;

protected:
event_base( unspecified-parameter );
virtual ~event_base();
};
}
}

Class event_base constructor and destructor 類 event_base 的構造函數和析構函數

event_base( unspecified-parameter );

Effects: Constructs the common base portion of an event
作用:構造一個事件的公共基類部分

virtual ~event_base();

Effects: Destructs the common base portion of an event
作用:析構一個事件的公共基類部分

Class event_base observer functions 類 event_base 的常性函數

intrusive_ptr< const event_base > intrusive_from_this() const;

Returns: Another intrusive_ptr< const event_base > referencing this if this is already referenced by an intrusive_ptr<>. Otherwise, returns an intrusive_ptr< const event_base > referencing a newly created copy of the most-derived object
返回:如果 this 已經被某個 intrusive_ptr<> 引向,則返回引向 this 的另一個 intrusive_ptr< const event_base > 。否則,返回,為類層次最底層的對象創建一個新的拷貝並返回引向它的 一個 intrusive_ptr< const event_base >

id_type dynamic_type() const;

Returns: A value unambiguously identifying the most-derived type
返回:一個明確標識出類層次最底層類型的值
Note: id_type values are comparable with operator==() and operator!=(). An unspecified collating order can be established with std::less< id_type >. In contrast to typeid( cs ), this function is available even on platforms that do not support C++ RTTI (or have been configured to not support it)
說明:id_type 的值可以通過 operator==()operator!=() 進行比較。未指定的比較順序可由 std::less< id_type > 確定。與 typeid( cs ) 相比,本函數即使在不支持 C++ RTTI (或被配置為不支持它)的平台上也可用

template< typename CustomId >
const CustomId * custom_dynamic_type_ptr() const;

Requires: If a custom type identifier has been set then CustomId must match the type of the previously set pointer
要求:如果已設置了一個定制類型標識符,則 CustomId 必須與之前設置的指針類型相匹配
Returns: A pointer to the custom type identifier or 0
返回:一個指向定制類型標識符的指針或0
Note: This function is not available if BOOST_STATECHART_USE_NATIVE_RTTI is defined
說明:如果定義了 BOOST_STATECHART_USE_NATIVE_RTTI, 則本函數不可用

Header <boost/statechart/event.hpp>

Class template event 類模板 event

This is the base class template of all events.
這是所有事件的基類模板。

Class template event parameters 類模板 event 的參數

Template parameter 模板參數 Requirements 要求 Semantics 語義 Default 缺省值
MostDerived The most-derived subtype of this class template
該類模板的最底層子類
   
Allocator A model of the standard Allocator concept
符合標準分配器概念的類型
Allocator::rebind< MostDerived >::other is used to allocate and deallocate all event subtype objects of dynamic storage duration, see operator new
Allocator::rebind< MostDerived >::other 用於分配和釋放動態存儲期間的所有事件子類對象,請見 operator new
std::allocator< void >

Class template event synopsis 類模板 event 的摘要

namespace boost
{
namespace statechart
{
template< class MostDerived, class Allocator = std::allocator< void > >
class event : implementation-defined
{
public:
static void * operator new( std::size_t size );
static void operator delete( void * pEvent );

static id_type static_type();

template< class CustomId >
static const CustomId * custom_static_type_ptr();

template< class CustomId >
static void custom_static_type_ptr( const CustomId * );

protected:
event();
virtual ~event();
};
}
}

Class template event constructor and destructor 類模板 event 的構造函數和析構函數

event();

Effects: Constructs an event
作用:構造一個事件

virtual ~event();

Effects: Destructs an event
作用:析構一個事件

Class template event static functions 類模板 event 的靜態函數

static void * operator new( std::size_t size );

Effects: Allocator::rebind< MostDerived >::other().allocate( 1, static_cast< MostDerived * >( 0 ) );
作用:Allocator::rebind< MostDerived >::other().allocate( 1, static_cast< MostDerived * >( 0 ) );
Returns: The return value of the above call
返回:以上調用的返回值
Throws: Whatever the above call throws
拋出:以上調用拋出的任何異常

static void * operator new( std::size_t size, void * p );

Effects: None
作用:
Returns: p
返回:p

static void operator delete( void * pEvent );

Effects: Allocator::rebind< MostDerived >::other().deallocate( static_cast< MostDerived * >( pEvent ), 1 );
作用:Allocator::rebind< MostDerived >::other().deallocate( static_cast< MostDerived * >( pEvent ), 1 );

static id_type static_type();

Returns: A value unambiguously identifying the type of MostDerived
返回:一個明確標識出 MostDerived 類型的值
Note: id_type values are comparable with operator==() and operator!=(). An unspecified collating order can be established with std::less< id_type >
說明:id_type 的值可以通過 operator==()operator!=() 來比較。未指定的比較順序可以由 std::less< id_type > 確定

template< class CustomId >
static const CustomId * custom_static_type_ptr();

Requires: If a custom type identifier has been set then CustomId must match the type of the previously set pointer
要求:如果已設置了一個定制類型標識符,則 CustomId 必須與之前設置的指針類型相匹配
Returns: A pointer to the custom type identifier or 0
返回:一個指向 MostDerived 的定制類型標識符的指針或0
Note: This function is not available if BOOST_STATECHART_USE_NATIVE_RTTI is defined
說明:如果定義了 BOOST_STATECHART_USE_NATIVE_RTTI, 則本函數不可用

template< class CustomId >
static void custom_static_type_ptr( const CustomId * );

Effects: Sets the pointer to the custom type identifier for MostDerived
作用:設置指向 MostDerived 的定制類型標識符的指針
Note: This function is not available if BOOST_STATECHART_USE_NATIVE_RTTI is defined
說明:如果定義了 BOOST_STATECHART_USE_NATIVE_RTTI, 則本函數不可用

Header <boost/statechart/transition.hpp>

Class template transition 類模板 transition

This class template is used to specify a transition reaction. Instantiations of this template can appear in the reactions member typedef in models of the SimpleState and State concepts.
這個類模板用於指定轉換反應。該模板的實例可以出現在符合 簡 單狀態狀態 概念的類型的 reactions 成員 typedef 中。

Class template transition parameters 類模板 transition 的參數

Template parameter 模板函數 Requirements 要求 Semantics 語義 Default 缺省值
Event A model of the Event concept or the class event_base
符合 事件 概念的類型或類 event_base
The event triggering the transition. If event_base is specified, the transition is triggered by all models of the Event concept
觸發轉換的事件。如果指定了 event_base, 則該轉換由所有符合 事件 概念的類型觸發
 
Destination A model of the SimpleState or State concepts or an instantiation of the shallow_history or deep_history class templates. The source state (the state for which this transition is defined) and Destination must have a common direct or indirect context
符合 簡單狀態狀態 概念的類型或是 shallow_historydeep_history 類模板的一個實例。源狀態(定義該轉換的狀態)與 Destination 必須具有一個公共的直接或間接上下文
The destination state to make a transition to
轉換到的目標狀態
 
TransitionContext A common context of the source and Destination state
源狀態與 Destination 狀態的公共上下文
The state of which the transition action is a member
該轉換動作作為其成員的狀態
unspecified
未指定
pTransitionAction A pointer to a member function of TransitionContext. The member function must accept a const Event & parameter and return void
指向 TransitionContext 的一個成員函數的指針。該成員函數必須接受一個 const Event & 參數並返回 void
The transition action that is executed during the transition. By default no transition action is executed
在轉換期間被執行的轉換動作。缺省時不執行轉換動作
unspecified
未指定

Class template transition synopsis 類模板 transition 的摘要

namespace boost
{
namespace statechart
{
template<
class Event,
class Destination,
class TransitionContext = unspecified,
void ( TransitionContext::*pTransitionAction )(
const Event & ) = unspecified >
class transition
{
// implementation-defined 由實現定義
};
}
}

Class template transition semantics 類模板 transition 的語義

When executed, one of the following calls to a member function of the state for which the reaction was defined is made:
執行時,將調用以下兩個成員函數之一,這兩個成員函數是定義該反應的狀態類的:

Header <boost/statechart/in_state_reaction.hpp>

Class template in_state_reaction 類模板 in_state_reaction

This class template is used to specify an in-state reaction. Instantiations of this template can appear in the reactions member typedef in models of the SimpleState and State concepts.
這個類模板用於指定一個狀態內反應。這個模板的實例可以出現在符合 簡 單狀態狀態 概念的類型的 reactions 成員 typedef 中。

Class template in_state_reaction parameters 類模板 in_state_reaction 的參數

Template parameter 模板參數 Requirements 要求 Semantics 語義
Event A model of the Event concept or the class event_base
符合 事件 概念的類型或者為類 event_base
The event triggering the in-state reaction. If event_base is specified, the in-state reaction is triggered by all models of the Event concept
觸發狀態內反應的事件。如果指定了 event_base, 則該狀態內反應由所有符合 事件 概念的類型觸發
ReactionContext Either the state defining the in-state reaction itself or one of it direct or indirect contexts
要麼是定義該狀態內反應的狀態,要麼是它的直接或間接上下文
The state of which the action is a member
以該動作為其成員的狀態
pAction A pointer to a member function of ReactionContext. The member function must accept a const Event & parameter and return void
指向 ReactionContext 的一個成員函數的指針。該成員函數必須接受一個 const Event & 參數並返回 void
The action that is executed during the in-state reaction
在狀態內反應期間被執行的動作

Class template in_state_reaction synopsis 類模板 in_state_reaction 的摘要

namespace boost
{
namespace statechart
{
template<
class Event,
class ReactionContext,
void ( ReactionContext::*pAction )( const Event & ) >
class in_state_reaction
{
// implementation-defined 由實現定義
};
}
}

Class template in_state_reaction semantics 類模板 in_state_reaction 的語義

When executed then the following happens:
執行時有以下動作:

  1. If an action was specified, pAction is called, passing the triggering event as the only argument
    如果指定了一個動作,則調用 pAction,以觸發事件作為唯一參數
  2. A call is made to the discard_event member function of the state for which the reaction was defined
    為定義該反應的狀態調用 discard_event 成員函數

Header <boost/statechart/termination.hpp>

Class template termination 類模板 termination

This class template is used to specify a termination reaction. Instantiations of this template can appear in the reactions member typedef in models of the SimpleState and State concepts.
這個類模板用於指定一個終止反應。該模板的實例可以出現在符合 簡 單狀態狀態 概念的類型的 reactions 成員 typedef 中。

Class template termination parameters 類模板 termination 的參數

Template parameter 模板參數 Requirements 要求 Semantics 語義
Event A model of the Event concept or the class event_base
符合 事件 概念的類型或者為類 event_base
The event triggering the termination. If event_base is specified, the termination is triggered by all models of the Event concept
觸發終止動作的事件。如果指定了 event_base, 則該終止動作由所有符合 事件 概念的類型觸發

Class template termination synopsis 類模板 termination 的摘要

namespace boost
{
namespace statechart
{
template< class Event >
class termination
{
// implementation-defined 由實現定義
};
}
}

Class template termination semantics 類模板 termination 的語義

When executed, a call is made to the terminate member function of the state for which the reaction was defined.
執行時,調用定義了該反應的狀態的 terminate 成員函數。

Header <boost/statechart/deferral.hpp>

Class template deferral 類模板 deferral

This class template is used to specify a deferral reaction. Instantiations of this template can appear in the reactions member typedef in models of the SimpleState and State concepts.
這個類模板用於指定一個延遲反應。該模板的實例可以出現在符合 簡 單狀態狀態 概念的類型的 reactions 成員 typedef 中。

Class template deferral parameters 類模板 deferral 的參數

Template parameter 模板參數 Requirements 要求 Semantics 語義
Event A model of the Event concept or the class event_base
符合 事件 概念的類型或者為類 event_base
The event triggering the deferral. If event_base is specified, the deferral is triggered by all models of the Event concept
觸發延遲動作的事件。如果指定了 event_base, 則該延遲動作由所有符合 事件 概念的類型觸發

Class template deferral synopsis 類模板 deferral 的摘要

namespace boost
{
namespace statechart
{
template< class Event >
class deferral
{
// implementation-defined 由實現定義
};
}
}

Class template deferral semantics 類模板 deferral 的語義

When executed, a call is made to the defer_event member function of the state for which the reaction was defined.
執行時,調用定義了該反應的狀態的 defer_event 成員函數。

Header <boost/statechart/custom_reaction.hpp>

Class template custom_reaction 類模板 custom_reaction

This class template is used to specify a custom reaction. Instantiations of this template can appear in the reactions member typedef in models of the SimpleState and State concepts.
這個類模板用於指定一個定制反應。該模板的實例可以出現在符合 簡 單狀態狀態 概念的類型的 reactions 成員 typedef 中。

Class template custom_reaction parameters 類模板 custom_reaction 的參數

Template parameter 模板參數 Requirements 要求 Semantics 語義
Event A model of the Event concept or the class event_base
符合 事件 概念的類型或者為類 event_base
The event triggering the custom reaction. If event_base is specified, the custom reaction is triggered by all models of the Event concept
觸發這個定制反應的事件。如果指定了 event_base, 則該定制反應由所有符合 事件 概念的類型觸發

Class template custom_reaction synopsis 類模板 custom_reaction 的摘要

namespace boost
{
namespace statechart
{
template< class Event >
class custom_reaction
{
// implementation-defined 由實現定義
};
}
}

Class template custom_reaction semantics 類模板 custom_reaction 的語義

When executed, a call is made to the user-supplied react member function of the state for which the reaction was defined. The react member function must have the following signature:
執行時,調用定義了該反應的狀態中由用戶提供的 react 成員函數。該 react 成員函數必須帶有以下簽名:

result react( const Event & );

and must call exactly one of the following reaction functions and return the obtained result object:
並且必須調用以下反應函數中的某一個,返回得到的 result 對像:

result discard_event();
result forward_event();
result defer_event();
template< class DestinationState >
result transit();
template<
class DestinationState,
class TransitionContext,
class Event >
result transit(
void ( TransitionContext::* )( const Event & ),
const Event & );
result terminate();

Header <boost/statechart/result.hpp>

Class result 類 result

Defines the nature of the reaction taken in a user-supplied react member function (called when a custom_reaction is executed). Objects of this type are always obtained by calling one of the reaction functions and must be returned from the react member function immediately.
定義在一個用戶提供的 react 成員函數(在執行一個 custom_reaction 時調用)中發生的反應的結果。該類型的對象總是通過調用某一個反應函數獲得,而且必須立即從 react 成員函數返回。

namespace boost
{
namespace statechart
{
class result
{
public:
result( const result & other );
~result();

private:
// Result objects are not assignable
// Result 對像不可賦值
result & operator=( const result & other );
};
}
}

Class result constructor and destructor 類 result 的構造函數和析構函數

result( const result & other );

Requires: other is not consumed
要求:other 不是已消耗的
Effects: Copy-constructs a new result object and marks other as consumed. That is, result has destructive copy semantics
作用:複製構造一個新的 result 對象,並將 other 標記為已消耗。即,result 具有破壞性的複製語義

~result();

Requires: this is marked as consumed
要求:this 被標記為已消耗
Effects: Destructs the result object
作用:析構 result 對像


Valid HTML 4.01 Transitional

Revised 06 January, 2008

Copyright c 2003-2008 Andreas Huber Donni

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