summaryrefslogtreecommitdiffstats
path: root/src/multimedia/qerrorinfo_p.h
blob: 6428cb00fd160b7ff066e0a566d694654065e4e4 (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
// Copyright (C) 2023 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 QERRORINFO_P_H
#define QERRORINFO_P_H

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//

#include <QtMultimedia/qtmultimediaglobal.h>
#include <QString>

QT_BEGIN_NAMESPACE

template <typename ErrorCode, ErrorCode NoError = ErrorCode::NoError>
class QErrorInfo
{
public:
    QErrorInfo(ErrorCode error = NoError, QString description = {})
        : m_code(error), m_description(std::move(description))
    {
    }

    template <typename Notifier>
    void setAndNotify(ErrorCode code, QString description, Notifier &notifier)
    {
        const bool changed = code != m_code || description != m_description;

        m_code = code;
        m_description = std::move(description);

        if (code != NoError)
            emit notifier.errorOccurred(m_code, m_description);

        if (changed)
            emit notifier.errorChanged();
    }

    ErrorCode code() const { return m_code; }
    QString description() const { return m_description; };

private:
    ErrorCode m_code;
    QString m_description;
};

QT_END_NAMESPACE

#endif // QERRORINFO_P_H