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