1// Copyright (C) 2022 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 Q_PROTOBUF_MESSAGE_H
5#define Q_PROTOBUF_MESSAGE_H
6
7#include <QtProtobuf/qtprotobufglobal.h>
8#include <QtCore/qtconfigmacros.h>
9#include <QtCore/qtmetamacros.h>
10#include <QtCore/qmetatype.h>
11
12QT_BEGIN_NAMESPACE
13
14class QProtobufMessage;
15struct QProtobufMessageDeleter {
16 Q_PROTOBUF_EXPORT void operator()(QProtobufMessage *ptr) noexcept;
17};
18using QProtobufMessagePointer = std::unique_ptr<QProtobufMessage, QProtobufMessageDeleter>;
19
20namespace QtProtobufPrivate {
21struct QProtobufPropertyOrderingInfo;
22}
23
24class QProtobufMessagePrivate;
25class QProtobufMessage
26{
27 Q_GADGET_EXPORT(Q_PROTOBUF_EXPORT)
28public:
29 Q_PROTOBUF_EXPORT QVariant property(QAnyStringView propertyName) const;
30 Q_PROTOBUF_EXPORT bool setProperty(QAnyStringView propertyName, const QVariant &value);
31 Q_PROTOBUF_EXPORT bool setProperty(QAnyStringView propertyName, QVariant &&value);
32
33 Q_REQUIRED_RESULT
34 Q_PROTOBUF_EXPORT static QProtobufMessagePointer constructByName(const QString &messageType);
35
36protected:
37 Q_PROTOBUF_EXPORT explicit QProtobufMessage(const QMetaObject *metaObject);
38 Q_PROTOBUF_EXPORT ~QProtobufMessage();
39 Q_PROTOBUF_EXPORT QProtobufMessage(const QProtobufMessage &other);
40 Q_PROTOBUF_EXPORT QProtobufMessage &operator=(const QProtobufMessage &other);
41 QProtobufMessage(QProtobufMessage &&other) noexcept : d_ptr(std::exchange(obj&: other.d_ptr, new_val: {})) { }
42 QProtobufMessage &operator=(QProtobufMessage &&other) noexcept
43 {
44 qt_ptr_swap(lhs&: d_ptr, rhs&: other.d_ptr);
45 return *this;
46 }
47
48 Q_PROTOBUF_EXPORT
49 static bool isEqual(const QProtobufMessage &lhs, const QProtobufMessage &rhs) noexcept;
50
51 QVariant property(const QtProtobufPrivate::QProtobufPropertyOrderingInfo &fieldInfo) const;
52 bool setProperty(const QtProtobufPrivate::QProtobufPropertyOrderingInfo &fieldInfo,
53 const QVariant &value);
54 bool setProperty(const QtProtobufPrivate::QProtobufPropertyOrderingInfo &fieldInfo,
55 QVariant &&value);
56
57private:
58 const QMetaObject *metaObject() const;
59
60 friend class QProtobufSerializer;
61 friend class QAbstractProtobufSerializer;
62 friend class QProtobufSerializerPrivate;
63 friend class QAbstractProtobufSerializer;
64 friend struct QProtobufMessageDeleter;
65
66 QProtobufMessagePrivate *d_ptr;
67 Q_DECLARE_PRIVATE(QProtobufMessage)
68};
69
70QT_END_NAMESPACE
71
72#endif // Q_PROTOBUF_MESSAGE_H
73

source code of qtgrpc/src/protobuf/qprotobufmessage.h