FastMicroStep.h
Go to the documentation of this file.
1 
20 #ifndef FASTMICROSTEP_H_065FE1F7
21 #define FASTMICROSTEP_H_065FE1F7
22 
23 //#define USCXML_VERBOSE 1
24 
25 #include "uscxml/config.h"
26 #include "uscxml/Common.h"
27 #include "uscxml/util/DOM.h" // X
28 
29 #include <vector>
30 #include <map>
31 #include <set>
32 #include "MicroStepImpl.h"
33 
34 #include <boost/dynamic_bitset.hpp>
35 
36 //#undef WITH_CACHE_FILES
37 
38 #ifdef _WIN32
39 #define BITSET_BLOCKTYPE size_t
40 #else
41 #define BITSET_BLOCKTYPE
42 #endif
43 
44 namespace uscxml {
45 
50 class FastMicroStep : public MicroStepImpl {
51 public:
53  virtual ~FastMicroStep();
54  virtual std::shared_ptr<MicroStepImpl> create(MicroStepCallbacks* callbacks);
55 
56  virtual InterpreterState step(size_t blockMs);
57  virtual void reset();
58  virtual bool isInState(const std::string& stateId);
59  virtual std::list<XERCESC_NS::DOMElement*> getConfiguration();
60  void markAsCancelled();
61 
62  virtual void deserialize(const Data& encodedState);
63  virtual Data serialize();
64 
65 protected:
66  class Transition {
67  public:
68  Transition() : element(NULL), source(0), onTrans(NULL), type(0) {}
69 
70  XERCESC_NS::DOMElement* element;
71  boost::dynamic_bitset<BITSET_BLOCKTYPE> conflicts;
72  boost::dynamic_bitset<BITSET_BLOCKTYPE> exitSet;
73 
74  uint32_t source;
75  boost::dynamic_bitset<BITSET_BLOCKTYPE> target;
76 
77  XERCESC_NS::DOMElement* onTrans;
78 
79  std::string event;
80  std::string cond;
81 
82  unsigned char type;
83 
84  };
85 
86  class State {
87  public:
88  State() : element(NULL), parent(0), documentOrder(0), doneData(NULL), type(0) {}
89 
90  XERCESC_NS::DOMElement* element;
91  boost::dynamic_bitset<BITSET_BLOCKTYPE> completion;
92  boost::dynamic_bitset<BITSET_BLOCKTYPE> children;
93  boost::dynamic_bitset<BITSET_BLOCKTYPE> ancestors;
94  uint32_t parent;
95  uint32_t documentOrder;
96 
97  std::list<XERCESC_NS::DOMElement*> data;
98  std::list<XERCESC_NS::DOMElement*> invoke;
99  std::list<XERCESC_NS::DOMElement*> onEntry;
100  std::list<XERCESC_NS::DOMElement*> onExit;
101  XERCESC_NS::DOMElement* doneData;
102 
103  unsigned char type;
104  };
105 
107  public:
108  std::map<const XERCESC_NS::DOMElement*, std::list<XERCESC_NS::DOMElement*> > exitSet;
109  };
110 
111  virtual void init(XERCESC_NS::DOMElement* scxml);
112 
113  std::list<XERCESC_NS::DOMElement*> getCompletion(const XERCESC_NS::DOMElement* state);
114 
115  unsigned char _flags;
116  std::map<std::string, int> _stateIds;
117 
118  std::vector<State*> _states;
119  std::vector<Transition*> _transitions;
120  std::list<XERCESC_NS::DOMElement*> _globalScripts;
121 
122  boost::dynamic_bitset<BITSET_BLOCKTYPE> _configuration;
123  boost::dynamic_bitset<BITSET_BLOCKTYPE> _invocations;
124  boost::dynamic_bitset<BITSET_BLOCKTYPE> _history;
125  boost::dynamic_bitset<BITSET_BLOCKTYPE> _initializedData;
126 
127  std::set<boost::dynamic_bitset<BITSET_BLOCKTYPE> > _microstepConfigurations;
128 
129  Binding _binding;
130  XERCESC_NS::DOMElement* _scxml;
131  X _xmlPrefix;
132  X _xmlNS;
133 
134  bool _isInitialized;
135  bool _isCancelled;
136  Event _event; // we do not care about the event's representation
137 
138 private:
139  std::list<XERCESC_NS::DOMElement*> getHistoryCompletion(const XERCESC_NS::DOMElement* state);
140  void resortStates(XERCESC_NS::DOMElement* node, const X& xmlPrefix);
141 
142  bool conflictsCached(const XERCESC_NS::DOMElement* t1, const XERCESC_NS::DOMElement* t2, const XERCESC_NS::DOMElement* root);
143 
144  std::string toBase64(const boost::dynamic_bitset<BITSET_BLOCKTYPE>& bitset);
145  boost::dynamic_bitset<BITSET_BLOCKTYPE> fromBase64(const std::string& encoded);
146 
147  std::list<XERCESC_NS::DOMElement*> getExitSetCached(const XERCESC_NS::DOMElement* transition,
148  const XERCESC_NS::DOMElement* root);
149 
150  CachedPredicates _cache;
151 
152 #ifdef USCXML_VERBOSE
153  void printStateNames(const boost::dynamic_bitset<BITSET_BLOCKTYPE>& bitset);
154 #endif
155 
156 };
157 
158 }
159 
160 #endif /* end of include guard: FASTMICROSTEP_H_065FE1F7 */
161 
Definition: FastMicroStep.h:50
Definition: MicroStepImpl.h:73
Definition: Breakpoint.cpp:26
Definition: MicroStepImpl.h:40
Definition: Event.h:94
virtual void reset()
Reset state machine.
Definition: FastMicroStep.cpp:1146
virtual InterpreterState step(size_t blockMs)
Definition: FastMicroStep.cpp:629
Definition: FastMicroStep.h:66
virtual void init(XERCESC_NS::DOMElement *scxml)
Definition: FastMicroStep.cpp:230
Definition: FastMicroStep.h:86
Definition: Data.h:44
Definition: FastMicroStep.h:106
Definition: DOM.h:133