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 QNDEFRECORD_H
5#define QNDEFRECORD_H
6
7#include <QtCore/QSharedDataPointer>
8#include <QtCore/QByteArray>
9#include <QtNfc/qtnfcglobal.h>
10
11QT_BEGIN_NAMESPACE
12
13class QNdefRecordPrivate;
14
15class Q_NFC_EXPORT QNdefRecord
16{
17public:
18 enum TypeNameFormat {
19 Empty = 0x00,
20 NfcRtd = 0x01,
21 Mime = 0x02,
22 Uri = 0x03,
23 ExternalRtd = 0x04,
24 Unknown = 0x05
25 };
26
27 QNdefRecord();
28 ~QNdefRecord();
29
30 QNdefRecord(const QNdefRecord &other);
31 QNdefRecord &operator=(const QNdefRecord &other);
32
33 void setTypeNameFormat(TypeNameFormat typeNameFormat);
34 TypeNameFormat typeNameFormat() const;
35
36 void setType(const QByteArray &type);
37 QByteArray type() const;
38
39 void setId(const QByteArray &id);
40 QByteArray id() const;
41
42 void setPayload(const QByteArray &payload);
43 QByteArray payload() const;
44
45 bool isEmpty() const;
46
47 template <typename T>
48 inline bool isRecordType() const
49 {
50 T dummy;
51 return (typeNameFormat() == dummy.typeNameFormat() && type() == dummy.type());
52 }
53
54 bool operator==(const QNdefRecord &other) const;
55 inline bool operator!=(const QNdefRecord &other) const { return !operator==(other); }
56
57 void clear();
58
59protected:
60 QNdefRecord(const QNdefRecord &other, TypeNameFormat typeNameFormat, const QByteArray &type);
61 QNdefRecord(const QNdefRecord &other, TypeNameFormat typeNameFormat);
62 QNdefRecord(TypeNameFormat typeNameFormat, const QByteArray &type);
63
64private:
65 QSharedDataPointer<QNdefRecordPrivate> d;
66};
67
68#define Q_DECLARE_NDEF_RECORD(className, typeNameFormat, type, initialPayload) \
69 className() : QNdefRecord(typeNameFormat, type) { setPayload(initialPayload); } \
70 className(const QNdefRecord &other) : QNdefRecord(other, typeNameFormat, type) { }
71
72#define Q_DECLARE_ISRECORDTYPE_FOR_NDEF_RECORD(className, typeNameFormat_, type_) \
73 QT_BEGIN_NAMESPACE \
74 template<> inline bool QNdefRecord::isRecordType<className>() const\
75 { \
76 return (typeNameFormat() == typeNameFormat_ && type() == type_); \
77 } \
78 QT_END_NAMESPACE
79
80Q_NFC_EXPORT size_t qHash(const QNdefRecord &key);
81
82QT_END_NAMESPACE
83
84#endif // QNDEFRECORD_H
85

source code of qtconnectivity/src/nfc/qndefrecord.h