Program Listing for File state_guard_action.hpp
↰ Return to documentation for file (rcppsw/patterns/fsm/state_guard_action.hpp
)
#pragma once
/*******************************************************************************
* Includes
******************************************************************************/
#include "rcppsw/patterns/fsm/event.hpp"
#include "rcppsw/patterns/fsm/state_guard.hpp"
/*******************************************************************************
* Namespaces/Decls
******************************************************************************/
namespace rcppsw::patterns::fsm {
class base_fsm;
/*******************************************************************************
* Class Definitions
******************************************************************************/
template <class SM, class Event, bool (SM::*Func)(const Event*)>
class state_guard_condition1 : public state_guard {
public:
~state_guard_condition1(void) override = default;
bool invoke_guard_condition(base_fsm* sm,
const event_data* data) const override {
auto* derived_fsm = static_cast<SM*>(sm);
const Event* derived_event = NULL;
if (nullptr != data) {
derived_event = dynamic_cast<const Event*>(data);
assert(derived_event);
}
return (derived_fsm->*Func)(derived_event);
}
};
template <class SM, bool (SM::*Func)(void)>
class state_guard_condition0 : public state_guard {
public:
~state_guard_condition0(void) override = default;
bool invoke_guard_condition(base_fsm* sm,
RCPPSW_UNUSED const event_data*) const override {
auto* derived_fsm = static_cast<SM*>(sm);
return (derived_fsm->*Func)();
}
};
} /* namespace rcppsw::patterns::fsm */