/** * @file * @author 2012-2016 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) * @copyright Simplified BSD * * @cond * This program is free software: you can redistribute it and/or modify * it under the terms of the FreeBSD license as published by the FreeBSD * project. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the FreeBSD license along with this * program. If not, see . * @endcond */ #ifndef FASTMICROSTEP_H_065FE1F7 #define FASTMICROSTEP_H_065FE1F7 //#define USCXML_VERBOSE 1 #include "uscxml/Common.h" #include "uscxml/util/DOM.h" // X #include #include #include #include "MicroStepImpl.h" #include //#undef WITH_CACHE_FILES #ifdef _WIN32 #define BITSET_BLOCKTYPE size_t #else #define BITSET_BLOCKTYPE #endif namespace uscxml { /** * @ingroup microstep * @ingroup impl * * MicroStep implementation backed by indexed bit-arrays. */ class FastMicroStep : public MicroStepImpl { public: FastMicroStep(MicroStepCallbacks* callbacks); virtual ~FastMicroStep(); virtual std::shared_ptr create(MicroStepCallbacks* callbacks); std::string getName() { return "fast"; } virtual InterpreterState step(size_t blockMs); virtual void reset(); virtual bool isInState(const std::string& stateId); virtual std::list getConfiguration(); void markAsCancelled(); virtual void deserialize(const Data& encodedState); virtual Data serialize(); protected: FastMicroStep() {}; // only for factory class Transition { public: Transition() : element(NULL), source(0), onTrans(NULL), type(0) {} XERCESC_NS::DOMElement* element; boost::dynamic_bitset conflicts; boost::dynamic_bitset exitSet; uint32_t source; boost::dynamic_bitset target; XERCESC_NS::DOMElement* onTrans; std::string event; std::string cond; unsigned char type; }; class State { public: State() : element(NULL), parent(0), documentOrder(0), doneData(NULL), type(0) {} XERCESC_NS::DOMElement* element; boost::dynamic_bitset completion; boost::dynamic_bitset children; boost::dynamic_bitset ancestors; uint32_t parent; uint32_t documentOrder; std::list data; std::list invoke; std::list onEntry; std::list onExit; XERCESC_NS::DOMElement* doneData; unsigned char type; }; class CachedPredicates { public: std::map > exitSet; }; virtual void init(XERCESC_NS::DOMElement* scxml); std::list getCompletion(const XERCESC_NS::DOMElement* state); unsigned char _flags; std::map _stateIds; std::vector _states; std::vector _transitions; std::list _globalScripts; boost::dynamic_bitset _configuration; boost::dynamic_bitset _invocations; boost::dynamic_bitset _history; boost::dynamic_bitset _initializedData; std::set > _microstepConfigurations; Binding _binding; XERCESC_NS::DOMElement* _scxml; X _xmlPrefix; X _xmlNS; bool _isInitialized; bool _isCancelled; Event _event; // we do not care about the event's representation private: std::list getHistoryCompletion(const XERCESC_NS::DOMElement* state); void resortStates(XERCESC_NS::DOMElement* node, const X& xmlPrefix); bool conflictsCached(const XERCESC_NS::DOMElement* t1, const XERCESC_NS::DOMElement* t2, const XERCESC_NS::DOMElement* root); ///< overrides implementation Predicates::conflicts for speed std::string toBase64(const boost::dynamic_bitset& bitset); boost::dynamic_bitset fromBase64(const std::string& encoded); std::list getExitSetCached(const XERCESC_NS::DOMElement* transition, const XERCESC_NS::DOMElement* root); CachedPredicates _cache; boost::dynamic_bitset _exitSet; boost::dynamic_bitset _entrySet; boost::dynamic_bitset _targetSet; boost::dynamic_bitset _tmpStates; boost::dynamic_bitset _conflicts; boost::dynamic_bitset _transSet; #ifdef USCXML_VERBOSE void printStateNames(const boost::dynamic_bitset& bitset); #endif friend class Factory; }; } #endif /* end of include guard: FASTMICROSTEP_H_065FE1F7 */