23 using namespace boost::property_tree;
28 std::string init_state_name;
29 for (
const ptree::value_type& state_itr : pt.get_child(
"state_machine"))
31 if(state_itr.first ==
"init_state")
33 init_state_name = state_itr.second.get<std::string>(
"<xmlattr>.name");
35 if(state_itr.first ==
"state_machine_name")
37 name_ = state_itr.second.get<std::string>(
"<xmlattr>.name");
40 for (
const ptree::value_type& state_itr : pt.get_child(
"state_machine"))
42 if(state_itr.first ==
"transition")
44 std::string from_state_name = state_itr.second.get<std::string>(
"<xmlattr>.from");
45 std::string to_state_name = state_itr.second.get<std::string>(
"<xmlattr>.to");
46 std::string trigger_event_name = state_itr.second.get<std::string>(
"<xmlattr>.name");
47 addTransition(from_state_name, to_state_name, trigger_event_name);
80 std::lock_guard<std::mutex> lock(
mtx_);
82 for (
auto first = vertex_range.first, last = vertex_range.second; first != last; ++first)
103 std::lock_guard<std::mutex> lock(
mtx_);
108 if(from_state_name != to_state_name)
110 bool from_state_found =
false;
111 bool to_state_found =
false;
112 for (
auto first = vertex_range.first, last = vertex_range.second; first != last; ++first)
117 from_state_found =
true;
122 to_state_found =
true;
126 if(!from_state_found)
138 bool inserted =
false;
139 boost::tie(transition, inserted) = boost::add_edge(from_state, to_state,
state_graph_);
140 state_graph_[transition].trigger_event = trigger_event_name;
146 bool state_found =
false;
147 for (
auto first = vertex_range.first, last = vertex_range.second; first != last; ++first)
164 bool inserted =
false;
165 boost::tie(transition, inserted) = boost::add_edge(from_state, to_state,
state_graph_);
166 state_graph_[transition].trigger_event = trigger_event_name;
180 std::lock_guard<std::mutex> lock(
mtx_);
181 std::vector<std::string> ret;
198 std::lock_guard<std::mutex> lock(
mtx_);
199 std::vector<std::string> ret;
218 std::lock_guard<std::mutex> lock(
mtx_);
223 if(trigger_event_name ==
state_graph_[*ei].trigger_event)
226 for (
auto first = vertex_range.first, last = vertex_range.second; first != last; ++first)
248 std::lock_guard<std::mutex> lock(
mtx_);
250 std::vector<std::string> possible_transitions;
255 possible_transitions.push_back(
state_graph_[*ei].trigger_event);
257 std::vector<std::string> possible_transition_states;
262 possible_transition_states.push_back(
state_graph_[*vi].name);
264 StateInfo ret(current_state, possible_transition_states, possible_transitions);
285 std::lock_guard<std::mutex> lock(
mtx_);
286 std::stringstream sstream;
289 return sstream.str();
299 std::lock_guard<std::mutex> lock(
mtx_);
300 std::ofstream
f(dot_filename.c_str());
bool setCurrentState(std::string current_state)
Function for setting Current State Infomation.
std::vector< std::string > getPossibeTransitions()
Function for getting possible transition trigger event.
EdgeWriter< Map > edge_writer_(Map &map)
void addTransition(std::string from_state_name, std::string to_state_name, std::string trigger_event_name)
add Transition function for the State Machine
boost::graph_traits< graph_t >::out_edge_iterator out_edge_iterator_t
StateInfo getStateInfo()
Function getting current state info.
bool tryTransition(std::string trigger_event_name)
Try transition from trigger event.
std::string getName()
get name of the state machine
std::string getCurrentState()
Function getting current state name.
std::string getDotString()
Function getting dot string which describe state machine in std::string format.
NodeWriter< Map > node_writer_(Map &map, std::string current_state)
GraphWriter graph_writer_
~StateMachine()
Destroy the State Machine:: State Machine object.
Struct for State Infomation.
State Machine Library using Boost::Graph.
graph_t::vertex_descriptor vertex_t
vertex type for State Machine Class (State)
std::vector< std::string > getPossibeTransitionStates()
Function for getting possible transition states.
graph_t::edge_descriptor edge_t
edge type for State Machine Class (State Transition)
void drawStateMachine(std::string dot_filename)
Function saving state machine in .dot format.
StateMachine(std::string xml_string)
Construct a new State Machine:: State Machine object.
boost::graph_traits< graph_t >::adjacency_iterator adjacency_iterator_t