| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QMETAOBJECTBUILDER_P_H |
| 5 | #define QMETAOBJECTBUILDER_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists for the convenience |
| 12 | // of moc. This header file may change from version to version without notice, |
| 13 | // or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtCore/private/qglobal_p.h> |
| 19 | #include <QtCore/qobject.h> |
| 20 | #include <QtCore/qmetaobject.h> |
| 21 | #include <QtCore/qdatastream.h> |
| 22 | #include <QtCore/qhash.h> |
| 23 | #include <QtCore/qmap.h> |
| 24 | |
| 25 | #include <private/qmetaobject_p.h> |
| 26 | |
| 27 | QT_BEGIN_NAMESPACE |
| 28 | |
| 29 | class QMetaObjectBuilderPrivate; |
| 30 | class QMetaMethodBuilder; |
| 31 | class QMetaMethodBuilderPrivate; |
| 32 | class QMetaPropertyBuilder; |
| 33 | class QMetaPropertyBuilderPrivate; |
| 34 | class QMetaEnumBuilder; |
| 35 | class QMetaEnumBuilderPrivate; |
| 36 | |
| 37 | class Q_CORE_EXPORT QMetaObjectBuilder |
| 38 | { |
| 39 | public: |
| 40 | enum AddMember |
| 41 | { |
| 42 | ClassName = 0x00000001, |
| 43 | SuperClass = 0x00000002, |
| 44 | Methods = 0x00000004, |
| 45 | Signals = 0x00000008, |
| 46 | Slots = 0x00000010, |
| 47 | Constructors = 0x00000020, |
| 48 | Properties = 0x00000040, |
| 49 | Enumerators = 0x00000080, |
| 50 | ClassInfos = 0x00000100, |
| 51 | RelatedMetaObjects = 0x00000200, |
| 52 | StaticMetacall = 0x00000400, |
| 53 | PublicMethods = 0x00000800, |
| 54 | ProtectedMethods = 0x00001000, |
| 55 | PrivateMethods = 0x00002000, |
| 56 | AllMembers = 0x7FFFFFFF, |
| 57 | AllPrimaryMembers = 0x7FFFFBFC |
| 58 | }; |
| 59 | Q_DECLARE_FLAGS(AddMembers, AddMember) |
| 60 | |
| 61 | QMetaObjectBuilder(); |
| 62 | explicit QMetaObjectBuilder(const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members = AllMembers); |
| 63 | virtual ~QMetaObjectBuilder(); |
| 64 | |
| 65 | QByteArray className() const; |
| 66 | void setClassName(const QByteArray& name); |
| 67 | |
| 68 | const QMetaObject *superClass() const; |
| 69 | void setSuperClass(const QMetaObject *meta); |
| 70 | |
| 71 | MetaObjectFlags flags() const; |
| 72 | void setFlags(MetaObjectFlags); |
| 73 | |
| 74 | int methodCount() const; |
| 75 | int constructorCount() const; |
| 76 | int propertyCount() const; |
| 77 | int enumeratorCount() const; |
| 78 | int classInfoCount() const; |
| 79 | int relatedMetaObjectCount() const; |
| 80 | |
| 81 | QMetaMethodBuilder addMethod(const QByteArray& signature); |
| 82 | QMetaMethodBuilder addMethod(const QByteArray& signature, const QByteArray& returnType); |
| 83 | QMetaMethodBuilder addMethod(const QMetaMethod& prototype); |
| 84 | |
| 85 | QMetaMethodBuilder addSlot(const QByteArray& signature); |
| 86 | QMetaMethodBuilder addSignal(const QByteArray& signature); |
| 87 | |
| 88 | QMetaMethodBuilder addConstructor(const QByteArray& signature); |
| 89 | QMetaMethodBuilder addConstructor(const QMetaMethod& prototype); |
| 90 | |
| 91 | QMetaPropertyBuilder addProperty(const QByteArray& name, const QByteArray& type, int notifierId=-1); |
| 92 | QMetaPropertyBuilder addProperty(const QByteArray& name, const QByteArray& type, QMetaType metaType, int notifierId=-1); |
| 93 | QMetaPropertyBuilder addProperty(const QMetaProperty& prototype); |
| 94 | |
| 95 | QMetaEnumBuilder addEnumerator(const QByteArray& name); |
| 96 | QMetaEnumBuilder addEnumerator(const QMetaEnum& prototype); |
| 97 | |
| 98 | int addClassInfo(const QByteArray& name, const QByteArray& value); |
| 99 | |
| 100 | int addRelatedMetaObject(const QMetaObject *meta); |
| 101 | |
| 102 | void addMetaObject(const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members = AllMembers); |
| 103 | |
| 104 | QMetaMethodBuilder method(int index) const; |
| 105 | QMetaMethodBuilder constructor(int index) const; |
| 106 | QMetaPropertyBuilder property(int index) const; |
| 107 | QMetaEnumBuilder enumerator(int index) const; |
| 108 | const QMetaObject *relatedMetaObject(int index) const; |
| 109 | |
| 110 | QByteArray classInfoName(int index) const; |
| 111 | QByteArray classInfoValue(int index) const; |
| 112 | |
| 113 | void removeMethod(int index); |
| 114 | void removeConstructor(int index); |
| 115 | void removeProperty(int index); |
| 116 | void removeEnumerator(int index); |
| 117 | void removeClassInfo(int index); |
| 118 | void removeRelatedMetaObject(int index); |
| 119 | |
| 120 | int indexOfMethod(const QByteArray& signature); |
| 121 | int indexOfSignal(const QByteArray& signature); |
| 122 | int indexOfSlot(const QByteArray& signature); |
| 123 | int indexOfConstructor(const QByteArray& signature); |
| 124 | int indexOfProperty(const QByteArray& name); |
| 125 | int indexOfEnumerator(const QByteArray& name); |
| 126 | int indexOfClassInfo(const QByteArray& name); |
| 127 | |
| 128 | typedef void (*StaticMetacallFunction)(QObject *, QMetaObject::Call, int, void **); |
| 129 | |
| 130 | QMetaObjectBuilder::StaticMetacallFunction staticMetacallFunction() const; |
| 131 | void setStaticMetacallFunction(QMetaObjectBuilder::StaticMetacallFunction value); |
| 132 | |
| 133 | QMetaObject *toMetaObject() const; |
| 134 | |
| 135 | private: |
| 136 | Q_DISABLE_COPY_MOVE(QMetaObjectBuilder) |
| 137 | |
| 138 | QMetaObjectBuilderPrivate *d; |
| 139 | |
| 140 | friend class QMetaMethodBuilder; |
| 141 | friend class QMetaPropertyBuilder; |
| 142 | friend class QMetaEnumBuilder; |
| 143 | }; |
| 144 | |
| 145 | class Q_CORE_EXPORT QMetaMethodBuilder |
| 146 | { |
| 147 | public: |
| 148 | QMetaMethodBuilder() : _mobj(nullptr), _index(0) {} |
| 149 | |
| 150 | int index() const; |
| 151 | |
| 152 | QMetaMethod::MethodType methodType() const; |
| 153 | QByteArray signature() const; |
| 154 | |
| 155 | QByteArray returnType() const; |
| 156 | void setReturnType(const QByteArray& value); |
| 157 | |
| 158 | QList<QByteArray> parameterTypes() const; |
| 159 | QList<QByteArray> parameterNames() const; |
| 160 | void setParameterNames(const QList<QByteArray>& value); |
| 161 | |
| 162 | QByteArray tag() const; |
| 163 | void setTag(const QByteArray& value); |
| 164 | |
| 165 | QMetaMethod::Access access() const; |
| 166 | void setAccess(QMetaMethod::Access value); |
| 167 | |
| 168 | int attributes() const; |
| 169 | void setAttributes(int value); |
| 170 | |
| 171 | int isConst() const; |
| 172 | void setConst(bool methodIsConst=true); |
| 173 | |
| 174 | int revision() const; |
| 175 | void setRevision(int revision); |
| 176 | |
| 177 | private: |
| 178 | const QMetaObjectBuilder *_mobj; |
| 179 | int _index; |
| 180 | |
| 181 | friend class QMetaObjectBuilder; |
| 182 | friend class QMetaPropertyBuilder; |
| 183 | |
| 184 | QMetaMethodBuilder(const QMetaObjectBuilder *mobj, int index) |
| 185 | : _mobj(mobj), _index(index) {} |
| 186 | |
| 187 | QMetaMethodBuilderPrivate *d_func() const; |
| 188 | }; |
| 189 | |
| 190 | class Q_CORE_EXPORT QMetaPropertyBuilder |
| 191 | { |
| 192 | public: |
| 193 | QMetaPropertyBuilder() : _mobj(nullptr), _index(0) {} |
| 194 | |
| 195 | int index() const { return _index; } |
| 196 | |
| 197 | QByteArray name() const; |
| 198 | QByteArray type() const; |
| 199 | |
| 200 | bool hasNotifySignal() const; |
| 201 | QMetaMethodBuilder notifySignal() const; |
| 202 | void setNotifySignal(const QMetaMethodBuilder& value); |
| 203 | void removeNotifySignal(); |
| 204 | |
| 205 | bool isReadable() const; |
| 206 | bool isWritable() const; |
| 207 | bool isResettable() const; |
| 208 | bool isDesignable() const; |
| 209 | bool isScriptable() const; |
| 210 | bool isStored() const; |
| 211 | bool isEditable() const; |
| 212 | bool isUser() const; |
| 213 | bool hasStdCppSet() const; |
| 214 | bool isEnumOrFlag() const; |
| 215 | bool isConstant() const; |
| 216 | bool isFinal() const; |
| 217 | bool isAlias() const; |
| 218 | bool isBindable() const; |
| 219 | |
| 220 | void setReadable(bool value); |
| 221 | void setWritable(bool value); |
| 222 | void setResettable(bool value); |
| 223 | void setDesignable(bool value); |
| 224 | void setScriptable(bool value); |
| 225 | void setStored(bool value); |
| 226 | void setUser(bool value); |
| 227 | void setStdCppSet(bool value); |
| 228 | void setEnumOrFlag(bool value); |
| 229 | void setConstant(bool value); |
| 230 | void setFinal(bool value); |
| 231 | void setAlias(bool value); |
| 232 | void setBindable(bool value); |
| 233 | |
| 234 | int revision() const; |
| 235 | void setRevision(int revision); |
| 236 | |
| 237 | private: |
| 238 | const QMetaObjectBuilder *_mobj; |
| 239 | int _index; |
| 240 | |
| 241 | friend class QMetaObjectBuilder; |
| 242 | |
| 243 | QMetaPropertyBuilder(const QMetaObjectBuilder *mobj, int index) |
| 244 | : _mobj(mobj), _index(index) {} |
| 245 | |
| 246 | QMetaPropertyBuilderPrivate *d_func() const; |
| 247 | }; |
| 248 | |
| 249 | class Q_CORE_EXPORT QMetaEnumBuilder |
| 250 | { |
| 251 | public: |
| 252 | QMetaEnumBuilder() : _mobj(nullptr), _index(0) {} |
| 253 | |
| 254 | int index() const { return _index; } |
| 255 | |
| 256 | QByteArray name() const; |
| 257 | |
| 258 | QByteArray enumName() const; |
| 259 | void setEnumName(const QByteArray &alias); |
| 260 | |
| 261 | QMetaType metaType() const; |
| 262 | void setMetaType(QMetaType metaType); |
| 263 | |
| 264 | bool isFlag() const; |
| 265 | void setIsFlag(bool value); |
| 266 | |
| 267 | bool isScoped() const; |
| 268 | void setIsScoped(bool value); |
| 269 | |
| 270 | int keyCount() const; |
| 271 | QByteArray key(int index) const; |
| 272 | int value(int index) const; |
| 273 | |
| 274 | int addKey(const QByteArray& name, int value); |
| 275 | void removeKey(int index); |
| 276 | |
| 277 | private: |
| 278 | const QMetaObjectBuilder *_mobj; |
| 279 | int _index; |
| 280 | |
| 281 | friend class QMetaObjectBuilder; |
| 282 | |
| 283 | QMetaEnumBuilder(const QMetaObjectBuilder *mobj, int index) |
| 284 | : _mobj(mobj), _index(index) {} |
| 285 | |
| 286 | QMetaEnumBuilderPrivate *d_func() const; |
| 287 | }; |
| 288 | |
| 289 | class Q_CORE_EXPORT QMetaStringTable |
| 290 | { |
| 291 | Q_DISABLE_COPY_MOVE(QMetaStringTable) |
| 292 | public: |
| 293 | explicit QMetaStringTable(const QByteArray &className); |
| 294 | |
| 295 | int enter(const QByteArray &value); |
| 296 | |
| 297 | static int preferredAlignment(); |
| 298 | int blobSize() const; |
| 299 | void writeBlob(char *out) const; |
| 300 | |
| 301 | private: |
| 302 | typedef QHash<QByteArray, int> Entries; // string --> index mapping |
| 303 | Entries m_entries; |
| 304 | int m_index; |
| 305 | QByteArray m_className; |
| 306 | }; |
| 307 | |
| 308 | Q_DECLARE_OPERATORS_FOR_FLAGS(QMetaObjectBuilder::AddMembers) |
| 309 | |
| 310 | QT_END_NAMESPACE |
| 311 | |
| 312 | #endif |
| 313 | |