| 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 "field.h" |
| 5 | #include "visitor.h" |
| 6 | |
| 7 | #include <QtCore/qdebug.h> |
| 8 | #include <QtCore/qstringlist.h> |
| 9 | |
| 10 | using namespace Qt::Literals::StringLiterals; |
| 11 | |
| 12 | Field::Field(const QString &name, const QString &typeName, const QString &lengthField) |
| 13 | : XmlElement(name) |
| 14 | , m_lengthField(lengthField) |
| 15 | , m_typeName(typeName) |
| 16 | {} |
| 17 | |
| 18 | QString Field::typeName() const |
| 19 | { |
| 20 | return m_typeName; |
| 21 | } |
| 22 | |
| 23 | QString Field::typeNameSecondPart() const |
| 24 | { |
| 25 | return m_typeName.split(sep: ':'_L1).value(i: 1, defaultValue: QString()); |
| 26 | } |
| 27 | |
| 28 | void Field::setTypeName(const QString &typeName) |
| 29 | { |
| 30 | m_typeName = typeName; |
| 31 | } |
| 32 | |
| 33 | QString Field::lengthField() const |
| 34 | { |
| 35 | return m_lengthField; |
| 36 | } |
| 37 | |
| 38 | void Field::setLengthField(const QString &lengthField) |
| 39 | { |
| 40 | m_lengthField = lengthField; |
| 41 | } |
| 42 | |
| 43 | bool Field::hasLengthField() const |
| 44 | { |
| 45 | return m_hasLengthField; |
| 46 | } |
| 47 | |
| 48 | void Field::setHasLengthField(bool hasLengthField) |
| 49 | { |
| 50 | m_hasLengthField = hasLengthField; |
| 51 | } |
| 52 | |
| 53 | bool Field::needContainer() const |
| 54 | { |
| 55 | return m_needContainer; |
| 56 | } |
| 57 | |
| 58 | void Field::setNeedContainer(bool needContainer) |
| 59 | { |
| 60 | m_needContainer = needContainer; |
| 61 | } |
| 62 | |
| 63 | bool Field::isInStructuredTypeBitMask() const |
| 64 | { |
| 65 | return m_isInStructuredTypeBitMask; |
| 66 | } |
| 67 | |
| 68 | void Field::setIsInStructuredTypeBitMask(bool isInStructuredTypeBitMask) |
| 69 | { |
| 70 | m_isInStructuredTypeBitMask = isInStructuredTypeBitMask; |
| 71 | } |
| 72 | |
| 73 | int Field::length() const |
| 74 | { |
| 75 | return m_length; |
| 76 | } |
| 77 | |
| 78 | void Field::setLength(int length) |
| 79 | { |
| 80 | m_length = length; |
| 81 | } |
| 82 | |
| 83 | QString Field::switchField() const |
| 84 | { |
| 85 | return m_switchField; |
| 86 | } |
| 87 | |
| 88 | void Field::setSwitchField(const QString &switchField) |
| 89 | { |
| 90 | m_switchField = switchField; |
| 91 | } |
| 92 | |
| 93 | int Field::switchValue() const |
| 94 | { |
| 95 | return m_switchValue; |
| 96 | } |
| 97 | |
| 98 | void Field::setSwitchValue(int switchValue) |
| 99 | { |
| 100 | m_switchValue = switchValue; |
| 101 | } |
| 102 | |
| 103 | bool Field::isUnion() const |
| 104 | { |
| 105 | return m_isUnion; |
| 106 | } |
| 107 | |
| 108 | void Field::setIsUnion(bool isUnion) |
| 109 | { |
| 110 | m_isUnion = isUnion; |
| 111 | } |
| 112 | |
| 113 | bool Field::recursive() const |
| 114 | { |
| 115 | return m_recursive; |
| 116 | } |
| 117 | |
| 118 | void Field::setRecursive(bool recursive) |
| 119 | { |
| 120 | m_recursive = recursive; |
| 121 | } |
| 122 | |
| 123 | bool Field::isEnum() const |
| 124 | { |
| 125 | return m_isEnum; |
| 126 | } |
| 127 | |
| 128 | void Field::setIsEnum(bool newIsEnum) |
| 129 | { |
| 130 | m_isEnum = newIsEnum; |
| 131 | } |
| 132 | |
| 133 | void Field::print() const |
| 134 | { |
| 135 | XmlElement::print(); |
| 136 | qDebug() << "Type name: "<< m_typeName; |
| 137 | if (!m_lengthField.isEmpty()) |
| 138 | qDebug() << "Length field: "<< m_lengthField; |
| 139 | } |
| 140 | |
| 141 | void Field::accept(Visitor *visitor) |
| 142 | { |
| 143 | visitor->visit(field: this); |
| 144 | } |
| 145 |
