Go to the documentation of this file.
16 explicit Attributes(
int max_iteration) : max_iteration(max_iteration) {}
30 std::cout <<
"The loop is over" << std::endl;
40 return attributes.
iteration < attributes.max_iteration;
44 std::cout << context.
get<
Attributes>().iteration << std::endl;
53 states.
create(INITIAL_STATE);
54 states.
create(LOOP_CONDITION_EVALUATION);
55 states.
create(BEGIN_OF_ITERATION);
56 states.
create(END_OF_ITERATION);
57 states.
create(FINAL_STATE);
59 transitions.
create(INITIAL_STATE, LOOP_CONDITION_EVALUATION, initialize_counter,
"$iteration = 0");
60 transitions.
create_if(LOOP_CONDITION_EVALUATION, BEGIN_OF_ITERATION, FINAL_STATE,evaluate_loop_condition,
"$iteration < $max_iteration");
61 transitions.
create(BEGIN_OF_ITERATION, END_OF_ITERATION, apply_loop_effect,
"show $iteration");
62 transitions.
create(END_OF_ITERATION, LOOP_CONDITION_EVALUATION, increment_counter,
"$iteration++");
63 transitions.
create(FINAL_STATE, FINAL_STATE, print_end_of_loop);
75 #ifndef STATE_MACHINE_CPP_EXAMPLE_FORLOOP_H
80 Algorithm::build<ForLoop>(algorithm);
86 auto context = Context::create<ForLoop>(10);
93 #endif // STATE_MACHINE_CPP_EXAMPLE_FORLOOP_H
static const State::Id BEGIN_OF_ITERATION
void create(const State::Any &t_initial_state, const State::Any &t_next_state, Transition::TrivialHandler &t_handler, std::string t_description="")
void create_if(const State::Any &t_initial_state, const State::Any &t_if_true, const State::Any &t_else, Transition::ConditionalHandler &t_handler, std::string t_description="")
void plot(const Algorithm::Instance &t_algorithm, const std::string &t_filename, bool t_run_command=true)
Attributes(int max_iteration)
static const State::Id END_OF_ITERATION
void run(const Algorithm::Instance &t_instance, Context &t_context)
static const State::Id INITIAL_STATE
static void apply_loop_effect(Context &context)
static const State::Id LOOP_CONDITION_EVALUATION
static void increment_counter(Context &context)
void build(States &states, Transitions &transitions, Layers &layers) override
virtual void create(const State::Any &t_state)=0
bool sanity_check(const Algorithm::Instance &t_algorithm)
static const State::Id FINAL_STATE
static void print_end_of_loop(Context &context)
static bool evaluate_loop_condition(const Context &context)
static AttributeTree< Layer< ForLoop::Attributes > > * create_attributes(int max_iteration)
static void initialize_counter(Context &context)