C++ Boost

Boost Statechart 庫

Definitions 定義

Introduction 簡介

The Boost.Statechart documentation uses a lot of terminology specific to state machines. Most of it is equal to the one used in the UML specifications. This document contains only definitions for terminology not used by the UML standard. A short tour around UML terminology can be found here.
Boost.Statechart 的文檔使用了很多有關狀態機的術語。其中多數術語與UML規範是一致的。本文檔僅包含了在 UML 標準 中沒有使用的術語。關於UML術語的一個簡短的介紹請見 這 裡

Definitions 定義

Context 上下文
Innermost common context 最內層公共上下文
Innermost state 最內層狀態
In-state reaction 狀態內反應
Outermost state 最外層狀態
Polymorphic events 多態事件
Reaction 反應
Unstable state 不穩定狀態
Unstable state machine 不穩定狀態機

Context 上下文

The contexts of a state define its location in the state hierarchy. A state's direct context is defined by what is passed as the Context template parameter of the simple_state and state class templates. This can either be the state machine (which makes the state an outermost state) or its direct outer state. A state's indirect contexts follow from the direct context of its direct context and the direct context of the direct context of its direct context and so on. Examples:
一個狀態的上下文定義了它在狀態層次中的位置。狀態的直 接上下文由傳給 simple_statestate 類模板的 Context 模板參數來定義。它可以是狀態機本身(這代表該狀態是 最外層狀態)或是狀態的直 接外層狀態。狀態的間接上下文即為直接上下文的直接上下文,以及直接上下文的直接上下文的直接上下文,等等。例 如:


Innermost common context 最內層公共上下文

The innermost common context of two states is the first direct or indirect context that both states have in common. Also known as Least Common Ancestor (UML).

Innermost state 最內層狀態

An innermost state is a state that does not itself have inner states. Also known as leaf state or simple state (UML). Note that boost::statechart::simple_state<> is not a model of the UML simple state.
最內層狀態是指沒有內層狀態的狀態。也稱為葉子狀態或簡單狀態(UML)。注意,boost::statechart::simple_state<> 並不符合UML的簡單狀態概念。

In-state reaction 狀態內反應

An in-state reaction is a reaction that neither exits nor enters any states. Also known as inner transition or internal transition (UML).
狀態內反應是指既不退出也不進入任何狀態的 反 應。也稱為內層轉換或內部轉換(UML)。

Outermost state 最外層狀態

An outermost state is a state that does not itself have outer states. Note that an outermost state is different from the UML top state. A state machine can have an arbitrary number of the former but only exactly one of the latter. Boost.Statechart only supports outermost states.
最外層狀態是指沒有外層狀態的狀態。注意,最外層狀態不同於UML的頂層狀態。一個狀態機可以有任意個最外層狀態,但只能有一個頂層狀態。 Boost.Statechart 只支持最外層狀態。

Polymorphic events 多態事件

An FSM library supports polymorphic events if events can inherit from each other without restrictions and if it allows the definition of reactions for leafs and nodes of the resulting event inheritance tree.
一個FSM庫是支持多態事件的,如果事件可以不受限制地相互派生,允 許為事件繼承樹中的葉子和節點定義反應。

Example (using a hypothetical FSM library, as Boost.Statechart does not support polymorphic events):
例子(使用一個假設的FSM庫,因為 Boost.Statechart 不支持多態事件):

struct EvButtonPressed : Event // node 節點
/* common button pressed properties 公共的按鍵特性 */

struct EvPlayButtonPressed : EvButtonPressed {}; // leaf 葉子
struct EvStopButtonPressed : EvButtonPressed {}; // leaf 葉子
struct EvForwardButtonPressed : EvButtonPressed {}; // leaf 葉子

If a state machine needs to react whenever any button (including the ones that may be added in the future) is pressed, a reaction for EvButtonPressed can be defined.
如果狀態機需要對任意按鍵 (包括可能在以後加入的按鍵)作為反應,就要為 EvButtonPressed 定義反應。

Reaction 反應

A reaction consists of all the side effects caused by the processing of one event. Reactions can be categorized as follows:

  1. In-state reaction 狀態內反應
  2. Event deferral 事件延遲
  3. Transition 轉換
  4. Termination, also known as transition to the final state (UML)

Note that it is possible to mix a reaction of type 1 with one of the other types (the in-state reaction is always executed first) but it is not possible to mix a reaction of type 2-4 with anything else but type 1.

A reaction is always associated with exactly one state type and exactly one event type.

Unstable state 不穩定狀態

A state is unstable from the moment when it has been entered until after its last direct inner state has been entered. A state is also unstable from the moment just before its first direct inner state is exited until right before the state itself is exited.
一個狀態從開始被進入,直到它最後一個直接內 層狀態被進入的這段時間中是不穩定的。同樣,從它的第一個直 接內層狀態被退出,直到狀態本身被退出的這段時間,狀態也是不穩定的。

Unstable state machine 不穩定狀態機

A state machine is unstable if at least one of its currently active states is unstable. This is the case during the following three operations:

Under normal circumstances a state machine has Run-To-Completion semantics, that is, it is always stable before the machine returns to the client or before the next event is dequeued. So, a state machine is usually only unstable when it is busy processing an event and becomes stable again right before it has finished processing the event. However, this can not be guaranteed when entry, exit or transition actions fail. Such a failure is reported by an event, which must be processed while the state machine is unstable. However, exception event processing rules ensure that a state machine is never unstable when it returns to the client (see state_machine<>::process_event() for details).
在通常情況下,狀態機具有"運行直至完成"的語義,即在狀態機返回至客戶之前或下一個事件被出列之前,它總是穩定的。所以,一個狀態機通常只會在處理某一 事件時處於不穩定,且在事件處理完畢後重新恢復穩定。但是,如果進入、退出或轉換動作失敗,則這一點不被保證。這種失敗會通過事件來報告,該事件必須被處 理而狀態機又是不穩定的。不過,異常事件處理規則保證了狀態機在返回到客戶之時不會是不穩定的(詳情請見 state_machine<>::process_event())。

Valid HTML 4.01 Transitional

Revised 29 December, 2006

Copyright © 2003-2006 Andreas Huber Dönni

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)