-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuanode.cpp
More file actions
499 lines (417 loc) · 11.2 KB
/
uanode.cpp
File metadata and controls
499 lines (417 loc) · 11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
// SPDX-FileCopyrightText: 2025 Marius Dege <marius.dege@basyskom.com>
// SPDX-FileCopyrightText: 2024 Marius Dege <marius.dege@basyskom.com>
// SPDX-FileCopyrightText: 2024 basysKom GmbH
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "uanode.h"
#include <qdebug.h>
UANode::~UANode()
{
m_references.clear();
}
UANode::UANode(const UANode& other)
: m_nodeId(other.m_nodeId)
, m_browseName(other.m_browseName)
, m_displayName(other.m_displayName)
, m_description(other.m_description)
, m_parentNodeId(other.m_parentNodeId)
, m_namespaceString(other.m_namespaceString)
, m_isOptional(other.m_isOptional)
, m_nodeVariableName(other.m_nodeVariableName)
, m_parentNode(other.m_parentNode)
, m_isRootNode(other.m_isRootNode)
, m_baseBrowseName(other.m_baseBrowseName)
{
// Deep copy of references
for (const std::shared_ptr<Reference>& ref : other.m_references) {
m_references.append(std::make_shared<Reference>(*ref));
}
}
UANode& UANode::operator=(const UANode& other)
{
if (this != &other) {
// clear existing references to prevent memory leaks
m_references.clear();
m_nodeId = other.m_nodeId;
m_browseName = other.m_browseName;
m_displayName = other.m_displayName;
m_description = other.m_description;
m_parentNodeId = other.m_parentNodeId;
m_namespaceString = other.m_namespaceString;
m_isOptional = other.m_isOptional;
m_nodeVariableName = other.m_nodeVariableName;
m_isRootNode = other.m_isRootNode;
m_baseBrowseName = other.m_baseBrowseName;
// Deep copy of references
m_references.reserve(other.m_references.size());
for (const auto& ref : other.m_references) {
m_references.append(std::make_shared<Reference>(*ref));
}
m_parentNode = std::weak_ptr<UANode>(other.m_parentNode);
}
return *this;
}
QString UANode::nodeId() const
{
return m_nodeId;
}
void UANode::setNodeId(const QString& nodeId)
{
m_nodeId = nodeId;
}
QString UANode::browseName() const
{
return m_browseName;
}
void UANode::setBrowseName(const QString& browseName)
{
m_browseName = browseName;
setNodeVariableName();
}
QString UANode::displayName() const
{
return m_displayName;
}
void UANode::setDisplayName(const QString& displayName)
{
m_displayName = displayName;
}
QList<std::shared_ptr<Reference>> UANode::references() const
{
return m_references;
}
void UANode::addReference(std::shared_ptr<Reference> reference)
{
m_references.append(std::move(reference));
}
QString UANode::parentNodeId() const
{
return m_parentNodeId;
}
void UANode::setParentNodeId(const QString& parentNodeId)
{
m_parentNodeId = parentNodeId;
}
QString UANode::description() const
{
return m_description;
}
void UANode::setDescription(const QString& description)
{
m_description = description;
}
std::weak_ptr<UANode> UANode::parentNode() const
{
return m_parentNode;
}
void UANode::setParentNode(std::weak_ptr<UANode> parentNode)
{
m_parentNode = parentNode;
}
QString UANode::namespaceString() const
{
return m_namespaceString;
}
void UANode::setNamespaceString(const QString& newNamespaceString)
{
m_namespaceString = newNamespaceString;
}
bool UANode::isOptional() const
{
return m_isOptional;
}
void UANode::setIsOptional(bool newIsOptional)
{
m_isOptional = newIsOptional;
}
void UANode::changeNamespaceId(const int newNamespaceId)
{
int nsPosition = m_nodeId.indexOf(QStringLiteral("ns="));
if (nsPosition != -1) {
int semicolonPosition = m_nodeId.indexOf(QStringLiteral(";"), nsPosition);
if (semicolonPosition != -1) {
// Replace the namespace number with the new one
QString newNodeId = m_nodeId.replace(
nsPosition + 3,
semicolonPosition - (nsPosition + 3),
QString::number(newNamespaceId));
// Set the new NodeId
setNodeId(newNodeId);
}
}
}
bool UANode::isRootNode() const
{
return m_isRootNode;
}
void UANode::setIsRootNode(bool newIsRootNode)
{
m_isRootNode = newIsRootNode;
}
QString UANode::nodeVariableName() const
{
return m_nodeVariableName;
}
void UANode::setNodeVariableName()
{
QString variableNameStr = Utils::instance()->removeNamespaceIndexFromName(m_browseName)
+ QStringLiteral("_")
+ Utils::instance()->extractIdentifier(m_nodeId);
m_nodeVariableName = variableNameStr;
}
QString UANode::baseBrowseName() const
{
return m_baseBrowseName;
}
void UANode::setBaseBrowseName(const QString& newBaseBrowseName)
{
m_baseBrowseName = newBaseBrowseName;
}
QString UANode::uniqueBaseBrowseName() const
{
return m_uniqueBaseBrowseName;
}
void UANode::setUniqueBaseBrowseName(const QString& newUniqueBaseBrowseName)
{
m_uniqueBaseBrowseName = newUniqueBaseBrowseName;
}
UADataType::UADataType(const UADataType& other)
: UANode(other)
, m_definitionName(other.m_definitionName)
, m_definitionFields(other.m_definitionFields)
, m_isEnum(other.m_isEnum)
{}
UADataType& UADataType::operator=(const UADataType& other)
{
if (this != &other) {
UANode::operator=(other);
m_definitionName = other.m_definitionName;
m_definitionFields = other.m_definitionFields;
m_isEnum = other.m_isEnum;
}
return *this;
}
bool UADataType::operator==(const UADataType& other) const
{
return (m_definitionName == other.m_definitionName)
&& (m_definitionFields == other.m_definitionFields) && (m_isEnum == other.m_isEnum);
}
QString UADataType::definitionName() const
{
return m_definitionName;
}
void UADataType::setDefinitionName(const QString& definitionName)
{
m_definitionName = definitionName;
}
QMap<QString, QString> UADataType::definitionFields() const
{
return m_definitionFields;
}
void UADataType::addDefinitionField(const QString& fieldName, const QString& fieldType)
{
// TODO currently, the definition fields handle ENUM members and datatypes with their name.
// We should store the enum definitions in a separate structure.
m_definitionFields[fieldName] = fieldType;
}
bool UADataType::isEnum() const
{
return m_isEnum;
}
void UADataType::setIsEnum(bool newIsEnum)
{
m_isEnum = newIsEnum;
}
UAObject::UAObject(const UAObject& other)
: UANode(other)
{}
UAObject& UAObject::operator=(const UAObject& other)
{
if (this != &other) {
UANode::operator=(other);
}
return *this;
}
UAVariable::UAVariable(const UAVariable& other)
: UANode(other)
, m_dataType(other.m_dataType)
, m_arguments(other.m_arguments)
, m_arrayDimensions(other.m_arrayDimensions)
, m_valueRank(other.m_valueRank)
{}
UAVariable& UAVariable::operator=(const UAVariable& other)
{
if (this != &other) {
UANode::operator=(other);
m_dataType = other.m_dataType;
m_arguments = other.m_arguments;
m_arrayDimensions = other.m_arrayDimensions;
m_valueRank = other.m_valueRank;
}
return *this;
}
UADataType UAVariable::dataType() const
{
return m_dataType;
}
void UAVariable::setDataType(const UADataType& dataType)
{
m_dataType = dataType;
}
QList<Argument> UAVariable::arguments() const
{
return m_arguments;
}
void UAVariable::setArguments(const QList<Argument>& newArguments)
{
m_arguments = newArguments;
}
int UAVariable::arrayDimensions() const
{
return m_arrayDimensions;
}
void UAVariable::setArrayDimensions(int newArrayDimensions)
{
m_arrayDimensions = newArrayDimensions;
}
int UAVariable::valueRank() const
{
return m_valueRank;
}
void UAVariable::setValueRank(int newValueRank)
{
m_valueRank = newValueRank;
}
UAMethod::UAMethod(const UAMethod& other)
: UANode(other)
, m_inputArgument(
other.m_inputArgument ? std::make_shared<UAVariable>(*other.m_inputArgument) : nullptr)
, m_outputArgument(
other.m_outputArgument ? std::make_shared<UAVariable>(*other.m_outputArgument) : nullptr)
{}
UAMethod& UAMethod::operator=(const UAMethod& other)
{
if (this != &other) {
UANode::operator=(other);
m_inputArgument = other.m_inputArgument
? std::make_shared<UAVariable>(*other.m_inputArgument)
: nullptr;
m_outputArgument = other.m_outputArgument
? std::make_shared<UAVariable>(*other.m_outputArgument)
: nullptr;
}
return *this;
}
void UAMethod::setInputArgument(std::shared_ptr<UAVariable> var)
{
m_inputArgument = var;
}
void UAMethod::setOutputArgument(std::shared_ptr<UAVariable> var)
{
m_outputArgument = var;
}
std::shared_ptr<UAVariable> UAMethod::inputArgument() const
{
return m_inputArgument;
}
std::shared_ptr<UAVariable> UAMethod::outputArgument() const
{
return m_outputArgument;
}
UAVariableType::UAVariableType(const UAVariableType& other)
: UAVariable(other)
, m_isAbstract(other.m_isAbstract)
{}
UAVariableType& UAVariableType::operator=(const UAVariableType& other)
{
if (this != &other) {
UAVariable::operator=(other);
m_isAbstract = other.m_isAbstract;
}
return *this;
}
bool UAVariableType::isAbstract() const
{
return m_isAbstract;
}
void UAVariableType::setIsAbstract(bool isAbstract)
{
m_isAbstract = isAbstract;
}
UAObjectType::UAObjectType(const UAObjectType& other)
: UANode(other)
, m_isAbstract(other.m_isAbstract)
{}
UAObjectType& UAObjectType::operator=(const UAObjectType& other)
{
if (this != &other) {
UANode::operator=(other);
m_isAbstract = other.m_isAbstract;
}
return *this;
}
bool UAObjectType::isAbstract() const
{
return m_isAbstract;
}
void UAObjectType::setIsAbstract(bool isAbstract)
{
m_isAbstract = isAbstract;
}
Reference::Reference(const Reference& other)
: m_referenceType(other.m_referenceType)
, m_targetNodeId(other.m_targetNodeId)
, m_isForward(other.m_isForward)
, m_namespaceString(other.m_namespaceString)
, m_node(other.m_node)
{}
Reference& Reference::operator=(const Reference& other)
{
if (this != &other) {
m_referenceType = other.m_referenceType;
m_targetNodeId = other.m_targetNodeId;
m_isForward = other.m_isForward;
m_namespaceString = other.m_namespaceString;
m_node = other.m_node;
}
return *this;
}
QString Reference::referenceType() const
{
return m_referenceType;
}
void Reference::setReferenceType(const QString& referenceType)
{
m_referenceType = referenceType;
}
QString Reference::targetNodeId() const
{
return m_targetNodeId;
}
void Reference::setTargetNodeId(const QString& targetId)
{
m_targetNodeId = targetId;
}
bool Reference::isForward() const
{
return m_isForward;
}
void Reference::setIsForward(bool isForward)
{
m_isForward = isForward;
}
QString Reference::namespaceString() const
{
return m_namespaceString;
}
void Reference::setNamespaceString(const QString& newNamespaceString)
{
m_namespaceString = newNamespaceString;
}
std::shared_ptr<UANode> Reference::node() const
{
return m_node.lock();
}
void Reference::setNode(std::shared_ptr<UANode> node)
{
m_node = node;
}