Program Listing for File cell2D_fsm.hpp
↰ Return to documentation for file (cosm/fsm/cell2D_fsm.hpp
)
#pragma once
/*******************************************************************************
* Includes
******************************************************************************/
#include <string>
#include "rcsw/common/common.h"
#include "rcppsw/patterns/fsm/simple_fsm.hpp"
#include "cosm/cosm.hpp"
#include "cosm/fsm/cell2D_state.hpp"
/*******************************************************************************
* Namespaces
******************************************************************************/
namespace cosm::fsm {
/*******************************************************************************
* Class Definitions
******************************************************************************/
class cell2D_fsm final : public rpfsm::simple_fsm,
public rer::client<cell2D_fsm> {
public:
using state = cell2D_state;
cell2D_fsm(void);
~cell2D_fsm(void) override = default;
cell2D_fsm& operator=(const cell2D_fsm&) = delete;
cell2D_fsm(const cell2D_fsm& other);
bool state_is_known(void) const {
return current_state() != state::ekST_UNKNOWN;
}
bool state_has_block(void) const {
return current_state() == state::ekST_HAS_BLOCK;
}
bool state_has_cache(void) const {
return current_state() == state::ekST_HAS_CACHE;
}
bool state_in_cache_extent(void) const {
return current_state() == state::ekST_CACHE_EXTENT;
}
bool state_in_block_extent(void) const {
return current_state() == state::ekST_BLOCK_EXTENT;
}
bool state_in_nest_extent(void) const {
return current_state() == state::ekST_NEST_EXTENT;
}
bool state_is_empty(void) const { return current_state() == state::ekST_EMPTY; }
/* events */
void event_unknown(void);
void event_empty(void);
void event_block_pickup(void);
void event_block_drop(void);
void event_block_extent(void);
void event_cache_extent(void);
void event_nest_extent(void);
size_t block_count(void) const { return m_block_count; }
private:
struct block_data final : public rpfsm::event_data {
explicit block_data(bool pickup_in) : pickup(pickup_in) {}
bool pickup;
};
RCPPSW_FSM_STATE_DECLARE_ND(cell2D_fsm, state_unknown);
RCPPSW_FSM_STATE_DECLARE_ND(cell2D_fsm, state_empty);
RCPPSW_FSM_STATE_DECLARE_ND(cell2D_fsm, state_block);
RCPPSW_FSM_STATE_DECLARE(cell2D_fsm, state_cache, struct block_data);
RCPPSW_FSM_STATE_DECLARE_ND(cell2D_fsm, state_block_extent);
RCPPSW_FSM_STATE_DECLARE_ND(cell2D_fsm, state_cache_extent);
RCPPSW_FSM_STATE_DECLARE_ND(cell2D_fsm, state_nest_extent, RCPPSW_CONST);
RCPPSW_FSM_DEFINE_STATE_MAP_ACCESSOR(state_map, index) override {
return &mc_state_map[index];
}
RCPPSW_FSM_DECLARE_STATE_MAP(state_map, mc_state_map, state::ekST_MAX_STATES);
/* clang-format off */
size_t m_block_count{0};
/* clang-format on */
};
} /* namespace forydca::fsm */