From 13faf5337e2d144b530e5b0bcf07480ef29471ec Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Tue, 20 Mar 2018 10:15:44 +0100 Subject: Reduced xerces deps and new transition callback --- contrib/cmake/FindUSCXML.cmake | 10 +- examples/cpp/library/lambdas/CMakeLists.txt | 11 +- examples/cpp/library/lambdas/main.cpp | 36 ++++- examples/cpp/library/simple/CMakeLists.txt | 4 +- .../swig/wrapped/WrappedInterpreterMonitor.cpp | 4 +- .../swig/wrapped/WrappedInterpreterMonitor.h | 2 + src/uscxml/Interpreter.cpp | 4 +- src/uscxml/debug/Breakpoint.cpp | 2 +- src/uscxml/debug/Breakpoint.h | 5 +- src/uscxml/debug/Debugger.cpp | 6 +- src/uscxml/debug/Debugger.h | 4 +- src/uscxml/interpreter/FastMicroStep.cpp | 21 ++- src/uscxml/interpreter/InterpreterMonitor.h | 15 +- src/uscxml/interpreter/LargeMicroStep.cpp | 21 ++- src/uscxml/util/Convenience.h | 2 + src/uscxml/util/DOM.cpp | 76 ++++++++++ src/uscxml/util/DOM.h | 162 ++------------------- test/src/test-stress.cpp | 4 +- 18 files changed, 204 insertions(+), 185 deletions(-) diff --git a/contrib/cmake/FindUSCXML.cmake b/contrib/cmake/FindUSCXML.cmake index bf3605d..75981b3 100644 --- a/contrib/cmake/FindUSCXML.cmake +++ b/contrib/cmake/FindUSCXML.cmake @@ -51,7 +51,7 @@ else() ENV USCXML_LIB_DIR ) if (USCXML_LIBRARY_RELEASE) - list(APPEND USCXML_LIBRARIES optimized USCXML_LIBRARY_RELEASE) + list(APPEND USCXML_LIBRARIES optimized ${USCXML_LIBRARY_RELEASE}) endif() endif() @@ -73,7 +73,13 @@ else() ENV USCXML_LIB_DIR ) if ("${USCXML_LIBRARY_DEBUG}") - list(APPEND USCXML_LIBRARIES debug USCXML_LIBRARY_DEBUG) + list(APPEND USCXML_LIBRARIES debug ${USCXML_LIBRARY_DEBUG}) + else() + # on unices, we can add release as debug + if (USCXML_LIBRARY_RELEASE) + list(APPEND USCXML_LIBRARIES debug ${USCXML_LIBRARY_RELEASE}) + endif() + endif() endif() diff --git a/examples/cpp/library/lambdas/CMakeLists.txt b/examples/cpp/library/lambdas/CMakeLists.txt index c062e64..f2dec76 100644 --- a/examples/cpp/library/lambdas/CMakeLists.txt +++ b/examples/cpp/library/lambdas/CMakeLists.txt @@ -1,10 +1,15 @@ cmake_minimum_required(VERSION 2.8.6) -project(simple-scxml) +project(lambda-scxml) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "/usr/local/share/uscxml/cmake/") find_package(USCXML REQUIRED) +# message(FATAL_ERROR "USCXML_LIBRARIES: ${USCXML_LIBRARIES}") + include_directories(${USCXML_INCLUDE_DIR}) -add_executable(simple main.cpp) -target_link_libraries(simple ${USCXML_LIBRARIES}) \ No newline at end of file +add_executable(lambdas main.cpp) +target_link_libraries(lambdas ${USCXML_LIBRARIES}) \ No newline at end of file diff --git a/examples/cpp/library/lambdas/main.cpp b/examples/cpp/library/lambdas/main.cpp index 316576b..33440fb 100644 --- a/examples/cpp/library/lambdas/main.cpp +++ b/examples/cpp/library/lambdas/main.cpp @@ -3,13 +3,39 @@ int main(int argc, char *argv[]) { - if (argc < 2) { - std::cerr << "Expected URL with SCXML document as first argument" << std::endl; - return -1; - } + std::string scxmlURL("https://raw.githubusercontent.com/tklab-tud/uscxml/master/test/w3c/null/test436.scxml"); - uscxml::Interpreter sc = uscxml::Interpreter::fromURL(argv[1]); + uscxml::Interpreter sc = uscxml::Interpreter::fromURL(scxmlURL); uscxml::InterpreterState state; + + sc.on().enterState([](const std::string& sessionId, + const std::string& stateName, + const xercesc_3_1::DOMElement* state) { + std::cout << "Entered " << stateName << std::endl; + }); + + sc.on().exitState([](const std::string& sessionId, + const std::string& stateName, + const xercesc_3_1::DOMElement* state) { + std::cout << "Exited " << stateName << std::endl; + }); + + sc.on().transition([](const std::string& sessionId, + const std::string& targetList, + const xercesc_3_1::DOMElement* transition) { + std::cout << "Transition to " << targetList << std::endl; + }); + + sc.on().completion([](const std::string& sessionId){ + std::cout << "Completed!" << std::endl; + }); + + sc.on().executeContent([](const std::string& sessionId, + const xercesc_3_1::DOMElement* element){ + std::cout << "Executing content" << std::endl; + + }); + while ((state = sc.step()) != uscxml::USCXML_FINISHED) { } diff --git a/examples/cpp/library/simple/CMakeLists.txt b/examples/cpp/library/simple/CMakeLists.txt index c062e64..475b4b2 100644 --- a/examples/cpp/library/simple/CMakeLists.txt +++ b/examples/cpp/library/simple/CMakeLists.txt @@ -1,10 +1,12 @@ cmake_minimum_required(VERSION 2.8.6) project(simple-scxml) +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "/usr/local/share/uscxml/cmake/") find_package(USCXML REQUIRED) - include_directories(${USCXML_INCLUDE_DIR}) add_executable(simple main.cpp) target_link_libraries(simple ${USCXML_LIBRARIES}) \ No newline at end of file diff --git a/src/bindings/swig/wrapped/WrappedInterpreterMonitor.cpp b/src/bindings/swig/wrapped/WrappedInterpreterMonitor.cpp index 2c501a1..a2fac3c 100644 --- a/src/bindings/swig/wrapped/WrappedInterpreterMonitor.cpp +++ b/src/bindings/swig/wrapped/WrappedInterpreterMonitor.cpp @@ -76,7 +76,7 @@ void WrappedInterpreterMonitor::afterUninvoking(const std::string& sessionId, co afterUninvoking(DOMUtils::xPathForNode(invoker), invokeId, ss.str()); } -void WrappedInterpreterMonitor::beforeTakingTransition(const std::string& sessionId, const XERCESC_NS::DOMElement* transition) { +void WrappedInterpreterMonitor::beforeTakingTransition(const std::string& sessionId, const std::string& targetList, const XERCESC_NS::DOMElement* transition) { XERCESC_NS::DOMElement* sourceState = getSourceState(transition); const XERCESC_NS::DOMElement* root = DOMUtils::getNearestAncestor(transition, "scxml"); @@ -93,7 +93,7 @@ void WrappedInterpreterMonitor::beforeTakingTransition(const std::string& sessio beforeTakingTransition(DOMUtils::xPathForNode(transition), ATTR_CAST(sourceState, kXMLCharId), targets, ss.str()); } -void WrappedInterpreterMonitor::afterTakingTransition(const std::string& sessionId, const XERCESC_NS::DOMElement* transition) { +void WrappedInterpreterMonitor::afterTakingTransition(const std::string& sessionId, const std::string& targetList, const XERCESC_NS::DOMElement* transition) { XERCESC_NS::DOMElement* sourceState = getSourceState(transition); const XERCESC_NS::DOMElement* root = DOMUtils::getNearestAncestor(transition, "scxml"); diff --git a/src/bindings/swig/wrapped/WrappedInterpreterMonitor.h b/src/bindings/swig/wrapped/WrappedInterpreterMonitor.h index cd4404b..532877b 100644 --- a/src/bindings/swig/wrapped/WrappedInterpreterMonitor.h +++ b/src/bindings/swig/wrapped/WrappedInterpreterMonitor.h @@ -92,6 +92,7 @@ public: void beforeTakingTransition(const std::string& sessionId, + const std::string& targetList, const XERCESC_NS::DOMElement* transition); virtual void beforeTakingTransition(const std::string& xpath, const std::string& source, @@ -99,6 +100,7 @@ public: const std::string& transitionXML) {} void afterTakingTransition(const std::string& sessionId, + const std::string& targetList, const XERCESC_NS::DOMElement* transition); virtual void afterTakingTransition(const std::string& xpath, const std::string& source, diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index 6146546..0972e0f 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -287,7 +287,9 @@ static void printNodeSet(Logger& logger, const std::list lock(_mutex); LOG(_logger, USCXML_VERBATIM) << "Transition: " << uscxml::DOMUtils::xPathForNode(transition) << std::endl; } diff --git a/src/uscxml/debug/Breakpoint.cpp b/src/uscxml/debug/Breakpoint.cpp index 7b9d5c9..97dedc1 100644 --- a/src/uscxml/debug/Breakpoint.cpp +++ b/src/uscxml/debug/Breakpoint.cpp @@ -264,4 +264,4 @@ bool Breakpoint::matches(Interpreter interpreter, const Breakpoint& other) const return true; } -} \ No newline at end of file +} diff --git a/src/uscxml/debug/Breakpoint.h b/src/uscxml/debug/Breakpoint.h index a9d96f8..6976ed1 100644 --- a/src/uscxml/debug/Breakpoint.h +++ b/src/uscxml/debug/Breakpoint.h @@ -23,12 +23,11 @@ #include // for string #include "uscxml/Common.h" // for USCXML_API #include "uscxml/Interpreter.h" -//#include "DOM/Element.hpp" // for Element #include "uscxml/messages/Data.h" // for Data // forward declare namespace XERCESC_NS { -class DOMElement; +class DOMNode; } namespace uscxml { @@ -77,7 +76,7 @@ public: Subject subject; Action action; - const XERCESC_NS::DOMElement* element = NULL; + const XERCESC_NS::DOMNode* element = NULL; std::string invokeId; std::string invokeType; diff --git a/src/uscxml/debug/Debugger.cpp b/src/uscxml/debug/Debugger.cpp index fa173f0..0d18833 100644 --- a/src/uscxml/debug/Debugger.cpp +++ b/src/uscxml/debug/Debugger.cpp @@ -18,8 +18,8 @@ */ #include "uscxml/debug/Debugger.h" -#include "uscxml/util/DOM.h" #include "uscxml/util/Predicates.h" +#include "uscxml/util/DOM.h" #include "uscxml/debug/DebugSession.h" namespace uscxml { @@ -90,10 +90,10 @@ std::list Debugger::getQualifiedTransBreakpoints(const std::string& return breakpoints; } -void Debugger::beforeTakingTransition(const std::string& sessionId, const XERCESC_NS::DOMElement* transition) { +void Debugger::beforeTakingTransition(const std::string& sessionId, const std::string& targetList, const XERCESC_NS::DOMElement* transition) { handleTransition(sessionId, transition, Breakpoint::BEFORE); } -void Debugger::afterTakingTransition(const std::string& sessionId, const XERCESC_NS::DOMElement* transition) { +void Debugger::afterTakingTransition(const std::string& sessionId, const std::string& targetList, const XERCESC_NS::DOMElement* transition) { handleTransition(sessionId, transition, Breakpoint::AFTER); } void Debugger::beforeExecutingContent(const std::string& sessionId, const XERCESC_NS::DOMElement* execContent) { diff --git a/src/uscxml/debug/Debugger.h b/src/uscxml/debug/Debugger.h index ec00a95..9b9aaf1 100644 --- a/src/uscxml/debug/Debugger.h +++ b/src/uscxml/debug/Debugger.h @@ -63,8 +63,8 @@ public: virtual void afterExecutingContent(const std::string& sessionId, const XERCESC_NS::DOMElement* execContent); virtual void beforeUninvoking(const std::string& sessionId, const XERCESC_NS::DOMElement* invokeElem, const std::string& invokeid); virtual void afterUninvoking(const std::string& sessionId, const XERCESC_NS::DOMElement* invokeElem, const std::string& invokeid); - virtual void beforeTakingTransition(const std::string& sessionId, const XERCESC_NS::DOMElement* transition); - virtual void afterTakingTransition(const std::string& sessionId, const XERCESC_NS::DOMElement* transition); + virtual void beforeTakingTransition(const std::string& sessionId, const std::string& targetList, const XERCESC_NS::DOMElement* transition); + virtual void afterTakingTransition(const std::string& sessionId, const std::string& targetList, const XERCESC_NS::DOMElement* transition); virtual void beforeEnteringState(const std::string& sessionId, const std::string& stateName, const XERCESC_NS::DOMElement* state); virtual void afterEnteringState(const std::string& sessionId, const std::string& stateName, const XERCESC_NS::DOMElement* state); virtual void beforeInvoking(const std::string& sessionId, const XERCESC_NS::DOMElement* invokeElem, const std::string& invokeid); diff --git a/src/uscxml/interpreter/FastMicroStep.cpp b/src/uscxml/interpreter/FastMicroStep.cpp index 78aada9..783ceab 100644 --- a/src/uscxml/interpreter/FastMicroStep.cpp +++ b/src/uscxml/interpreter/FastMicroStep.cpp @@ -1178,7 +1178,10 @@ ESTABLISH_ENTRYSET: i = _transSet.find_first(); while(i != boost::dynamic_bitset::npos) { if ((USCXML_GET_TRANS(i).type & (USCXML_TRANS_HISTORY | USCXML_TRANS_INITIAL)) == 0) { - USCXML_MONITOR_CALLBACK1(monitors, beforeTakingTransition, USCXML_GET_TRANS(i).element); + USCXML_MONITOR_CALLBACK2(monitors, + beforeTakingTransition, + (HAS_ATTR(USCXML_GET_TRANS(i).element, kXMLCharTarget) ? ATTR(USCXML_GET_TRANS(i).element, kXMLCharTarget) : ""), + USCXML_GET_TRANS(i).element); if (USCXML_GET_TRANS(i).onTrans != NULL) { @@ -1190,7 +1193,11 @@ ESTABLISH_ENTRYSET: } } - USCXML_MONITOR_CALLBACK1(monitors, afterTakingTransition, USCXML_GET_TRANS(i).element); + USCXML_MONITOR_CALLBACK2(monitors, + afterTakingTransition, + (HAS_ATTR(USCXML_GET_TRANS(i).element, kXMLCharTarget) ? ATTR(USCXML_GET_TRANS(i).element, kXMLCharTarget) : ""), + USCXML_GET_TRANS(i).element); + } i = _transSet.find_next(i); @@ -1249,7 +1256,10 @@ ESTABLISH_ENTRYSET: if unlikely((USCXML_GET_TRANS(j).type & (USCXML_TRANS_HISTORY | USCXML_TRANS_INITIAL)) && USCXML_GET_STATE(USCXML_GET_TRANS(j).source).parent == i) { - USCXML_MONITOR_CALLBACK1(monitors, beforeTakingTransition, USCXML_GET_TRANS(j).element); + USCXML_MONITOR_CALLBACK2(monitors, + beforeTakingTransition, + (HAS_ATTR(USCXML_GET_TRANS(j).element, kXMLCharTarget) ? ATTR(USCXML_GET_TRANS(j).element, kXMLCharTarget) : ""), + USCXML_GET_TRANS(j).element); /* call executable content in transition */ if (USCXML_GET_TRANS(j).onTrans != NULL) { @@ -1260,7 +1270,10 @@ ESTABLISH_ENTRYSET: } } - USCXML_MONITOR_CALLBACK1(monitors, afterTakingTransition, USCXML_GET_TRANS(j).element); + USCXML_MONITOR_CALLBACK2(monitors, + afterTakingTransition, + (HAS_ATTR(USCXML_GET_TRANS(j).element, kXMLCharTarget) ? ATTR(USCXML_GET_TRANS(j).element, kXMLCharTarget) : ""), + USCXML_GET_TRANS(j).element); } j = _transSet.find_next(j); diff --git a/src/uscxml/interpreter/InterpreterMonitor.h b/src/uscxml/interpreter/InterpreterMonitor.h index 64c281c..0bb389e 100644 --- a/src/uscxml/interpreter/InterpreterMonitor.h +++ b/src/uscxml/interpreter/InterpreterMonitor.h @@ -89,8 +89,10 @@ public: const std::string& invokeid) {} virtual void beforeTakingTransition(const std::string& sessionId, + const std::string& targetList, const XERCESC_NS::DOMElement* transition) {} virtual void afterTakingTransition(const std::string& sessionId, + const std::string& targetList, const XERCESC_NS::DOMElement* transition) {} virtual void beforeEnteringState(const std::string& sessionId, @@ -134,7 +136,7 @@ public: StateTransitionMonitor(std::string prefix = "") : _logPrefix(prefix) {} virtual ~StateTransitionMonitor() {} - virtual void beforeTakingTransition(const std::string& sessionId, const XERCESC_NS::DOMElement* transition); + virtual void beforeTakingTransition(const std::string& sessionId, const std::string& targetList, const XERCESC_NS::DOMElement* transition); virtual void beforeExecutingContent(const std::string& sessionId, const XERCESC_NS::DOMElement* element); virtual void onStableConfiguration(const std::string& sessionId); virtual void beforeProcessingEvent(const std::string& sessionId, const uscxml::Event& event); @@ -198,6 +200,7 @@ public: } void transition(std::function callback, bool after = false) { if (after) { @@ -278,8 +281,10 @@ protected: const std::string& invokeid)> _afterUninvoking; std::function _beforeTakingTransition; std::function _afterTakingTransition; std::functiontype & (USCXML_TRANS_HISTORY | USCXML_TRANS_INITIAL)) == 0) { - USCXML_MONITOR_CALLBACK1(monitors, beforeTakingTransition, transition->element); + USCXML_MONITOR_CALLBACK2(monitors, + beforeTakingTransition, + (HAS_ATTR(transition->element, kXMLCharTarget) ? ATTR(transition->element, kXMLCharTarget) : ""), + transition->element); if (transition->onTrans != NULL) { @@ -1072,8 +1075,10 @@ NEXT_DESCENDANT: // do nothing and continue with next block } } - - USCXML_MONITOR_CALLBACK1(monitors, afterTakingTransition, transition->element); + USCXML_MONITOR_CALLBACK2(monitors, + afterTakingTransition, + (HAS_ATTR(transition->element, kXMLCharTarget) ? ATTR(transition->element, kXMLCharTarget) : ""), + transition->element); } } } @@ -1134,7 +1139,10 @@ NEXT_DESCENDANT: _transSet.find(transition) == _transSet.end()) continue; - USCXML_MONITOR_CALLBACK1(monitors, beforeTakingTransition, transition->element); + USCXML_MONITOR_CALLBACK2(monitors, + beforeTakingTransition, + (HAS_ATTR(transition->element, kXMLCharTarget) ? ATTR(transition->element, kXMLCharTarget) : ""), + transition->element); /* call executable content in transition */ if (transition->onTrans != NULL) { @@ -1144,8 +1152,11 @@ NEXT_DESCENDANT: // do nothing and continue with next block } } + USCXML_MONITOR_CALLBACK2(monitors, + afterTakingTransition, + (HAS_ATTR(transition->element, kXMLCharTarget) ? ATTR(transition->element, kXMLCharTarget) : ""), + transition->element); - USCXML_MONITOR_CALLBACK1(monitors, afterTakingTransition, transition->element); } } diff --git a/src/uscxml/util/Convenience.h b/src/uscxml/util/Convenience.h index e3bdb9e..7c39d04 100644 --- a/src/uscxml/util/Convenience.h +++ b/src/uscxml/util/Convenience.h @@ -25,6 +25,8 @@ #include #include +/* this is where node2xpath ought to go as it is most convenient when we forward declare */ + namespace uscxml { inline bool isnan(double x); diff --git a/src/uscxml/util/DOM.cpp b/src/uscxml/util/DOM.cpp index a2d0252..439d47e 100644 --- a/src/uscxml/util/DOM.cpp +++ b/src/uscxml/util/DOM.cpp @@ -390,4 +390,80 @@ std::list DOMUtils::filterChildType(const DOMNode::NodeType type, return filteredChildType; } + +X::X(X const &other) { + + _localForm = other._localForm; + _unicodeForm = XERCESC_NS::XMLString::replicate(other._unicodeForm); + _deallocOther = true; +} + +X::X(const XMLCh* const toTranscode) { + + if (toTranscode != NULL) { + // Call the private transcoding method + char* tmp = XERCESC_NS::XMLString::transcode(toTranscode); + _localForm = std::string(tmp); + XERCESC_NS::XMLString::release(&tmp); + } + _unicodeForm = NULL; + _deallocOther = false; +} + +X::X(const std::string& fromTranscode) { + + // Call the private transcoding method + _localForm = fromTranscode; + _unicodeForm = XERCESC_NS::XMLString::transcode(fromTranscode.c_str()); + _deallocOther = true; +} + +X::X(const char* const fromTranscode) { + // this is most unfortunate but needed with static XMLChars :( + if (!_xercesIsInit) { + try { + ::xercesc_3_1::XMLPlatformUtils::Initialize(); + _xercesIsInit = true; + } catch (const XERCESC_NS::XMLException& toCatch) { + throw ("Cannot initialize XercesC: " + X(toCatch.getMessage()).str()); + } + } + + // Call the private transcoding method + _localForm = fromTranscode; + _unicodeForm = XERCESC_NS::XMLString::transcode(fromTranscode); + _deallocOther = true; +} + +X::X(char* fromTranscode) { + + // Call the private transcoding method + _localForm = fromTranscode; + _unicodeForm = XERCESC_NS::XMLString::transcode(fromTranscode); + _deallocOther = true; +} + +X::~X() { + if (_deallocOther) + XERCESC_NS::XMLString::release(&_unicodeForm); +} + +int X::iequals(const XMLCh* const other) const { + return XERCESC_NS::XMLString::compareIString(_unicodeForm, other); +} + +void X::operator=(X const &other) { + _localForm = other._localForm; + _unicodeForm = XERCESC_NS::XMLString::replicate(other._unicodeForm); + _deallocOther = true; +} + +bool X::operator==(const XMLCh* other) const { + return XERCESC_NS::XMLString::compareString(other, _unicodeForm) == 0; +} + +bool X::operator<(const X& other) const { + return XERCESC_NS::XMLString::compareString(_unicodeForm, other._unicodeForm) < 0; +} + } diff --git a/src/uscxml/util/DOM.h b/src/uscxml/util/DOM.h index 1e0b8ce..01ae22f 100644 --- a/src/uscxml/util/DOM.h +++ b/src/uscxml/util/DOM.h @@ -25,6 +25,7 @@ #include #include "uscxml/Common.h" + #include #include @@ -37,6 +38,7 @@ #define LOCALNAME(elem) std::string(X((elem)->getLocalName())) #define LOCALNAME_CAST(elem) LOCALNAME(static_cast(elem)) + namespace uscxml { class USCXML_API DOMUtils { @@ -76,7 +78,7 @@ public: const std::list& nodeSet, bool recurse = false); - static std::list filterChildType(const XERCESC_NS::DOMNode::NodeType type, + static std::list filterChildType(const XERCESC_NS::DOMNode::NodeType type, const XERCESC_NS::DOMNode* node, bool recurse = false) { return filterTypeGeneric({ type }, node, (recurse ? DOCUMENT : NO_RECURSE), true, false); @@ -124,7 +126,6 @@ public: // create a prefix from a given element - useful for copying namespace information #define XML_PREFIX(element) X(element->getPrefix() ? X(element->getPrefix()).str() + ":" : "") -#if 1 /** * @todo: More performant XercesStrings * https://alfps.wordpress.com/2010/05/27/cppx-xerces-strings-simplified-by-ownership-part-i/ @@ -133,92 +134,32 @@ public: class USCXML_API X { public : - X(X const &other) { - - _localForm = other._localForm; - _unicodeForm = XERCESC_NS::XMLString::replicate(other._unicodeForm); - _deallocOther = true; - } - - X(const XMLCh* const toTranscode) { - - if (toTranscode != NULL) { - // Call the private transcoding method - char* tmp = XERCESC_NS::XMLString::transcode(toTranscode); - _localForm = std::string(tmp); - XERCESC_NS::XMLString::release(&tmp); - } - _unicodeForm = NULL; - _deallocOther = false; - } - - X(const std::string& fromTranscode) { - - // Call the private transcoding method - _localForm = fromTranscode; - _unicodeForm = XERCESC_NS::XMLString::transcode(fromTranscode.c_str()); - _deallocOther = true; - } - - X(const char* const fromTranscode) { - // this is most unfortunate but needed with static XMLChars :( - if (!_xercesIsInit) { - try { - ::xercesc_3_1::XMLPlatformUtils::Initialize(); - _xercesIsInit = true; - } catch (const XERCESC_NS::XMLException& toCatch) { - throw ("Cannot initialize XercesC: " + X(toCatch.getMessage()).str()); - } - } - - // Call the private transcoding method - _localForm = fromTranscode; - _unicodeForm = XERCESC_NS::XMLString::transcode(fromTranscode); - _deallocOther = true; - } - - X(char* fromTranscode) { - - // Call the private transcoding method - _localForm = fromTranscode; - _unicodeForm = XERCESC_NS::XMLString::transcode(fromTranscode); - _deallocOther = true; - } + X(X const &other); + X(const XMLCh* const toTranscode); + X(const std::string& fromTranscode); + X(const char* const fromTranscode); + X(char* fromTranscode); X() { - _unicodeForm = NULL; _deallocOther = false; } - ~X() { - - if (_deallocOther) - XERCESC_NS::XMLString::release(&_unicodeForm); - } + ~X(); const std::string& str() const { return _localForm; } - int iequals(const XMLCh* const other) const { - return XERCESC_NS::XMLString::compareIString(_unicodeForm, other); - } - + int iequals(const XMLCh* const other) const; + operator XMLCh* () const { assert(_unicodeForm != NULL); // constructor with XMLCh return _unicodeForm; } - void operator=(X const &other) { - _localForm = other._localForm; - _unicodeForm = XERCESC_NS::XMLString::replicate(other._unicodeForm); - _deallocOther = true; - } - - bool operator==(const XMLCh* other) const { - return XERCESC_NS::XMLString::compareString(other, _unicodeForm) == 0; - } + void operator=(X const &other); + bool operator==(const XMLCh* other) const; bool operator==(const X& other) const { return (_localForm == other._localForm) != 0; @@ -228,9 +169,7 @@ public : return !(_unicodeForm == other._unicodeForm); } - bool operator<(const X& other) const { - return XERCESC_NS::XMLString::compareString(_unicodeForm, other._unicodeForm) < 0; - } + bool operator<(const X& other) const; operator bool () { return _localForm.size() > 0; @@ -250,79 +189,6 @@ private: bool _xercesIsInit = false; }; -#else - -class USCXML_API X { -public : - X() { - } - - void operator=(X const &other) { - localForm = other.localForm; - if (unicodeForm != NULL) { - XERCESC_NS::XMLString::release(&unicodeForm); - } - unicodeForm = XERCESC_NS::XMLString::replicate(other.unicodeForm); - } - - X(X const &other) { - localForm = other.localForm; - unicodeForm = XERCESC_NS::XMLString::replicate(other.unicodeForm); - } - - X(const char* const toTranscode) { - if (toTranscode != NULL) { - localForm = toTranscode; - unicodeForm = XERCESC_NS::XMLString::transcode(toTranscode); - } - } - - X(const XMLCh* toTranscode) { - if (toTranscode != NULL) { - unicodeForm = XERCESC_NS::XMLString::replicate(toTranscode); - localForm = XERCESC_NS::XMLString::transcode(toTranscode); - } - } - - X(const std::string& toTranscode) { - localForm = toTranscode; - unicodeForm = XERCESC_NS::XMLString::transcode(toTranscode.c_str()); - } - - ~X() { - if (unicodeForm != NULL) { - XERCESC_NS::XMLString::release(&unicodeForm); - } - } - - operator XMLCh* () const { - return unicodeForm; - } - - operator const std::string& () { - return localForm; - } - - const std::string& str() const { - return localForm; - } - - const XMLCh* unicode() const { - return unicodeForm; - } - - -protected: - friend USCXML_API std::ostream& operator<< (std::ostream& os, const X& data); - -private: - XMLCh* unicodeForm = NULL; - std::string localForm; - -}; - -#endif - static const X kXMLCharScxml = X("scxml"); static const X kXMLCharState = X("state"); static const X kXMLCharParallel = X("parallel"); diff --git a/test/src/test-stress.cpp b/test/src/test-stress.cpp index d0c15fd..a220387 100644 --- a/test/src/test-stress.cpp +++ b/test/src/test-stress.cpp @@ -19,7 +19,9 @@ int startedAt; int lastTransitionAt; class StatusMonitor : public uscxml::InterpreterMonitor { - void beforeTakingTransition(const std::string& sessionId, const XERCESC_NS::DOMElement* transition) { + void beforeTakingTransition(const std::string& sessionId, + const std::string& targetList, + const XERCESC_NS::DOMElement* transition) { lastTransitionAt = time(NULL); } -- cgit v0.12