Robot Devastation
StateMachineBuilder.hpp
1 // Authors: see AUTHORS.md at project root.
2 // CopyPolicy: released under the terms of the LGPLv2.1, see LICENSE at project root.
3 // URL: https://github.com/asrob-uc3m/robotDevastation
4 
5 #ifndef __RD_STATE_MACHINE_BUILDER_HPP__
6 #define __RD_STATE_MACHINE_BUILDER_HPP__
7 
8 #include <string>
9 #include <vector>
10 #include <map>
11 #include <utility>
12 
13 #include "State.hpp"
14 #include "StateDirector.hpp"
15 #include "StateMachine.hpp"
16 
17 namespace rd {
18 
26 {
27  public:
29 
35  bool setDirectorType(const std::string& type);
36 
38  bool setInitialState(int initial_state_id);
39 
40 
46  int addState(State *state);
47 
54  bool addTransition(int origin_id, int destination_id, int condition);
55 
68 
69  protected:
76  StateDirector * createStateDirector(const std::string &type, State* state);
77 
78  private:
79  std::vector<State *> states;
80  std::vector<StateDirector *> stateDirectors;
87  std::map< int, std::vector<std::pair<int, int> > > transition_table;
88 
89  std::string type;
90  int initial_state_id;
91 };
92 }
93 #endif // __RD_STATE_MACHINE_BUILDER_HPP__
rd::StateMachineBuilder::addTransition
bool addTransition(int origin_id, int destination_id, int condition)
Adds a transition from one state to other one depending on a condition.
Definition: StateMachineBuilder.cpp:37
rd
The main, catch-all namespace for Robot Devastation.
Definition: groups.dox:4
rd::StateMachineBuilder::setInitialState
bool setInitialState(int initial_state_id)
Configure the initial state of the FiniteStateMachine.
Definition: StateMachineBuilder.cpp:25
rd::StateMachineBuilder::setDirectorType
bool setDirectorType(const std::string &type)
Select the type of StateDirector to be used.
Definition: StateMachineBuilder.cpp:19
rd::FiniteStateMachine
Class implementing a finite state machine.
Definition: StateMachine.hpp:19
rd::StateMachineBuilder::buildStateMachine
FiniteStateMachine * buildStateMachine()
Creates a FiniteStateMachine.
Definition: StateMachineBuilder.cpp:65
rd::StateMachineBuilder::transition_table
std::map< int, std::vector< std::pair< int, int > > > transition_table
Stores the transitions of the fsm.
Definition: StateMachineBuilder.hpp:87
rd::State
Base class for each of the states of a FiniteStateMachine.
Definition: State.hpp:18
rd::StateMachineBuilder::createStateDirector
StateDirector * createStateDirector(const std::string &type, State *state)
Factory method to create a StateDirector from the type string.
Definition: StateMachineBuilder.cpp:114
rd::StateMachineBuilder::addState
int addState(State *state)
Adds a State to the FiniteStateMachine.
Definition: StateMachineBuilder.cpp:31
rd::StateMachineBuilder
Class that helps with the creation of FiniteStateMachine.
Definition: StateMachineBuilder.hpp:25
rd::StateDirector
A base class for controlling flow of States of a Finite State Machine.
Definition: StateDirector.hpp:19