MIRA
Transition.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Redistribution and modification of this code is strictly prohibited.
9  *
10  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
11  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
12  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
13  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14  *
15  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
16  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
18  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
19  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
20  */
21 
30 #ifndef _MIRA_TRANSITION_H_
31 #define _MIRA_TRANSITION_H_
32 
33 #include <string>
34 #include <list>
35 #include <map>
36 
37 #ifndef Q_MOC_RUN
38 #include <boost/shared_ptr.hpp>
39 #endif
40 
41 #include <sm/Event.h>
42 #include <sm/TransitionTarget.h>
43 
44 namespace mira { namespace sm {
45 
47 
49 {
50 public:
51  enum Type
52  {
55  };
56 
58  source(s) {}
59 
60  bool matchEvent(const std::string& event) const
61  {
62  if (event.empty())
63  return false;
64  // if one of the event descriptors is * we match any events name
65  if (std::find(events.begin(), events.end(), "*") != events.end())
66  return true;
67 
68  // check for each event if it is a substring of the events name
69  for(std::size_t i=0; i<events.size(); ++i)
70  {
71  if (events[i].length() > event.length())
72  continue;
73  if (events[i] == event)
74  return true;
75  std::size_t p = event.find('.');
76  while (p!=std::string::npos)
77  {
78  if (events[i] == event.substr(0, p))
79  return true;
80  p = event.find('.', p+1);
81  }
82  }
83  return false;
84  }
85 
86  std::vector<std::string> events;
87  std::string condition;
88  std::string target;
92 };
93 
95 
96 }} // namespace
97 
98 #endif
Definition: Transition.h:48
boost::shared_ptr< TransitionTarget > TransitionTargetPtr
Definition: TransitionTarget.h:54
Type
Definition: Transition.h:51
Definition: Transition.h:53
static constexpr size_t npos
sibling_iterator iterator
Type type
Definition: Transition.h:89
Definition: Transition.h:54
Transition(TransitionTargetPtr s)
Definition: Transition.h:57
An event of the SCXML based state machine implementation.
TODO Add description.
std::vector< std::string > events
Definition: Transition.h:86
bool matchEvent(const std::string &event) const
Definition: Transition.h:60
XMLDom::iterator node
Definition: Transition.h:91
std::string condition
Definition: Transition.h:87
TransitionTargetPtr source
Definition: Transition.h:90
std::string target
Definition: Transition.h:88