summaryrefslogtreecommitdiffstats
path: root/src/network/access/qhttp1configuration.h
blob: 128b8aa5aac5377cdc7c733b58117f56f1e8d480 (plain)
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
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef QHTTP1CONFIGURATION_H
#define QHTTP1CONFIGURATION_H

#include <QtNetwork/qtnetworkglobal.h>

#include <utility>
#include <cstdint>

QT_REQUIRE_CONFIG(http);

QT_BEGIN_NAMESPACE

class QHttp1ConfigurationPrivate;
class QHttp1Configuration
{
public:
    Q_NETWORK_EXPORT QHttp1Configuration();
    Q_NETWORK_EXPORT QHttp1Configuration(const QHttp1Configuration &other);
    QHttp1Configuration(QHttp1Configuration &&other) noexcept
        : u{other.u} { other.u.d = nullptr; }

    Q_NETWORK_EXPORT QHttp1Configuration &operator=(const QHttp1Configuration &other);
    QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QHttp1Configuration)

    Q_NETWORK_EXPORT ~QHttp1Configuration();

    Q_NETWORK_EXPORT void setNumberOfConnectionsPerHost(qsizetype amount);
    Q_NETWORK_EXPORT qsizetype numberOfConnectionsPerHost() const;

    void swap(QHttp1Configuration &other) noexcept
    { std::swap(u, other.u); }

private:
    struct ShortData {
        std::uint8_t numConnectionsPerHost;
        char reserved[sizeof(void*) - sizeof(numConnectionsPerHost)];
    };
    union U {
        U(ShortData _data) : data(_data) {}
        QHttp1ConfigurationPrivate *d;
        ShortData data;
    } u;

    Q_NETWORK_EXPORT bool equals(const QHttp1Configuration &other) const noexcept;
    Q_NETWORK_EXPORT size_t hash(size_t seed) const noexcept;

    friend bool operator==(const QHttp1Configuration &lhs, const QHttp1Configuration &rhs) noexcept
    { return lhs.equals(rhs); }
    friend bool operator!=(const QHttp1Configuration &lhs, const QHttp1Configuration &rhs) noexcept
    { return !lhs.equals(rhs); }

    friend size_t qHash(const QHttp1Configuration &key, size_t seed = 0) noexcept { return key.hash(seed); }
};

Q_DECLARE_SHARED(QHttp1Configuration)

QT_END_NAMESPACE

#endif // QHTTP1CONFIGURATION_H