state_machine.h
Go to the documentation of this file.
1 #ifndef StateMachine_H_INCLUDED
2 #define StateMachine_H_INCLUDED
3 
15 //headers in boost
16 #include <boost/graph/adjacency_list.hpp>
17 #include <boost/graph/graph_utility.hpp>
18 #include <boost/property_tree/ptree.hpp>
19 #include <boost/property_tree/xml_parser.hpp>
20 #include <boost/foreach.hpp>
21 #include <boost/lexical_cast.hpp>
22 #include <boost/graph/graphviz.hpp>
23 
24 //headers in STL
25 #include <mutex>
26 
27 //headers in this package
29 
35 {
36  std::string trigger_event;
37  std::string from_state;
38  std::string to_state;
39 };
40 
46 {
47  std::string name;
48 };
49 
54 typedef boost::adjacency_list<boost::listS, boost::vecS, boost::bidirectionalS, StateProperty, TransitionProperty> graph_t;
59 typedef graph_t::vertex_descriptor vertex_t;
64 typedef graph_t::edge_descriptor edge_t;
65 typedef boost::graph_traits<graph_t>::adjacency_iterator adjacency_iterator_t;
66 typedef boost::graph_traits<graph_t>::out_edge_iterator out_edge_iterator_t;
67 
72 struct StateInfo
73 {
78  const std::vector<std::string> possibe_transition_states;
83  const std::vector<std::string> possibe_transitions;
88  const std::string current_state;
89  StateInfo(std::string current_state_,
90  std::vector<std::string> possibe_transition_states_,
91  std::vector<std::string> possibe_transitions_)
92  : current_state(current_state_),
93  possibe_transition_states(possibe_transition_states_),
94  possibe_transitions(possibe_transitions_)
95  {
96 
97  }
98 };
99 
105 {
106 public:
107  StateMachine(std::string xml_string);
108  ~StateMachine();
109  bool tryTransition(std::string trigger_event_name);
110  bool setCurrentState(std::string current_state);
111  std::vector<std::string> getPossibeTransitionStates();
112  std::vector<std::string> getPossibeTransitions();
113  std::string getCurrentState();
114  StateInfo getStateInfo();
115  void drawStateMachine(std::string dot_filename);
116  std::string getDotString();
117  std::string getName();
118 private:
119  void addTransition(std::string from_state_name, std::string to_state_name, std::string trigger_event_name);
120  std::mutex mtx_;
123  std::string name_;
124  template <typename Map>
125  NodeWriter<Map> node_writer_(Map& map,std::string current_state){ return NodeWriter<Map>(map,current_state); }
126  template <typename Map>
127  EdgeWriter<Map> edge_writer_(Map& map){ return EdgeWriter<Map>(map); }
129 };
130 #endif //StateMachine_H_INCLUDED
State Machine Class using Boost::Graph.
EdgeWriter< Map > edge_writer_(Map &map)
boost::graph_traits< graph_t >::out_edge_iterator out_edge_iterator_t
Definition: state_machine.h:66
std::string getName(void *handle)
std::string name
Definition: state_machine.h:47
boost::adjacency_list< boost::listS, boost::vecS, boost::bidirectionalS, StateProperty, TransitionProperty > graph_t
Boost::Graph type for State Machine Class.
Definition: state_machine.h:54
const std::vector< std::string > possibe_transition_states
Possibe Transition States from the Current State.
Definition: state_machine.h:78
std::string name_
vertex_t current_state_
std::string trigger_event
Definition: state_machine.h:36
graph_t state_graph_
std::string from_state
Definition: state_machine.h:37
std::mutex mtx_
State Transition Property for State Machine Class.
Definition: state_machine.h:34
StateInfo(std::string current_state_, std::vector< std::string > possibe_transition_states_, std::vector< std::string > possibe_transitions_)
Definition: state_machine.h:89
NodeWriter< Map > node_writer_(Map &map, std::string current_state)
const std::vector< std::string > possibe_transitions
Possibe Transitions from the Current State.
Definition: state_machine.h:83
GraphWriter graph_writer_
Struct for State Infomation.
Definition: state_machine.h:72
std::string to_state
Definition: state_machine.h:38
graph_t::vertex_descriptor vertex_t
vertex type for State Machine Class (State)
Definition: state_machine.h:59
const std::string current_state
Current State.
Definition: state_machine.h:88
graph_t::edge_descriptor edge_t
edge type for State Machine Class (State Transition)
Definition: state_machine.h:64
State Property for State Machine Class.
Definition: state_machine.h:45
boost::graph_traits< graph_t >::adjacency_iterator adjacency_iterator_t
Definition: state_machine.h:65


rostate_machine
Author(s):
autogenerated on Wed Sep 4 2019 05:19:52