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 "dependencydatatypevalidator.h"
5#include "enumeratedtype.h"
6#include "field.h"
7#include "stringidentifier.h"
8#include "structuredtype.h"
9
10DependencyDataTypeValidator::DependencyDataTypeValidator()
11 : m_readResolveDependencies(ReadDependencies)
12{}
13
14void DependencyDataTypeValidator::visit(EnumeratedType *enumeratedType)
15{
16 if (m_readResolveDependencies == DependencyDataTypeValidator::ResolveDependencies) {
17 if (m_unresolvedDependencyStringList.contains(str: enumeratedType->name())) {
18 m_unresolvedDependencyStringList.removeAll(t: enumeratedType->name());
19 m_resolvedDependencyElementList.push_back(t: enumeratedType);
20 }
21 }
22}
23
24void DependencyDataTypeValidator::visit(EnumeratedValue *enumeratedValue)
25{
26 Q_UNUSED(enumeratedValue);
27}
28
29void DependencyDataTypeValidator::visit(Field *field)
30{
31 if (m_readResolveDependencies == DependencyDataTypeValidator::ReadDependencies) {
32 if (!field->typeName().contains(s: "opc:")) {
33 const auto typeName = field->typeNameSecondPart();
34 for (const auto &precoded : StringIdentifier::opcUaPrecodedTypes) {
35 if (precoded.contains(name: typeName)) {
36 return;
37 }
38 }
39 m_unresolvedDependencyStringList.push_back(t: typeName);
40 }
41 }
42}
43
44void DependencyDataTypeValidator::visit(Import *import)
45{
46 Q_UNUSED(import);
47}
48
49void DependencyDataTypeValidator::visit(StructuredType *structuredType)
50{
51 if (m_readResolveDependencies == DependencyDataTypeValidator::ResolveDependencies) {
52 if (m_unresolvedDependencyStringList.contains(str: structuredType->name())) {
53 m_unresolvedDependencyStringList.removeAll(t: structuredType->name());
54 m_resolvedDependencyElementList.push_back(t: structuredType);
55 for (const auto &field : structuredType->fields()) {
56 const auto typeName = field->typeNameSecondPart();
57
58 if (!StringIdentifier::typeNameDataTypeConverter.contains(key: field->typeName())) {
59 bool isPrecoded = false;
60 for (const auto &precoded : StringIdentifier::opcUaPrecodedTypes) {
61 if (precoded.contains(name: typeName)) {
62 isPrecoded = true;
63 break;
64 }
65 }
66 if (!isPrecoded && !m_unresolvedDependencyStringList.contains(str: typeName)) {
67 bool isResolved = false;
68 for (const auto &type : m_resolvedDependencyElementList) {
69 if (type->name() == typeName) {
70 isResolved = true;
71 break;
72 }
73 }
74 if (!isResolved)
75 m_unresolvedDependencyStringList.push_back(t: typeName);
76 }
77 }
78 }
79 }
80 }
81}
82
83void DependencyDataTypeValidator::visit(TypeDictionary *typeDictionary)
84{
85 Q_UNUSED(typeDictionary);
86}
87
88void DependencyDataTypeValidator::visit(XmlElement *xmlElement)
89{
90 Q_UNUSED(xmlElement);
91}
92
93QStringList DependencyDataTypeValidator::unresolvedDependencyStringList() const
94{
95 return m_unresolvedDependencyStringList;
96}
97
98QList<XmlElement *> DependencyDataTypeValidator::resolvedDependencyElementList() const
99{
100 return m_resolvedDependencyElementList;
101}
102
103void DependencyDataTypeValidator::setReadResolveDependencies(
104 const ReadResolveDependencies &readResolveDependencies)
105{
106 m_readResolveDependencies = readResolveDependencies;
107}
108

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of qtopcua/tools/datatypecodegenerator/dependencydatatypevalidator.cpp