1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QOPEN62541VALUECONVERTER_H
5#define QOPEN62541VALUECONVERTER_H
6
7#include "qopen62541.h"
8#include <QtOpcUa/qopcuanode.h>
9#include <QtOpcUa/qopcuatype.h>
10#include <QtOpcUa/qopcuabinarydataencoding.h>
11
12#include <QtCore/qvariant.h>
13
14QT_BEGIN_NAMESPACE
15
16namespace QOpen62541ValueConverter {
17
18 inline UA_AttributeId toUaAttributeId(QOpcUa::NodeAttribute attr)
19 {
20 const int attributeIdUsedBits = 22;
21 for (int i = 0; i < attributeIdUsedBits; ++i)
22 if (static_cast<int>(attr) == (1 << i))
23 return static_cast<UA_AttributeId>(i + 1);
24
25 return static_cast<UA_AttributeId>(0);
26 }
27
28 UA_Variant toOpen62541Variant(const QVariant&, QOpcUa::Types);
29 QVariant toQVariant(const UA_Variant&);
30 const UA_DataType *toDataType(QOpcUa::Types valueType);
31 QOpcUa::Types qvariantTypeToQOpcUaType(QMetaType::Type type);
32
33 template<typename TARGETTYPE, typename UATYPE>
34 TARGETTYPE scalarToQt(const UATYPE *data);
35
36 template<typename TARGETTYPE, typename UATYPE>
37 QVariant arrayToQVariant(const UA_Variant &var, QMetaType::Type type = QMetaType::UnknownType);
38
39 template<typename TARGETTYPE, typename QTTYPE>
40 void scalarFromQt(const QTTYPE &var, TARGETTYPE *ptr);
41
42 template<typename TARGETTYPE, typename QTTYPE>
43 UA_Variant arrayFromQVariant(const QVariant &var, const UA_DataType *type);
44
45 void createExtensionObject(QByteArray &data, const UA_NodeId &typeEncodingId, UA_ExtensionObject *ptr,
46 QOpcUaExtensionObject::Encoding encoding = QOpcUaExtensionObject::Encoding::ByteString);
47}
48
49QT_END_NAMESPACE
50
51#endif // QOPEN62541VALUECONVERTER_H
52

source code of qtopcua/src/plugins/opcua/open62541/qopen62541valueconverter.h