File indexing completed on 2024-11-10 04:40:47
0001 /* 0002 SPDX-FileCopyrightText: 2017 Daniel Vrátil <dvratil@kde.og> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QList> 0010 #include <QMultiMap> 0011 0012 class Node 0013 { 0014 public: 0015 enum NodeType { 0016 Document, 0017 Class, 0018 Ctor, 0019 Enum, 0020 EnumValue, 0021 Property, 0022 }; 0023 0024 Node(NodeType type, Node *parent); 0025 Node(const Node &) = delete; 0026 Node(Node &&) = delete; 0027 virtual ~Node(); 0028 0029 Node &operator=(const Node &) = delete; 0030 Node &operator=(Node &&) = delete; 0031 0032 NodeType type() const; 0033 Node *parent() const; 0034 0035 void appendNode(Node *child); 0036 0037 const QList<Node const *> &children() const; 0038 0039 protected: 0040 Node *mParent; 0041 QList<Node const *> mChildren; 0042 NodeType mType; 0043 }; 0044 0045 class DocumentNode : public Node 0046 { 0047 public: 0048 DocumentNode(int version); 0049 0050 int version() const; 0051 0052 private: 0053 int mVersion; 0054 }; 0055 0056 class PropertyNode; 0057 class ClassNode : public Node 0058 { 0059 public: 0060 enum ClassType { 0061 Invalid, 0062 Class, 0063 Command, 0064 Response, 0065 Notification, 0066 }; 0067 0068 ClassNode(const QString &name, ClassType type, DocumentNode *parent); 0069 QString name() const; 0070 ClassType classType() const; 0071 QString className() const; 0072 QString parentClassName() const; 0073 QList<PropertyNode const *> properties() const; 0074 0075 static ClassType elementNameToType(QStringView name); 0076 0077 private: 0078 QString mName; 0079 ClassType mClassType; 0080 }; 0081 0082 class CtorNode : public Node 0083 { 0084 public: 0085 struct Argument { 0086 QString name; 0087 QString type; 0088 QString defaultValue; 0089 0090 QString mVariableName() const 0091 { 0092 return QStringLiteral("m") + name[0].toUpper() + QStringView(name).mid(1); 0093 } 0094 }; 0095 0096 CtorNode(const QList<Argument> &args, ClassNode *parent); 0097 ~CtorNode() override; 0098 0099 QList<Argument> arguments() const; 0100 void setArgumentType(const QString &name, const QString &type); 0101 0102 private: 0103 QList<Argument> mArgs; 0104 }; 0105 0106 class EnumNode : public Node 0107 { 0108 public: 0109 enum EnumType { 0110 TypeInvalid, 0111 TypeEnum, 0112 TypeFlag, 0113 }; 0114 0115 EnumNode(const QString &name, EnumType type, ClassNode *parent); 0116 0117 QString name() const; 0118 EnumType enumType() const; 0119 static EnumType elementNameToType(QStringView name); 0120 0121 QString flagsName() const; 0122 0123 private: 0124 QString mName; 0125 EnumType mEnumType; 0126 }; 0127 0128 class EnumValueNode : public Node 0129 { 0130 public: 0131 EnumValueNode(const QString &name, EnumNode *parent); 0132 0133 QString name() const; 0134 void setValue(const QString &value); 0135 QString value() const; 0136 0137 private: 0138 QString mName; 0139 QString mValue; 0140 }; 0141 0142 class PropertyNode : public Node 0143 { 0144 public: 0145 struct Setter { 0146 QString name; 0147 QString type; 0148 QString append; 0149 QString remove; 0150 }; 0151 0152 PropertyNode(const QString &name, const QString &type, ClassNode *parent); 0153 ~PropertyNode() override; 0154 0155 QString type() const; 0156 QString name() const; 0157 0158 void setDefaultValue(const QString &defaultValue); 0159 QString defaultValue() const; 0160 0161 bool readOnly() const; 0162 void setReadOnly(bool readOnly); 0163 0164 bool asReference() const; 0165 void setAsReference(bool asReference); 0166 0167 bool isPointer() const; 0168 bool isEnum() const; 0169 0170 QMultiMap<QString, QString> dependencies() const; 0171 void addDependency(const QString &enumVar, const QString &enumValue); 0172 0173 Setter *setter() const; 0174 void setSetter(Setter *setter); 0175 0176 QString mVariableName() const; 0177 QString setterName() const; 0178 0179 private: 0180 QString mName; 0181 QString mType; 0182 QString mDefaultValue; 0183 QMultiMap<QString, QString> mDepends; 0184 Setter *mSetter; 0185 bool mReadOnly; 0186 bool mAsReference; 0187 };