summaryrefslogtreecommitdiffstats
path: root/src/plugins/opcua/open62541/qopen62541utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/opcua/open62541/qopen62541utils.h')
-rw-r--r--src/plugins/opcua/open62541/qopen62541utils.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/plugins/opcua/open62541/qopen62541utils.h b/src/plugins/opcua/open62541/qopen62541utils.h
index d9738ad..5a40c6c 100644
--- a/src/plugins/opcua/open62541/qopen62541utils.h
+++ b/src/plugins/opcua/open62541/qopen62541utils.h
@@ -41,8 +41,49 @@
#include <QtCore/qstring.h>
+#include <functional>
+
QT_BEGIN_NAMESPACE
+template <typename T>
+class UaDeleter
+{
+public:
+ UaDeleter(T *data, std::function<void(T *value)> f)
+ : m_data(data)
+ , m_function(f)
+ {
+ }
+ ~UaDeleter()
+ {
+ if (m_data)
+ m_function(m_data);
+ }
+private:
+ T *m_data {nullptr};
+ std::function<void(T *attribute)> m_function;
+};
+
+template <uint TYPEINDEX>
+class UaArrayDeleter
+{
+public:
+ UaArrayDeleter(void *data, size_t arrayLength)
+ : m_data(data)
+ , m_arrayLength(arrayLength)
+ {
+ static_assert (TYPEINDEX < UA_TYPES_COUNT, "Invalid index outside the UA_TYPES array.");
+ }
+ ~UaArrayDeleter()
+ {
+ if (m_data && m_arrayLength > 0)
+ UA_Array_delete(m_data, m_arrayLength, &UA_TYPES[TYPEINDEX]);
+ }
+private:
+ void *m_data {nullptr};
+ size_t m_arrayLength {0};
+};
+
namespace Open62541Utils {
UA_NodeId nodeIdFromQString(const QString &name);
QString nodeIdToQString(UA_NodeId id);