From 9b02d5a62ea41136b46b744f7b2c1cf50f30a888 Mon Sep 17 00:00:00 2001
From: Henrik Rentz-Reichert
Date: Wed, 4 Jan 2017 21:07:12 +0100
Subject: Bug 509875 - [runtime.cpp] replace STL containers with own containers
that are more light weight
* replaced streaming code with (s)printf constructs
* added String, Vector, Set, Pair and Map with tests
* using new String class in
* Address
* Message
* MSCFilter
* MSCLogger
* RTObject
* and affected classes
* using new Vector class in
* RTObject
* MSCLogger
* MessageServiceController
* ReplicatedActorClassBase
* ReplicatedInterfaceItemBase
* and affected classes
* using new Set class in
* MessageDispatcher
* using new Map class in
* SubSystemClassBase
* DebuggingService
* adjusted cpp generator
Change-Id: I9c91289057185e6e36b9453ecf03f6f6d3834ec6
---
.../jgen_modellib_java.launch | 2 +
.../common/modelbase/RTSystemServicesProtocol.cpp | 40 ++-
.../common/modelbase/RTSystemServicesProtocol.h | 20 +-
.../src/common/containers/Map.cpp | 20 ++
.../src/common/containers/Map.h | 232 ++++++++++++++
.../src/common/containers/Pair.h | 84 ++++++
.../src/common/containers/Set.cpp | 20 ++
.../src/common/containers/Set.h | 222 ++++++++++++++
.../src/common/containers/String.cpp | 169 +++++++++++
.../src/common/containers/String.h | 318 ++++++++++++++++++++
.../src/common/containers/Vector.cpp | 22 ++
.../src/common/containers/Vector.h | 334 +++++++++++++++++++++
.../src/common/debugging/DebuggingService.cpp | 61 ++--
.../src/common/debugging/DebuggingService.h | 21 +-
.../src/common/debugging/MSCFilter.cpp | 10 +-
.../src/common/debugging/MSCFilter.h | 26 +-
.../src/common/debugging/MSCFunctionObject.cpp | 12 +-
.../src/common/debugging/MSCFunctionObject.h | 8 +-
.../src/common/debugging/MSCLogger.cpp | 42 +--
.../src/common/debugging/MSCLogger.h | 43 ++-
.../src/common/messaging/AbstractMessageReceiver.h | 7 +-
.../src/common/messaging/Address.cpp | 5 +-
.../src/common/messaging/Address.h | 6 +-
.../src/common/messaging/IRTObject.cpp | 3 +-
.../src/common/messaging/IRTObject.h | 22 +-
.../src/common/messaging/Message.cpp | 19 +-
.../src/common/messaging/Message.h | 6 +-
.../src/common/messaging/MessageDispatcher.cpp | 20 +-
.../src/common/messaging/MessageDispatcher.h | 17 +-
.../src/common/messaging/MessageSeQueue.cpp | 2 +-
.../src/common/messaging/MessageSeQueue.h | 3 +-
.../src/common/messaging/MessageService.cpp | 10 +-
.../src/common/messaging/MessageService.h | 7 +-
.../common/messaging/MessageServiceController.cpp | 26 +-
.../common/messaging/MessageServiceController.h | 10 +-
.../src/common/messaging/RTObject.cpp | 60 ++--
.../src/common/messaging/RTObject.h | 56 ++--
.../src/common/messaging/StaticMessageMemory.cpp | 7 +-
.../src/common/messaging/StaticMessageMemory.h | 2 +-
.../src/common/modelbase/ActorClassBase.cpp | 13 +-
.../src/common/modelbase/ActorClassBase.h | 11 +-
.../src/common/modelbase/DataPort.cpp | 3 +-
.../src/common/modelbase/DataPort.h | 9 +-
.../src/common/modelbase/EventReceiver.cpp | 3 +-
.../src/common/modelbase/EventReceiver.h | 3 +-
.../src/common/modelbase/InterfaceItemBase.cpp | 26 +-
.../src/common/modelbase/InterfaceItemBase.h | 7 +-
.../src/common/modelbase/PortBase.h | 5 +-
.../src/common/modelbase/RTSystem.h | 4 +-
.../src/common/modelbase/RTSystemProtocol.cpp | 13 +-
.../src/common/modelbase/RTSystemProtocol.h | 7 +-
.../common/modelbase/ReplicatedActorClassBase.cpp | 16 +-
.../common/modelbase/ReplicatedActorClassBase.h | 10 +-
.../modelbase/ReplicatedInterfaceItemBase.cpp | 26 +-
.../common/modelbase/ReplicatedInterfaceItemBase.h | 17 +-
.../src/common/modelbase/ReplicatedPortBase.h | 3 +-
.../src/common/modelbase/SubSystemClassBase.cpp | 44 ++-
.../src/common/modelbase/SubSystemClassBase.h | 13 +-
.../src/common/modelbase/SubSystemRunnerBase.cpp | 18 +-
.../src/common/modelbase/SubSystemRunnerBase.h | 6 +-
.../src/common/modelbase/SystemPortOwner.h | 3 +-
61 files changed, 1851 insertions(+), 403 deletions(-)
create mode 100644 runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Map.cpp
create mode 100644 runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Map.h
create mode 100644 runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Pair.h
create mode 100644 runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Set.cpp
create mode 100644 runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Set.h
create mode 100644 runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/String.cpp
create mode 100644 runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/String.h
create mode 100644 runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Vector.cpp
create mode 100644 runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Vector.h
(limited to 'runtime')
diff --git a/runtime/org.eclipse.etrice.modellib.java/jgen_modellib_java.launch b/runtime/org.eclipse.etrice.modellib.java/jgen_modellib_java.launch
index fac0a9524..02583c781 100644
--- a/runtime/org.eclipse.etrice.modellib.java/jgen_modellib_java.launch
+++ b/runtime/org.eclipse.etrice.modellib.java/jgen_modellib_java.launch
@@ -6,8 +6,10 @@
+
+
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src-gen/common/modelbase/RTSystemServicesProtocol.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src-gen/common/modelbase/RTSystemServicesProtocol.cpp
index 83fa9cd55..77e266e0d 100644
--- a/runtime/org.eclipse.etrice.runtime.cpp/src-gen/common/modelbase/RTSystemServicesProtocol.cpp
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src-gen/common/modelbase/RTSystemServicesProtocol.cpp
@@ -13,22 +13,20 @@
#include "common/messaging/Address.h"
#include "common/messaging/Message.h"
#include "common/modelbase/IEventReceiver.h"
-#include
-#include
using namespace etRuntime;
/* message names as strings for debugging (generate MSC) */
-const std::string RTSystemServicesProtocol::s_messageStrings[] = {"MIN", "executeInitialTransition","startDebugging","stopDebugging","MAX"};
+const String RTSystemServicesProtocol::s_messageStrings[] = {"MIN", "executeInitialTransition","startDebugging","stopDebugging","MAX"};
-const std::string& RTSystemServicesProtocol::getMessageString(int msg_id) {
+const String& RTSystemServicesProtocol::getMessageString(int msg_id) {
if ((MSG_MIN < msg_id ) && ( msg_id < MSG_MAX )) {
return s_messageStrings[msg_id];
} else {
// id out of range
- static const std::string errorMsg = "Message ID out of range";
+ static const String errorMsg = "Message ID out of range";
return errorMsg;
}
}
@@ -37,12 +35,12 @@ const std::string& RTSystemServicesProtocol::getMessageString(int msg_id) {
// port class
//------------------------------------------------------------------------------------------------------------
-RTSystemServicesProtocolPort::RTSystemServicesProtocolPort(IInterfaceItemOwner* actor, const std::string& name, int localId)
+RTSystemServicesProtocolPort::RTSystemServicesProtocolPort(IInterfaceItemOwner* actor, const String& name, int localId)
: PortBase(actor, name, localId, 0)
{
}
-RTSystemServicesProtocolPort::RTSystemServicesProtocolPort(IInterfaceItemOwner* actor, const std::string& name, int localId, int idx)
+RTSystemServicesProtocolPort::RTSystemServicesProtocolPort(IInterfaceItemOwner* actor, const String& name, int localId, int idx)
: PortBase(actor, name, localId, idx)
{
}
@@ -55,10 +53,10 @@ void RTSystemServicesProtocolPort::destroy() {
void RTSystemServicesProtocolPort::receive(const Message* msg) {
// TODO JH further
if (! RTSystemServicesProtocol::isValidIncomingEvtID(msg->getEvtId())) {
- std::cout << "unknown" << std::endl;
+ //std::cout << "unknown" << std::endl;
}
- DebuggingService::getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), RTSystemServicesProtocol::getMessageString(msg->getEvtId()));
+ DebuggingService::getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), RTSystemServicesProtocol::getMessageString(msg->getEvtId()).c_str());
getActor()->receiveEvent(this, msg->getEvtId(), msg->getData());
}
@@ -69,7 +67,7 @@ void RTSystemServicesProtocolPort::receive(const Message* msg) {
//------------------------------------------------------------------------------------------------------------
// replicated port class
//------------------------------------------------------------------------------------------------------------
-RTSystemServicesProtocolReplPort::RTSystemServicesProtocolReplPort(IInterfaceItemOwner* actor, const std::string& name, int localId) :
+RTSystemServicesProtocolReplPort::RTSystemServicesProtocolReplPort(IInterfaceItemOwner* actor, const String& name, int localId) :
ReplicatedPortBase(actor, name, localId)
{
}
@@ -79,12 +77,12 @@ RTSystemServicesProtocolReplPort::RTSystemServicesProtocolReplPort(IInterfaceIte
// conjugated port class
//------------------------------------------------------------------------------------------------------------
-RTSystemServicesProtocolConjPort::RTSystemServicesProtocolConjPort(IInterfaceItemOwner* actor, const std::string& name, int localId)
+RTSystemServicesProtocolConjPort::RTSystemServicesProtocolConjPort(IInterfaceItemOwner* actor, const String& name, int localId)
: PortBase(actor, name, localId, 0)
{
}
-RTSystemServicesProtocolConjPort::RTSystemServicesProtocolConjPort(IInterfaceItemOwner* actor, const std::string& name, int localId, int idx)
+RTSystemServicesProtocolConjPort::RTSystemServicesProtocolConjPort(IInterfaceItemOwner* actor, const String& name, int localId, int idx)
: PortBase(actor, name, localId, idx)
{
}
@@ -97,10 +95,10 @@ void RTSystemServicesProtocolConjPort::destroy() {
void RTSystemServicesProtocolConjPort::receive(const Message* msg) {
// TODO JH further
if (! RTSystemServicesProtocol::isValidOutgoingEvtID(msg->getEvtId())) {
- std::cout << "unknown" << std::endl;
+ //std::cout << "unknown" << std::endl;
}
- DebuggingService::getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), RTSystemServicesProtocol::getMessageString(msg->getEvtId()));
+ DebuggingService::getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), RTSystemServicesProtocol::getMessageString(msg->getEvtId()).c_str());
getActor()->receiveEvent(this, msg->getEvtId(), msg->getData());
}
@@ -113,7 +111,7 @@ void RTSystemServicesProtocolConjPort::executeInitialTransition() {
void RTSystemServicesProtocolConjPort::executeInitialTransition_impl() {
DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
- RTSystemServicesProtocol::getMessageString(RTSystemServicesProtocol::IN_executeInitialTransition));
+ RTSystemServicesProtocol::getMessageString(RTSystemServicesProtocol::IN_executeInitialTransition).c_str());
if (getPeerAddress().isValid()) {
Message* buffer = dynamic_cast(getPeerMsgReceiver())->getMessageBuffer(sizeof(Message));
if (buffer) {
@@ -127,7 +125,7 @@ void RTSystemServicesProtocolConjPort::startDebugging() {
void RTSystemServicesProtocolConjPort::startDebugging_impl() {
DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
- RTSystemServicesProtocol::getMessageString(RTSystemServicesProtocol::IN_startDebugging));
+ RTSystemServicesProtocol::getMessageString(RTSystemServicesProtocol::IN_startDebugging).c_str());
if (getPeerAddress().isValid()) {
Message* buffer = dynamic_cast(getPeerMsgReceiver())->getMessageBuffer(sizeof(Message));
if (buffer) {
@@ -141,7 +139,7 @@ void RTSystemServicesProtocolConjPort::stopDebugging() {
void RTSystemServicesProtocolConjPort::stopDebugging_impl() {
DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
- RTSystemServicesProtocol::getMessageString(RTSystemServicesProtocol::IN_stopDebugging));
+ RTSystemServicesProtocol::getMessageString(RTSystemServicesProtocol::IN_stopDebugging).c_str());
if (getPeerAddress().isValid()) {
Message* buffer = dynamic_cast(getPeerMsgReceiver())->getMessageBuffer(sizeof(Message));
if (buffer) {
@@ -153,24 +151,24 @@ void RTSystemServicesProtocolConjPort::stopDebugging_impl() {
//------------------------------------------------------------------------------------------------------------
// conjugated replicated port class
//------------------------------------------------------------------------------------------------------------
-RTSystemServicesProtocolConjReplPort::RTSystemServicesProtocolConjReplPort(IInterfaceItemOwner* actor, const std::string& name, int localId) :
+RTSystemServicesProtocolConjReplPort::RTSystemServicesProtocolConjReplPort(IInterfaceItemOwner* actor, const String& name, int localId) :
ReplicatedPortBase(actor, name, localId)
{
}
// incoming messages
void RTSystemServicesProtocolConjReplPort::executeInitialTransition(){
- for (std::vector::iterator it = getItems().begin(); it != getItems().end(); ++it) {
+ for (Vector::iterator it = getItems().begin(); it != getItems().end(); ++it) {
(dynamic_cast(*it))->executeInitialTransition();
}
}
void RTSystemServicesProtocolConjReplPort::startDebugging(){
- for (std::vector::iterator it = getItems().begin(); it != getItems().end(); ++it) {
+ for (Vector::iterator it = getItems().begin(); it != getItems().end(); ++it) {
(dynamic_cast(*it))->startDebugging();
}
}
void RTSystemServicesProtocolConjReplPort::stopDebugging(){
- for (std::vector::iterator it = getItems().begin(); it != getItems().end(); ++it) {
+ for (Vector::iterator it = getItems().begin(); it != getItems().end(); ++it) {
(dynamic_cast(*it))->stopDebugging();
}
}
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src-gen/common/modelbase/RTSystemServicesProtocol.h b/runtime/org.eclipse.etrice.runtime.cpp/src-gen/common/modelbase/RTSystemServicesProtocol.h
index 49f575623..83301edb3 100644
--- a/runtime/org.eclipse.etrice.runtime.cpp/src-gen/common/modelbase/RTSystemServicesProtocol.h
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src-gen/common/modelbase/RTSystemServicesProtocol.h
@@ -38,10 +38,10 @@ class RTSystemServicesProtocol {
static bool isValidIncomingEvtID(int evtId) {
return ((IN_executeInitialTransition <= evtId) && (evtId < MSG_MAX));
}
- static const std::string& getMessageString(int msg_id);
+ static const etRuntime::String& getMessageString(int msg_id);
private:
- static const std::string s_messageStrings[];
+ static const etRuntime::String s_messageStrings[];
};
@@ -50,8 +50,8 @@ class RTSystemServicesProtocol {
//------------------------------------------------------------------------------------------------------------
class RTSystemServicesProtocolPort : public etRuntime::PortBase {
public:
- RTSystemServicesProtocolPort(etRuntime::IInterfaceItemOwner* actor, const std::string& name, int localId);
- RTSystemServicesProtocolPort(etRuntime::IInterfaceItemOwner* actor, const std::string& name, int localId, int idx);
+ RTSystemServicesProtocolPort(etRuntime::IInterfaceItemOwner* actor, const etRuntime::String& name, int localId);
+ RTSystemServicesProtocolPort(etRuntime::IInterfaceItemOwner* actor, const etRuntime::String& name, int localId, int idx);
virtual void destroy();
@@ -67,7 +67,7 @@ class RTSystemServicesProtocolPort : public etRuntime::PortBase {
class RTSystemServicesProtocolReplPort : public etRuntime::ReplicatedPortBase {
public:
- RTSystemServicesProtocolReplPort(etRuntime::IInterfaceItemOwner* actor, const std::string& name, int localId);
+ RTSystemServicesProtocolReplPort(etRuntime::IInterfaceItemOwner* actor, const etRuntime::String& name, int localId);
int getReplication() const { return getNInterfaceItems(); }
int getIndexOf(const etRuntime::InterfaceItemBase& ifitem) const { return ifitem.getIdx(); }
@@ -76,7 +76,7 @@ class RTSystemServicesProtocolReplPort : public etRuntime::ReplicatedPortBase {
// outgoing messages
protected:
- virtual etRuntime::InterfaceItemBase* createInterfaceItem(etRuntime::IInterfaceItemOwner* rcv, const std::string& name, int lid, int idx) {
+ virtual etRuntime::InterfaceItemBase* createInterfaceItem(etRuntime::IInterfaceItemOwner* rcv, const etRuntime::String& name, int lid, int idx) {
return new RTSystemServicesProtocolPort(rcv, name, lid, idx);
}
@@ -86,8 +86,8 @@ class RTSystemServicesProtocolReplPort : public etRuntime::ReplicatedPortBase {
//------------------------------------------------------------------------------------------------------------
class RTSystemServicesProtocolConjPort : public etRuntime::PortBase {
public:
- RTSystemServicesProtocolConjPort(etRuntime::IInterfaceItemOwner* actor, const std::string& name, int localId);
- RTSystemServicesProtocolConjPort(etRuntime::IInterfaceItemOwner* actor, const std::string& name, int localId, int idx);
+ RTSystemServicesProtocolConjPort(etRuntime::IInterfaceItemOwner* actor, const etRuntime::String& name, int localId);
+ RTSystemServicesProtocolConjPort(etRuntime::IInterfaceItemOwner* actor, const etRuntime::String& name, int localId, int idx);
virtual void destroy();
@@ -109,7 +109,7 @@ class RTSystemServicesProtocolConjPort : public etRuntime::PortBase {
class RTSystemServicesProtocolConjReplPort : public etRuntime::ReplicatedPortBase {
public:
- RTSystemServicesProtocolConjReplPort(etRuntime::IInterfaceItemOwner* actor, const std::string& name, int localId);
+ RTSystemServicesProtocolConjReplPort(etRuntime::IInterfaceItemOwner* actor, const etRuntime::String& name, int localId);
int getReplication() const { return getNInterfaceItems(); }
int getIndexOf(const etRuntime::InterfaceItemBase& ifitem) const { return ifitem.getIdx(); }
@@ -121,7 +121,7 @@ class RTSystemServicesProtocolConjReplPort : public etRuntime::ReplicatedPortBas
public: void stopDebugging();
protected:
- virtual etRuntime::InterfaceItemBase* createInterfaceItem(etRuntime::IInterfaceItemOwner* rcv, const std::string& name, int lid, int idx) {
+ virtual etRuntime::InterfaceItemBase* createInterfaceItem(etRuntime::IInterfaceItemOwner* rcv, const etRuntime::String& name, int lid, int idx) {
return new RTSystemServicesProtocolConjPort(rcv, name, lid, idx);
}
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Map.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Map.cpp
new file mode 100644
index 000000000..35bd4188a
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Map.cpp
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2017 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+#include "common/containers/Map.h"
+
+namespace etRuntime {
+
+size_t MapStats::ncreated = 0;
+size_t MapStats::ndestroyed = 0;
+
+} /* namespace etRuntime */
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Map.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Map.h
new file mode 100644
index 000000000..d77c53f5e
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Map.h
@@ -0,0 +1,232 @@
+/*******************************************************************************
+ * Copyright (c) 2017 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+#ifndef MAP_H_
+#define MAP_H_
+
+#include "etDatatypes.h"
+#include "Pair.h"
+#include "Vector.h"
+
+namespace etRuntime {
+
+/**
+ * common map base class with counters for creations and destructions
+ */
+class MapStats {
+public:
+ static size_t getNCreated() { return ncreated; }
+ static size_t getNDestroyed() { return ndestroyed; }
+
+private:
+ template friend class Map;
+ static size_t ncreated;
+ static size_t ndestroyed;
+};
+
+template
+class Map {
+public:
+
+ typedef Pair Entry;
+ typedef typename Vector::iterator iterator;
+ typedef typename Vector::const_iterator const_iterator;
+ typedef typename Vector::reverse_iterator reverse_iterator;
+
+ /**
+ * default constructor
+ */
+ Map()
+ : _container()
+ {
+ ++MapStats::ncreated;
+ }
+
+ /**
+ * copy constructor
+ */
+ Map(const Map &rhs)
+ : _container(rhs._container)
+ {
+ ++MapStats::ncreated;
+ }
+
+ /**
+ * virtual destructor
+ */
+ virtual ~Map(void) {
+ ++MapStats::ndestroyed;
+ }
+
+ /**
+ * Requests that the set capacity be at least enough to contain n elements.
+ *
+ * If n is greater than the current set capacity, the function causes the container
+ * to reallocate its storage increasing its capacity to n (or greater).
+ * In all other cases, the function call does not cause a reallocation and the set
+ * capacity is not affected.
+ *
+ * This function has no effect on the set size and cannot alter its elements.
+ */
+ void reserve(size_t n) {
+ _container.reserve(n);
+ }
+
+ /**
+ * returns the _size of this set
+ */
+ int size(void) const {
+ return _container.size();
+ }
+
+ /**
+ * Returns whether the set is empty (i.e. whether its size is 0).
+ * This function does not modify the container in any way.
+ * To clear the content of a set, see Map::clear.
+ */
+ bool empty(void) const {
+ return _container.empty();
+ }
+
+ void clear() {
+ _container.clear();
+ }
+
+ Value& operator[](const Key& key) {
+ for (iterator it=begin(); it!=end(); ++it) {
+ if (key==it->first) {
+ return it->second;
+ }
+ }
+
+ _container.push_back(Entry(key, Value()));
+ return _container.back().second;
+ }
+
+ iterator find(const Key& key) {
+ for (iterator it=begin(); it!=end(); ++it) {
+ if (key==(*it).first) {
+ return it;
+ }
+ }
+ return end();
+ }
+
+ const_iterator find(const Key& key) const {
+ for (const_iterator it=begin(); it!=end(); ++it) {
+ if (key==(*it).first) {
+ return it;
+ }
+ }
+ return end();
+ }
+
+ iterator erase(iterator position) {
+ return _container.erase(position);
+ }
+
+ size_t erase(const Key& key) {
+ iterator it = find(key);
+ if (it==end()) {
+ return 0;
+ }
+ else {
+ _container.erase(it);
+ return 1;
+ }
+ }
+
+ /**
+ * returns a pointer to the _data of this set (as a C array)
+ */
+ Entry* getData(void) {
+ return _container.getData();
+ }
+
+ /**
+ * returns a const pointer to the _data of this set (as a C array)
+ */
+ const Entry* getData(void) const {
+ return _container.getData();
+ }
+
+ /**
+ * copy assignment makes a deep copy
+ */
+ Map& operator=(const Map &rhs) {
+ _container = rhs._container;
+ return *this;
+ }
+
+ const_iterator begin() const {
+ return _container.begin();
+ }
+
+ const_iterator end() const {
+ return _container.end();
+ }
+
+ iterator begin() {
+ return _container.begin();
+ }
+
+ iterator end() {
+ return _container.end();
+ }
+
+ reverse_iterator rbegin() {
+ return _container.rbegin();
+ }
+
+ reverse_iterator rend() {
+ return _container.rend();
+ }
+
+protected:
+ Vector _container;
+};
+
+/**
+ * comparison operator (expensive because not ordered - O(n^2))
+ */
+template
+inline bool operator==(const Map lhs, const Map rhs) {
+ if (rhs.size()!=lhs.size()) {
+ return false;
+ }
+
+ // are all elements contained in rhs?
+ for (typename Map::const_iterator it=lhs.begin(); it!=lhs.end(); ++it) {
+ // find key
+ typename Map::const_iterator rit = rhs.find(it->first);
+ if (rit==rhs.end()) {
+ return false;
+ }
+ else {
+ // compare value
+ if (rit->second!=it->second) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
+template
+inline bool operator!=(const Map &lhs, const Map &rhs) {
+ return !(lhs==rhs);
+}
+
+} /* namespace etRuntime */
+#endif /* MAP_H_ */
+
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Pair.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Pair.h
new file mode 100644
index 000000000..ae61816e7
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Pair.h
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2017 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+#ifndef PAIR_H_
+#define PAIR_H_
+
+#include "etDatatypes.h"
+
+namespace etRuntime {
+
+
+template
+struct Pair {
+ Pair()
+ : first(), second()
+ { }
+ Pair(const T1& f, const T2& s)
+ : first(f), second(s)
+ { }
+
+ // copy constructor
+ // works if T1==U1 and T1==U2 or implicit conversions T1(U1) and T2(U2) exist
+ template
+ Pair(const Pair& p)
+ : first(p.first)
+ , second(p.second)
+ {
+ }
+
+ T1 first;
+ T2 second;
+};
+
+/**
+ * two pairs of the same pair of types are equal iff their members are equal.
+ */
+template
+inline bool operator==(const Pair& lhs, const Pair& rhs) {
+ return lhs.first == rhs.first && lhs.second == rhs.second;
+}
+
+// uses operator==
+template
+inline bool operator!=(const Pair& lhs, const Pair& rhs) {
+ return !(lhs==rhs);
+}
+
+// see http://www.cplusplus.com/reference/utility/pair/operators/
+template
+inline bool operator<(const Pair& lhs, const Pair& rhs) {
+ return lhs.first < rhs.first
+ || (!(rhs.first < lhs.first) && lhs.second < rhs.second);
+}
+
+// uses operator<
+template
+inline bool operator>(const Pair& lhs, const Pair& rhs) {
+ return rhs < lhs;
+}
+
+// uses operator<
+template
+inline bool operator<=(const Pair& lhs, const Pair& rhs) {
+ return !(rhs < lhs);
+}
+
+// uses operator<
+template
+inline bool operator>=(const Pair& lhs, const Pair& rhs) {
+ return !(lhs < rhs);
+}
+
+} /* namespace etRuntime */
+#endif /* PAIR_H_ */
+
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Set.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Set.cpp
new file mode 100644
index 000000000..e00d75d92
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Set.cpp
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2017 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+#include "common/containers/Set.h"
+
+namespace etRuntime {
+
+size_t SetStats::ncreated = 0;
+size_t SetStats::ndestroyed = 0;
+
+} /* namespace etRuntime */
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Set.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Set.h
new file mode 100644
index 000000000..8fac8cada
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Set.h
@@ -0,0 +1,222 @@
+/*******************************************************************************
+ * Copyright (c) 2017 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+#ifndef SET_H_
+#define SET_H_
+
+#include "etDatatypes.h"
+#include "Vector.h"
+
+namespace etRuntime {
+
+/**
+ * common set base class with counters for allocations and deallocations
+ */
+class SetStats {
+public:
+ static size_t getNCreated() { return ncreated; }
+ static size_t getNDestroyed() { return ndestroyed; }
+
+private:
+ template friend class Set;
+ static size_t ncreated;
+ static size_t ndestroyed;
+};
+
+template
+class Set {
+public:
+
+ typedef typename Vector::iterator iterator;
+ typedef typename Vector::const_iterator const_iterator;
+ typedef typename Vector::reverse_iterator reverse_iterator;
+
+ /**
+ * default constructor
+ */
+ Set()
+ : _container()
+ {
+ ++SetStats::ncreated;
+ }
+
+ /**
+ * copy constructor
+ */
+ Set(const Set &rhs)
+ : _container(rhs._container)
+ {
+ ++SetStats::ncreated;
+ }
+
+ /**
+ * virtual destructor
+ */
+ virtual ~Set(void) {
+ ++SetStats::ndestroyed;
+ }
+
+ /**
+ * Requests that the set capacity be at least enough to contain n elements.
+ *
+ * If n is greater than the current set capacity, the function causes the container
+ * to reallocate its storage increasing its capacity to n (or greater).
+ * In all other cases, the function call does not cause a reallocation and the set
+ * capacity is not affected.
+ *
+ * This function has no effect on the set size and cannot alter its elements.
+ */
+ void reserve(size_t n) {
+ _container.reserve(n);
+ }
+
+ /**
+ * returns the _size of this set
+ */
+ int size(void) const {
+ return _container.size();
+ }
+
+ /**
+ * Returns whether the set is empty (i.e. whether its size is 0).
+ * This function does not modify the container in any way.
+ * To clear the content of a set, see Set::clear.
+ */
+ bool empty(void) const {
+ return _container.empty();
+ }
+
+ void clear() {
+ _container.clear();
+ }
+
+ bool insert(const Type& t) {
+ iterator it = find(t);
+ if (it==end()) {
+ _container.push_back(t);
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+
+ iterator find(const Type& t) {
+ for (iterator it=begin(); it!=end(); ++it) {
+ if (t==*it) {
+ return it;
+ }
+ }
+ return end();
+ }
+
+ const_iterator find(const Type& t) const {
+ for (const_iterator it=begin(); it!=end(); ++it) {
+ if (t==*it) {
+ return it;
+ }
+ }
+ return end();
+ }
+
+ iterator erase(iterator position) {
+ return _container.erase(position);
+ }
+
+ size_t erase(const Type& t) {
+ iterator it = find(t);
+ if (it==end()) {
+ return 0;
+ }
+ else {
+ _container.erase(it);
+ return 1;
+ }
+ }
+
+ /**
+ * returns a pointer to the _data of this set (as a C array)
+ */
+ Type* getData(void) {
+ return _container.getData();
+ }
+
+ /**
+ * returns a const pointer to the _data of this set (as a C array)
+ */
+ const Type* getData(void) const {
+ return _container.getData();
+ }
+
+ /**
+ * copy assignment makes a deep copy
+ */
+ Set& operator=(const Set &rhs) {
+ _container = rhs._container;
+ return *this;
+ }
+
+ const_iterator begin() const {
+ return _container.begin();
+ }
+
+ const_iterator end() const {
+ return _container.end();
+ }
+
+ iterator begin() {
+ return _container.begin();
+ }
+
+ iterator end() {
+ return _container.end();
+ }
+
+ reverse_iterator rbegin() {
+ return _container.rbegin();
+ }
+
+ reverse_iterator rend() {
+ return _container.rend();
+ }
+
+protected:
+ Vector _container;
+};
+
+/**
+ * comparison operator (expensive because not ordered - O(n^2))
+ */
+template
+inline bool operator==(const Set lhs, const Set rhs) {
+ if (rhs.size()!=lhs.size()) {
+ return false;
+ }
+
+ // are all elements contained in rhs?
+ for (typename Set::const_iterator it=lhs.begin(); it!=lhs.end(); ++it) {
+ if (rhs.find(*it)==rhs.end()) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+template
+inline bool operator!=(const Set &lhs, const Set &rhs) {
+ return !(lhs==rhs);
+}
+
+} /* namespace etRuntime */
+#endif /* SET_H_ */
+
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/String.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/String.cpp
new file mode 100644
index 000000000..a82c11dd8
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/String.cpp
@@ -0,0 +1,169 @@
+/*******************************************************************************
+ * Copyright (c) 2017 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+#include "common/containers/String.h"
+
+namespace etRuntime {
+
+size_t String::nallocs = 0;
+size_t String::ndeallocs = 0;
+size_t String::ncreated = 0;
+size_t String::ndestroyed = 0;
+
+String::String()
+: _size(0)
+, _data(new char[1])
+{
+ ++nallocs;
+ ++ncreated;
+ _data[0] = '\0';
+}
+
+String::~String(void) {
+ ++ndestroyed;
+ if (_data) {
+ delete[] _data;
+ ++ndeallocs;
+ }
+}
+
+/*
+ * added this according to
+ * http://stackoverflow.com/questions/1634359/is-there-a-reverse-function-for-strstr
+ */
+static const char *rstrstr(const char * s1, const char * s2) {
+ size_t s1len = strlen(s1);
+ size_t s2len = strlen(s2);
+ const char *s;
+
+ if (s2len > s1len) {
+ return NULL;
+ }
+ for (s = s1 + s1len - s2len; s >= s1; --s) {
+ if (strncmp(s, s2, s2len) == 0) {
+ return s;
+ }
+ }
+ return NULL;
+}
+
+String& String::operator=(const char *rhs) {
+ if (rhs && rhs!=this->_data) {
+ size_t new_size = std::strlen(rhs) + 1;
+ if (new_size > _size) {
+ _size = new_size;
+ if (_data) {
+ delete[] _data;
+ ++ndeallocs;
+ }
+ _data = new char[new_size];
+ ++nallocs;
+ }
+ std::strcpy(this->_data, rhs);
+ }
+ return *this;
+}
+
+const String String::operator+=(const char* rhs) {
+ if (rhs) {
+ size_t new_size = this->length() + std::strlen(rhs) + 1;
+ if (new_size > _size) {
+ _size = new_size;
+ char* new_data = new char[new_size];
+ ++nallocs;
+ if (_data) {
+ std::strcpy(new_data, _data);
+ delete[] _data;
+ ++ndeallocs;
+ }
+ else {
+ new_data[0] = '\0';
+ }
+ _data = new_data;
+ }
+ std::strcat(this->_data, rhs);
+ }
+
+ // Note: this function returns a const, not a const&!
+ // this prohibits things like (a + b) = c
+ return *this;
+}
+
+const String String::operator+=(char c) {
+ size_t new_size = this->length() + 2;
+ if (new_size > _size) {
+ _size = new_size;
+ char* new_data = new char[new_size];
+ ++nallocs;
+ if (_data) {
+ std::strcpy(new_data, _data);
+ delete[] _data;
+ ++ndeallocs;
+ }
+ _data = new_data;
+ }
+ _data[new_size-2] = c;
+ _data[new_size-1] = '\0';
+
+ // Note: this function returns a const, not a const&!
+ // this prohibits things like (a + b) = c
+ return *this;
+}
+
+size_t String::find(const String& str, size_t pos) const {
+ if (pos>length()) {
+ return npos;
+ }
+ return std::strstr(_data + pos, str._data) - _data;
+}
+
+size_t String::find(const char* str, size_t pos) const {
+ if (pos>length()) {
+ return npos;
+ }
+ return std::strstr(_data + pos, str) - _data;
+}
+
+size_t String::find(char c, size_t pos) const {
+ if (pos>length()) {
+ return npos;
+ }
+ return std::strchr(_data + pos, c) - _data;
+}
+
+size_t String::rfind(const String& str) const {
+ return rstrstr(_data, str._data) - _data;
+}
+
+size_t String::rfind(const char* str) const {
+ return rstrstr(_data, str) - _data;
+}
+
+size_t String::rfind(char c) const {
+ return std::strrchr(_data, c) - _data;
+}
+
+
+String String::substr(size_t pos, size_t len) const {
+ if (pos > length()) {
+ return String("");
+ }
+
+ String result(_data+pos);
+ if (len < result.length()) {
+ result._data[len] = '\0';
+ }
+
+ return result;
+}
+
+} /* namespace etRuntime */
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/String.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/String.h
new file mode 100644
index 000000000..70ac624b8
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/String.h
@@ -0,0 +1,318 @@
+/*******************************************************************************
+ * Copyright (c) 2017 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+#ifndef STRING_H_
+#define STRING_H_
+
+#include
+#include
+
+namespace etRuntime {
+
+/**
+ * a static size string class that basically encapsulates a C string
+ */
+class String {
+public:
+ /**
+ * default constructor is empty string
+ */
+ String();
+
+ /**
+ * copy constructor calls operator=(const char *rhs)
+ */
+ String(const String &rhs)
+ : _size(0)
+ , _data(0)
+ {
+ ++ncreated;
+ operator=(rhs._data);
+ }
+
+ /**
+ * constructor calls operator=(const char *rhs)
+ */
+ String(const char *rhs)
+ : _size(0)
+ , _data(0)
+ {
+ ++ncreated;
+ operator=(rhs);
+ }
+
+ /**
+ * virtual destructor
+ */
+ virtual ~String(void);
+
+
+ /**
+ * returns the length of the C string stored
+ */
+ size_t length(void) const
+ {
+ return std::strlen(this->_data);
+ }
+
+ /**
+ * returns a const char * pointer to the data of this array
+ */
+ const char* c_str(void) const
+ {
+ return this->_data;
+ }
+
+ /**
+ * returns the character at the given position. If index is out of range 0 is returned
+ */
+ char operator[](int index) const {
+ return (index < 0 || index >= (int)_size) ? 0 : _data[index];
+ }
+
+ /**
+ * forwards to operator=(const char *rhs)
+ */
+ String& operator=(const String &rhs)
+ {
+ return operator=(rhs._data);
+ }
+
+ /**
+ * creates a copy of the rhs
+ */
+ String& operator=(const char *rhs);
+
+ //
+ // string concatenation
+ //
+
+ /*
+ * concatenates the rhs to the end of the string.
+ */
+ const String operator+=(const String& rhs) {
+ return operator+=(rhs._data);
+ }
+
+ /*
+ * concatenates the rhs to the end of the string.
+ */
+ const String operator+=(const char* rhs);
+
+ /*
+ * concatenates the c to the end of the string.
+ */
+ const String operator+=(char c);
+
+ //
+ // comparison
+ //
+
+ /**
+ * compares two strings
+ */
+ int compare(const String& rhs) const {
+ return std::strcmp(this->_data, rhs._data);
+ }
+ int compareXX(const String& rhs) const {
+ return std::strcmp(this->_data, rhs._data);
+ }
+//
+// /**
+// * compares a string with a C-String
+// */
+// int compare(const char *rhs) const {
+// return strcmp(this->_data, rhs);
+// }
+
+ //
+ // find
+ //
+ static const size_t npos = -1;
+
+ size_t find(const String& str, size_t pos = 0) const;
+ size_t find(const char* str, size_t pos = 0) const;
+ size_t find(char c, size_t pos = 0) const;
+
+ size_t rfind(const String& str) const;
+ size_t rfind(const char* str) const;
+ size_t rfind(char c) const;
+
+ //
+ // sub strings
+ //
+ String substr(size_t pos = 0, size_t len = npos) const;
+
+ static size_t getNAllocations() { return nallocs; }
+ static size_t getNDeallocations() { return ndeallocs; }
+ static size_t getNCreated() { return ncreated; }
+ static size_t getNDestroyed() { return ndestroyed; }
+
+private:
+ static size_t nallocs;
+ static size_t ndeallocs;
+ static size_t ncreated;
+ static size_t ndestroyed;
+
+ size_t _size;
+ char* _data;
+};
+
+//
+// string concatenation
+//
+
+/**
+ * concatenates lhs and rhs.
+ */
+inline const String operator+(const String &lhs, const String &rhs) {
+ // make a copy and add
+ return String(lhs) += rhs;
+}
+
+/**
+ * concatenates lhs and rhs.
+ */
+inline const String operator+(const String &lhs, const char* rhs) {
+ // make a copy and add
+ return String(lhs) += rhs;
+}
+
+/**
+ * concatenates lhs and c
+ */
+inline const String operator+(const String &lhs, char c) {
+ // make a copy and add
+ String result(lhs);
+ result += c;
+ return result;
+}
+
+/**
+ * concatenates lhs and rhs.
+ */
+inline const String operator+(const char* lhs, const String& rhs) {
+ // create a string and add
+ String result(lhs);
+ result += rhs;
+ return result;
+}
+
+/**
+ * concatenates c and rhs.
+ */
+inline const String operator+(char c, const String& rhs) {
+ // create a string and add
+ String result("");
+ result += c;
+ result += rhs;
+ return result;
+}
+
+//
+// string comparison
+//
+
+/**
+ * compares two strings
+ */
+inline bool operator==(const String& lhs, const String &rhs) {
+ return lhs.compare(rhs)==0;
+}
+
+/**
+ * compares a string with a C-string
+ */
+inline bool operator==(const String& lhs, const char *rhs) {
+ return lhs.compare(rhs)==0;
+}
+
+/**
+ * compares a C-string with a string
+ */
+inline bool operator==(const char* lhs, const String& rhs) {
+ return rhs.compare(lhs)==0;
+}
+
+/**
+ * compares two strings
+ */
+inline bool operator!=(const String &lhs, const String &rhs) {
+ return !(lhs == rhs);
+}
+
+/**
+ * compares a string and a C-string
+ */
+inline bool operator!=(const String &lhs, const char *rhs) {
+ return !(lhs == rhs);
+}
+
+/**
+ * compares a C-string and a string
+ */
+inline bool operator!=(const char* lhs, const String& rhs) {
+ return !(lhs == rhs);
+}
+
+inline bool operator<(const String &lhs, const String& rhs) {
+ return lhs.compare(rhs) < 0;
+}
+
+inline bool operator<(const String &lhs, const char* rhs) {
+ return lhs.compare(rhs) < 0;
+}
+
+inline bool operator<(const char* lhs, const String& rhs) {
+ return rhs.compare(lhs) > 0;
+}
+
+inline bool operator<=(const String &lhs, const String& rhs) {
+ return lhs.compare(rhs) <= 0;
+}
+
+inline bool operator<=(const String &lhs, const char* rhs) {
+ return lhs.compare(rhs) <= 0;
+}
+
+inline bool operator<=(const char* lhs, const String& rhs) {
+ return rhs.compare(lhs) >= 0;
+}
+
+inline bool operator>(const String &lhs, const String& rhs) {
+ return lhs.compare(rhs) > 0;
+}
+
+inline bool operator>(const String &lhs, const char* rhs) {
+ return lhs.compare(rhs) > 0;
+}
+
+inline bool operator>(const char* lhs, const String& rhs) {
+ return rhs.compare(lhs) < 0;
+}
+
+inline bool operator>=(const String &lhs, const String& rhs) {
+ return lhs.compare(rhs) >= 0;
+}
+
+inline bool operator>=(const String &lhs, const char* rhs) {
+ return lhs.compare(rhs) >= 0;
+}
+
+inline bool operator>=(const char* lhs, const String& rhs) {
+ return rhs.compare(lhs) <= 0;
+}
+
+} /* namespace etRuntime */
+
+#endif /* STRING_H_ */
+
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Vector.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Vector.cpp
new file mode 100644
index 000000000..e688803eb
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Vector.cpp
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2017 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+#include "common/containers/Vector.h"
+
+namespace etRuntime {
+
+size_t VectorStats::nallocs = 0;
+size_t VectorStats::ndeallocs = 0;
+size_t VectorStats::ncreated = 0;
+size_t VectorStats::ndestroyed = 0;
+
+} /* namespace etRuntime */
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Vector.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Vector.h
new file mode 100644
index 000000000..065a58f9d
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/containers/Vector.h
@@ -0,0 +1,334 @@
+/*******************************************************************************
+ * Copyright (c) 2017 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+#ifndef VECTOR_H_
+#define VECTOR_H_
+
+#include "etDatatypes.h"
+#include
+
+namespace etRuntime {
+
+/**
+ * common vector base class with counters for allocations and deallocations
+ */
+class VectorStats {
+public:
+ static size_t getNAllocations() { return nallocs; }
+ static size_t getNDeallocations() { return ndeallocs; }
+ static size_t getNCreated() { return ncreated; }
+ static size_t getNDestroyed() { return ndestroyed; }
+
+private:
+ template friend class Vector;
+ static size_t nallocs;
+ static size_t ndeallocs;
+ static size_t ncreated;
+ static size_t ndestroyed;
+};
+
+template
+class Vector {
+public:
+
+ typedef Type* iterator;
+ typedef const Type* const_iterator;
+
+ class reverse_iterator {
+ public:
+ reverse_iterator(Type* d) : _current(d) {}
+ reverse_iterator(const reverse_iterator& rhs) : _current(rhs._current) {}
+
+ reverse_iterator& operator=(const reverse_iterator& rhs) {
+ _current = rhs._current;
+ return *this;
+ }
+
+ Type operator*() const {
+ Type* tmp = _current;
+ return *(--tmp);
+ }
+ Type* operator->() const {
+ return &(operator*());
+ }
+
+ reverse_iterator& operator++() {
+ --_current;
+ return *this;
+ }
+ reverse_iterator operator++(int) {
+ reverse_iterator tmp = *this;
+ --_current;
+ return tmp;
+ }
+ reverse_iterator& operator--() {
+ ++_current;
+ return *this;
+ }
+ reverse_iterator operator--(int) {
+ reverse_iterator tmp = *this;
+ ++_current;
+ return tmp;
+ }
+
+ bool operator==(const reverse_iterator& rhs) const {
+ return _current == rhs._current;
+ }
+ bool operator!=(const reverse_iterator& rhs) const {
+ return !(operator==(rhs));
+ }
+ private:
+ Type* _current;
+ };
+
+ /**
+ * default constructor
+ */
+ Vector()
+ : _size(0)
+ , _capacity(0)
+ , _data(0)
+ {
+ ++VectorStats::ncreated;
+ }
+
+ /**
+ * copy constructor
+ */
+ Vector(const Vector &rhs)
+ : _size(rhs._size)
+ , _capacity(rhs._size)
+ , _data(new Type[rhs._size])
+ {
+ ++VectorStats::ncreated;
+ ++VectorStats::nallocs;
+ for (int i = 0; i < _size; i++) {
+ _data[i] = rhs[i];
+ }
+ }
+
+ /**
+ * initializes each vector element to t
+ */
+ Vector(size_t size, const Type& t=Type())
+ : _size(size)
+ , _capacity(size)
+ , _data(new Type[size])
+ {
+ ++VectorStats::ncreated;
+ ++VectorStats::nallocs;
+ for (int i = 0; i < _size; i++) {
+ _data[i] = t;
+ }
+ }
+
+ /**
+ * virtual destructor
+ */
+ virtual ~Vector(void) {
+ ++VectorStats::ndestroyed;
+ if (_data) {
+ delete[] _data;
+ ++VectorStats::ndeallocs;
+ }
+ }
+
+ /**
+ * Requests that the vector capacity be at least enough to contain n elements.
+ *
+ * If n is greater than the current vector capacity, the function causes the container
+ * to reallocate its storage increasing its capacity to n (or greater).
+ * In all other cases, the function call does not cause a reallocation and the vector
+ * capacity is not affected.
+ *
+ * This function has no effect on the vector size and cannot alter its elements.
+ */
+ void reserve(size_t n) {
+ if (n > _capacity) {
+ _capacity = n;
+ Type* new_data = new Type[_capacity];
+ ++VectorStats::nallocs;
+ if (_data) {
+ for (int i = 0; i < _size; i++) {
+ new_data[i] = _data[i];
+ }
+ delete[] _data;
+ ++VectorStats::ndeallocs;
+ }
+ _data = new_data;
+ }
+ }
+
+ /**
+ * returns the _size of this vector
+ */
+ int size(void) const {
+ return _size;
+ }
+
+ /**
+ * Returns whether the vector is empty (i.e. whether its size is 0).
+ * This function does not modify the container in any way.
+ * To clear the content of a vector, see Vector::clear.
+ */
+ bool empty(void) const {
+ return _size==0;
+ }
+
+ void clear() {
+ _size = 0;
+ _capacity = 0;
+ if (_data) {
+ delete[] _data;
+ ++VectorStats::ndeallocs;
+ }
+ _data = 0;
+ }
+
+ void push_back(const Type& t) {
+ if (_size>=_capacity) {
+ reserve(_size + const_grow_by);
+ }
+
+ _data[_size++] = t;
+ }
+
+ void pop_back() {
+ if (_size>0) {
+ --_size;
+ }
+ }
+
+ iterator erase (iterator position) {
+ if (_size>0 && (position >= _data) && (position < _data+_size)) {
+ // copy following elements one position down each
+ iterator curr = position;
+ iterator next = position + 1;
+ for (; next!=end(); ++curr, ++next) {
+ *curr = *next;
+ }
+ --_size;
+ }
+ return position;
+ }
+
+ /**
+ * returns a pointer to the _data of this vector (as a C array)
+ */
+ Type* getData(void) {
+ return this->_data;
+ }
+
+ /**
+ * returns a const pointer to the _data of this vector (as a C array)
+ */
+ const Type* getData(void) const {
+ return this->_data;
+ }
+
+ /**
+ * indexed access without range check
+ */
+ Type& operator[](int index) {
+ return _data[index];
+ }
+
+ /**
+ * indexed access without range check
+ */
+ const Type& operator[](int index) const {
+ return _data[index];
+ }
+
+ Type& front() {
+ return _data[0];
+ }
+
+ const Type& front() const {
+ return _data[0];
+ }
+
+ Type& back() {
+ return _data[_size-1];
+ }
+
+ const Type& back() const {
+ return _data[_size-1];
+ }
+
+ /**
+ * copy assignment makes a deep copy
+ */
+ Vector& operator=(const Vector &rhs) {
+ if (&rhs!=this) {
+ _size = rhs._size;
+ if (_size > _capacity) {
+ _capacity = _size;
+ if (_data) {
+ delete[] _data;
+ ++VectorStats::ndeallocs;
+ }
+ _data = new Type[_capacity];
+ ++VectorStats::nallocs;
+ }
+ for (int i = 0; i < _size; i++) {
+ _data[i] = rhs[i];
+ }
+ }
+ return *this;
+ }
+
+ /**
+ * comparison operator based on memcmp()
+ */
+ bool operator==(const Vector &rhs) const {
+ return _size!=rhs._size ? false : std::memcmp(this->_data, rhs._data, _size*sizeof(*_data)) == 0;
+ }
+ bool operator!=(const Vector &rhs) const {
+ return !(operator==(rhs));
+ }
+
+ const_iterator begin() const {
+ return _data;
+ }
+
+ const_iterator end() const {
+ return _data + _size;
+ }
+
+ iterator begin() {
+ return _data;
+ }
+
+ iterator end() {
+ return _data + _size;
+ }
+
+ reverse_iterator rbegin() {
+ return reverse_iterator(_data + _size);
+ }
+
+ reverse_iterator rend() {
+ return reverse_iterator(_data);
+ }
+
+protected:
+ size_t _size;
+ size_t _capacity;
+ Type* _data; ///< the C array holding the _data
+
+ static const size_t const_grow_by = 4;
+};
+
+} /* namespace etRuntime */
+#endif /* VECTOR_H_ */
+
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/DebuggingService.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/DebuggingService.cpp
index b2dedc349..7216a1640 100644
--- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/DebuggingService.cpp
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/DebuggingService.cpp
@@ -15,7 +15,6 @@
#include "common/modelbase/ActorClassBase.h"
#include "common/modelbase/SubSystemClassBase.h"
#include "common/modelbase/InterfaceItemBase.h"
-#include
namespace etRuntime {
@@ -32,66 +31,76 @@ DebuggingService::DebuggingService() :
}
const InterfaceItemBase* DebuggingService::getPort(const Address& address) const {
- std::map::const_iterator it = m_portInstances.find(address);
+ Map::const_iterator it = m_portInstances.find(address);
if (it != m_portInstances.end())
return it->second;
return 0;
}
-void DebuggingService::addMessageAsyncOut(const Address& source, const Address& target, const std::string& msg) {
+void DebuggingService::addMessageAsyncOut(const Address& source, const Address& target, const String& msg) {
const InterfaceItemBase* srcPort = getPort(source);
const InterfaceItemBase* tgtPort = getPort(target);
- if (srcPort != 0 && tgtPort != 0)
- m_asyncLogger.addMessageAsyncOut(srcPort->getActor()->getInstancePath(), tgtPort->getActor()->getInstancePath(),
- msg);
+ if (srcPort != 0 && tgtPort != 0) {
+ etRuntime::String srcPath = srcPort->getActor()->getInstancePath();
+ etRuntime::String tgtPath = tgtPort->getActor()->getInstancePath();
+ m_asyncLogger.addMessageAsyncOut(srcPath, tgtPath, msg);
+ }
}
-void DebuggingService::addMessageAsyncIn(const Address& source, const Address& target, const std::string& msg) {
+void DebuggingService::addMessageAsyncIn(const Address& source, const Address& target, const String& msg) {
const InterfaceItemBase* srcPort = getPort(source);
const InterfaceItemBase* tgtPort = getPort(target);
- if (srcPort != 0 && tgtPort != 0)
- m_asyncLogger.addMessageAsyncIn(srcPort->getActor()->getInstancePath(), tgtPort->getActor()->getInstancePath(),
- msg);
+ if (srcPort != 0 && tgtPort != 0) {
+ etRuntime::String srcPath = srcPort->getActor()->getInstancePath();
+ etRuntime::String tgtPath = tgtPort->getActor()->getInstancePath();
+ m_asyncLogger.addMessageAsyncIn(srcPath, tgtPath, msg);
+ }
}
-void DebuggingService::addMessageSyncCall(const Address& source, const Address& target, const std::string& msg) {
+void DebuggingService::addMessageSyncCall(const Address& source, const Address& target, const String& msg) {
const InterfaceItemBase* srcPort = getPort(source);
const InterfaceItemBase* tgtPort = getPort(target);
- if (srcPort != 0 && tgtPort != 0)
- m_asyncLogger.addMessageSyncCall(srcPort->getActor()->getInstancePath(), tgtPort->getActor()->getInstancePath(),
- msg);
+ if (srcPort != 0 && tgtPort != 0) {
+ etRuntime::String srcPath = srcPort->getActor()->getInstancePath();
+ etRuntime::String tgtPath = tgtPort->getActor()->getInstancePath();
+ m_asyncLogger.addMessageSyncCall(srcPath, tgtPath, msg);
+ }
}
-void DebuggingService::addMessageSyncReturn(const Address& source, const Address& target, const std::string& msg) {
+void DebuggingService::addMessageSyncReturn(const Address& source, const Address& target, const String& msg) {
const InterfaceItemBase* srcPort = getPort(source);
const InterfaceItemBase* tgtPort = getPort(target);
- if (srcPort != 0 && tgtPort != 0)
+ if (srcPort != 0 && tgtPort != 0) {
m_asyncLogger.addMessageSyncReturn(srcPort->getActor()->getInstancePath(),
tgtPort->getActor()->getInstancePath(), msg);
+ }
}
-void DebuggingService::addActorState(const ActorClassBase& actor, const std::string& state) {
- m_asyncLogger.addActorState(actor.getInstancePath(), state);
+void DebuggingService::addActorState(const ActorClassBase& actor, const String& state) {
+ etRuntime::String instancePath = actor.getInstancePath();
+ m_asyncLogger.addActorState(instancePath, state);
}
-void DebuggingService::addMessageActorCreate(const SubSystemClassBase& parent, const std::string& refName) {
- m_asyncLogger.addMessageActorCreate(parent.getInstancePath(),
- parent.getInstancePath() + IRTObject::PATH_DELIM + refName);
+void DebuggingService::addMessageActorCreate(const SubSystemClassBase& parent, const String& refName) {
+ etRuntime::String parentPath = parent.getInstancePath();
+ m_asyncLogger.addMessageActorCreate(parentPath, String(parentPath) + IRTObject::PATH_DELIM + refName);
}
-void DebuggingService::addMessageActorCreate(const ActorClassBase& parent, const std::string& refName) {
- m_asyncLogger.addMessageActorCreate(parent.getInstancePath(),
- parent.getInstancePath() + IRTObject::PATH_DELIM + refName);
+void DebuggingService::addMessageActorCreate(const ActorClassBase& parent, const String& refName) {
+ etRuntime::String parentPath = parent.getInstancePath();
+ m_asyncLogger.addMessageActorCreate(parentPath, String(parentPath) + IRTObject::PATH_DELIM + refName);
}
void DebuggingService::addMessageActorDestroy(const ActorClassBase& inst) {
+ etRuntime::String parentPath = inst.getParent()->getInstancePath();
+ etRuntime::String instancePath = inst.getInstancePath();
//if (!(inst.getParent() instanceof OptionalActorInterfaceBase))
- m_asyncLogger.addMessageActorDestroy(inst.getParent()->getInstancePath(), inst.getInstancePath());
+ m_asyncLogger.addMessageActorDestroy(parentPath, instancePath);
}
-void DebuggingService::addVisibleComment(const std::string& comment) {
+void DebuggingService::addVisibleComment(const String& comment) {
m_asyncLogger.addVisibleComment(comment);
}
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/DebuggingService.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/DebuggingService.h
index 0ac9e6354..ff070c243 100644
--- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/DebuggingService.h
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/DebuggingService.h
@@ -14,11 +14,10 @@
#define DEBUGGINGSERVICE_H_
#include "common/debugging/MSCLogger.h"
+#include "common/containers/Map.h"
#include "common/messaging/Address.h"
#include "etDatatypes.h"
#include "common/modelbase/InterfaceItemBase.h"
-#include
-#include