| 1 | // Copyright (C) 2023 basysKom GmbH, opensource@basyskom.com | 
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only | 
| 3 | |
| 4 | #include "qopcuastructuredefinition.h" | 
| 5 | |
| 6 | #include <QtOpcUa/qopcuastructurefield.h> | 
| 7 | |
| 8 | #include <QtCore/qlist.h> | 
| 9 | #include <QtCore/qvariant.h> | 
| 10 | |
| 11 | QT_BEGIN_NAMESPACE | 
| 12 | |
| 13 | /*! | 
| 14 | \class QOpcUaStructureDefinition | 
| 15 | \inmodule QtOpcUa | 
| 16 | \since 6.7 | 
| 17 | \brief The OPC UA StructureDefinition type. | 
| 18 | |
| 19 | This is the Qt OPC UA representation for the OPC UA StructureDefinition type defined in OPC UA part 3. | 
| 20 | It describes the structure of a structured type. | 
| 21 | */ | 
| 22 | |
| 23 | class QOpcUaStructureDefinitionData : public QSharedData | 
| 24 | { | 
| 25 | public: | 
| 26 | QString defaultEncodingId; | 
| 27 | QString baseDataType; | 
| 28 | QOpcUaStructureDefinition::StructureType structureType = QOpcUaStructureDefinition::StructureType::Structure; | 
| 29 | QList<QOpcUaStructureField> fields; | 
| 30 | }; | 
| 31 | |
| 32 | QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QOpcUaStructureDefinitionData); | 
| 33 | |
| 34 | /*! | 
| 35 | Default constructs a structure definition with no parameters set. | 
| 36 | */ | 
| 37 | QOpcUaStructureDefinition::QOpcUaStructureDefinition() | 
| 38 | : data(new QOpcUaStructureDefinitionData) | 
| 39 | { | 
| 40 | } | 
| 41 | |
| 42 | /*! | 
| 43 | Constructs a structure definition from \a rhs. | 
| 44 | */ | 
| 45 | QOpcUaStructureDefinition::QOpcUaStructureDefinition(const QOpcUaStructureDefinition &rhs) | 
| 46 | : data(rhs.data) | 
| 47 | { | 
| 48 | } | 
| 49 | |
| 50 | /*! | 
| 51 | Sets the values from \a rhs in this structure definition. | 
| 52 | */ | 
| 53 | QOpcUaStructureDefinition &QOpcUaStructureDefinition::operator=(const QOpcUaStructureDefinition &rhs) | 
| 54 | { | 
| 55 | if (this != &rhs) | 
| 56 | data.operator=(o: rhs.data); | 
| 57 | return *this; | 
| 58 | } | 
| 59 | |
| 60 | /*! | 
| 61 | \fn QOpcUaStructureDefinition::QOpcUaStructureDefinition(QOpcUaStructureDefinition &&other) | 
| 62 | |
| 63 | Move-constructs a new structure definition from \a other. | 
| 64 | |
| 65 | \note The moved-from object \a other is placed in a | 
| 66 | partially-formed state, in which the only valid operations are | 
| 67 | destruction and assignment of a new value. | 
| 68 | */ | 
| 69 | |
| 70 | /*! | 
| 71 | \fn QOpcUaStructureDefinition &QOpcUaStructureDefinition::operator=(QOpcUaStructureDefinition &&other) | 
| 72 | |
| 73 | Move-assigns \a other to this QOpcUaStructureDefinition instance. | 
| 74 | |
| 75 | \note The moved-from object \a other is placed in a | 
| 76 | partially-formed state, in which the only valid operations are | 
| 77 | destruction and assignment of a new value. | 
| 78 | */ | 
| 79 | |
| 80 | /*! | 
| 81 | \fn void QOpcUaStructureDefinition::swap(QOpcUaStructureDefinition &other) | 
| 82 | |
| 83 | Swaps structure definition object \a other with this structure definition | 
| 84 | object. This operation is very fast and never fails. | 
| 85 | */ | 
| 86 | |
| 87 | /*! | 
| 88 | \fn bool QOpcUaStructureDefinition::operator!=(const QOpcUaStructureDefinition &lhs, const QOpcUaStructureDefinition &rhs) noexcept | 
| 89 | |
| 90 | Returns \c true if \a lhs is not equal to \a rhs. | 
| 91 | */ | 
| 92 | |
| 93 | /*! | 
| 94 | \fn bool QOpcUaStructureDefinition::operator==(const QOpcUaStructureDefinition &lhs, const QOpcUaStructureDefinition &rhs) noexcept | 
| 95 | |
| 96 | Returns \c true if \a lhs is equal to \a rhs. | 
| 97 | */ | 
| 98 | bool comparesEqual(const QOpcUaStructureDefinition &lhs, const QOpcUaStructureDefinition &rhs) noexcept | 
| 99 | { | 
| 100 | return lhs.data->defaultEncodingId == rhs.defaultEncodingId() && | 
| 101 | lhs.data->baseDataType == rhs.baseDataType() && | 
| 102 | lhs.data->structureType == rhs.structureType() && | 
| 103 | lhs.data->fields == rhs.fields(); | 
| 104 | } | 
| 105 | |
| 106 | /*! | 
| 107 | Converts this structure definition to \l QVariant. | 
| 108 | */ | 
| 109 | QOpcUaStructureDefinition::operator QVariant() const | 
| 110 | { | 
| 111 | return QVariant::fromValue(value: *this); | 
| 112 | } | 
| 113 | |
| 114 | /*! | 
| 115 | Destroys this structure definition object. | 
| 116 | */ | 
| 117 | QOpcUaStructureDefinition::~QOpcUaStructureDefinition() | 
| 118 | { | 
| 119 | } | 
| 120 | |
| 121 | /*! | 
| 122 | Returns the default encoding node ID for the struct type. | 
| 123 | */ | 
| 124 | QString QOpcUaStructureDefinition::defaultEncodingId() const | 
| 125 | { | 
| 126 | return data->defaultEncodingId; | 
| 127 | } | 
| 128 | |
| 129 | /*! | 
| 130 | Sets the default encoding node ID of the struct type to \a defaultEncodingId. | 
| 131 | */ | 
| 132 | void QOpcUaStructureDefinition::setDefaultEncodingId(const QString &defaultEncodingId) | 
| 133 | { | 
| 134 | if (defaultEncodingId != data->defaultEncodingId) { | 
| 135 | data.detach(); | 
| 136 | data->defaultEncodingId = defaultEncodingId; | 
| 137 | } | 
| 138 | } | 
| 139 | |
| 140 | /*! | 
| 141 | Returns the node id of the base data type of the struct type. | 
| 142 | */ | 
| 143 | QString QOpcUaStructureDefinition::baseDataType() const | 
| 144 | { | 
| 145 | return data->baseDataType; | 
| 146 | } | 
| 147 | |
| 148 | /*! | 
| 149 | Sets the base data type node id of the type to \a baseDataType. | 
| 150 | */ | 
| 151 | void QOpcUaStructureDefinition::setBaseDataType(const QString &baseDataType) | 
| 152 | { | 
| 153 | if (baseDataType != data->baseDataType) { | 
| 154 | data.detach(); | 
| 155 | data->baseDataType = baseDataType; | 
| 156 | } | 
| 157 | } | 
| 158 | |
| 159 | /*! | 
| 160 | Returns the structure type of the struct type. | 
| 161 | */ | 
| 162 | QOpcUaStructureDefinition::StructureType QOpcUaStructureDefinition::structureType() const | 
| 163 | { | 
| 164 | return data->structureType; | 
| 165 | } | 
| 166 | |
| 167 | /*! | 
| 168 | Sets the structure type to \a structureType. | 
| 169 | */ | 
| 170 | void QOpcUaStructureDefinition::setStructureType(const QOpcUaStructureDefinition::StructureType &structureType) | 
| 171 | { | 
| 172 | if (structureType != data->structureType) { | 
| 173 | data.detach(); | 
| 174 | data->structureType = structureType; | 
| 175 | } | 
| 176 | } | 
| 177 | |
| 178 | /*! | 
| 179 | Returns the fields of the struct type. | 
| 180 | */ | 
| 181 | QList<QOpcUaStructureField> QOpcUaStructureDefinition::fields() const | 
| 182 | { | 
| 183 | return data->fields; | 
| 184 | } | 
| 185 | |
| 186 | /*! | 
| 187 | Sets the fields of the struct type to \a fields. | 
| 188 | */ | 
| 189 | void QOpcUaStructureDefinition::setFields(const QList<QOpcUaStructureField> &fields) | 
| 190 | { | 
| 191 | if (fields != data->fields) { | 
| 192 | data.detach(); | 
| 193 | data->fields = fields; | 
| 194 | } | 
| 195 | } | 
| 196 | |
| 197 | QT_END_NAMESPACE | 
| 198 | 
