File: Message.h

package info (click to toggle)
js8call 2.5.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,720 kB
  • sloc: cpp: 562,655; sh: 898; python: 132; ansic: 102; makefile: 4
file content (71 lines) | stat: -rw-r--r-- 1,470 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef MESSAGE_HPP
#define MESSAGE_HPP

/**
 * (C) 2018 Jordan Sherer <kn4crd@gmail.com> - All Rights Reserved
 **/

#include <QByteArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QMap>
#include <QSharedDataPointer>
#include <QString>
#include <QVariant>

class Message final {
  public:
    // Constructors

    Message();
    Message(QString const &type, QString const &value = {});
    Message(QString const &type, QString const &value,
            QVariantMap const &params);

    // Copying and moving

    Message(Message const &);
    Message &operator=(Message const &);
    Message(Message &&) noexcept;
    Message &operator=(Message &&) noexcept;

    // Destructor

    ~Message();

    // Accessors

    qint64 id() const;
    QString type() const;
    QString value() const;
    QVariantMap params() const;

    // Manipulators

    qint64 ensureId();
    void setType(QString const &);
    void setValue(QString const &);

    // Conversions

    QByteArray toJson() const;
    QJsonDocument toJsonDocument() const;
    QJsonObject toJsonObject() const;
    QVariantMap toVariantMap() const;

    // Deserialization

    static Message fromJson(QByteArray const &);
    static Message fromJson(QJsonDocument const &);
    static Message fromJson(QJsonObject const &);

  private:
    // Shared data implementation

    struct Data;
    QSharedDataPointer<Data> d_;
};

Q_DECLARE_TYPEINFO(Message, Q_MOVABLE_TYPE);

#endif // MESSAGE_HPP