diff options
Diffstat (limited to 'src/uscxml/util')
-rw-r--r-- | src/uscxml/util/BlockingQueue.h | 77 | ||||
-rw-r--r-- | src/uscxml/util/DOM.h | 40 |
2 files changed, 114 insertions, 3 deletions
diff --git a/src/uscxml/util/BlockingQueue.h b/src/uscxml/util/BlockingQueue.h new file mode 100644 index 0000000..2f0ab2e --- /dev/null +++ b/src/uscxml/util/BlockingQueue.h @@ -0,0 +1,77 @@ +/** + * @file + * @author 2012-2013 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 <http://www.opensource.org/licenses/bsd-license>. + * @endcond + */ + +#ifndef BLOCKINGQUEUE_H_4LEVMY0N +#define BLOCKINGQUEUE_H_4LEVMY0N + +#include "uscxml/Common.h" +#include <list> +#include <condition_variable> + +namespace uscxml { + +template <class T> +class BlockingQueue { +public: + BlockingQueue() {} + virtual ~BlockingQueue() { + } + + virtual void push(const T& elem) { + std::lock_guard<std::mutex> lock(_mutex); + _queue.push_back(elem); + _cond.notify_all(); + } + + virtual void push_front(const T& elem) { + std::lock_guard<std::mutex> lock(_mutex); + _queue.push_front(elem); + _cond.notify_all(); + } + + virtual T pop() { + std::lock_guard<std::mutex> lock(_mutex); +// std::cout << "Popping from " << this << std::endl; + while (_queue.empty()) { + _cond.wait(_mutex); + } + T ret = _queue.front(); + _queue.pop_front(); + return ret; + } + + virtual void clear() { + std::lock_guard<std::mutex> lock(_mutex); + _queue.clear(); + } + + virtual bool isEmpty() { + std::lock_guard<std::mutex> lock(_mutex); + return _queue.empty(); + } + +protected: + std::mutex _mutex; + std::condition_variable_any _cond; + std::list<T> _queue; +}; + +} + +#endif /* end of include guard: BLOCKINGQUEUE_H_4LEVMY0N */ diff --git a/src/uscxml/util/DOM.h b/src/uscxml/util/DOM.h index 0b35f40..86fa813 100644 --- a/src/uscxml/util/DOM.h +++ b/src/uscxml/util/DOM.h @@ -127,17 +127,20 @@ class USCXML_API X { public : X(X const &other) { + _localForm = other._localForm; _unicodeForm = XERCESC_NS::XMLString::replicate(other._unicodeForm); _deallocOther = true; } void operator=(X const &other) { // did we maybe leak before? + _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); @@ -149,6 +152,7 @@ public : } X(const std::string& fromTranscode) { + // Call the private transcoding method _localForm = fromTranscode; _unicodeForm = XERCESC_NS::XMLString::transcode(fromTranscode.c_str()); @@ -156,6 +160,7 @@ public : } X(const char* const fromTranscode) { + // Call the private transcoding method _localForm = fromTranscode; _unicodeForm = XERCESC_NS::XMLString::transcode(fromTranscode); @@ -163,22 +168,25 @@ public : } X(char* fromTranscode) { - // Call the private transcoding method + + // Call the private transcoding method _localForm = fromTranscode; _unicodeForm = XERCESC_NS::XMLString::transcode(fromTranscode); _deallocOther = true; } X() { + _unicodeForm = NULL; _deallocOther = false; } ~X() { + if (_deallocOther) XERCESC_NS::XMLString::release(&_unicodeForm); } - + const std::string& str() const { return _localForm; } @@ -195,7 +203,7 @@ public : operator std::string () { return _localForm; } - + protected: friend USCXML_API std::ostream& operator<< (std::ostream& os, const X& data); @@ -277,6 +285,32 @@ private: }; #endif + +#if 0 +static const X kElementScxmlName = X("scxml"); +static const X kElementStateName = X("state"); +static const X kElementParallelName = X("parallel"); +static const X kElementTransitionName = X("transition"); +static const X kElementInitialName = X("initial"); +static const X kElementFinalName = X("final"); +static const X kElementOnEntryName = X("onentry"); +static const X kElementOnExitName = X("onexit"); +static const X kElementHistoryName = X("history"); + +static const X kElementRaiseName = X("raise"); +static const X kElementIfName = X("if"); +static const X kElementElseIfName = X("elseif"); +static const X kElementElseName = X("else"); +static const X kElementForEachName = X("foreach"); +static const X kElementLogName = X("log"); + +static const X kElementDataModelName = X("datamodel"); +static const X kElementDataName = X("data"); +static const X kElementAssignName = X("assign"); +static const X kElementContentName = X("content"); +static const X kElementParamName = X("param"); +static const X kElementScriptName = X("script"); +#endif USCXML_API std::ostream& operator<< (std::ostream& os, const X& xmlString); USCXML_API std::ostream& operator<< (std::ostream& os, const XERCESC_NS::DOMNode& node); |