Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qmultimedia_enum_to_string_converter_p.h
Go to the documentation of this file.
1// Copyright (C) 2025 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 QMULTIMEDIA_ENUM_TO_STRING_CONVERTER_P_H
5#define QMULTIMEDIA_ENUM_TO_STRING_CONVERTER_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qdebug.h>
19#include <QtCore/qstring.h>
20#include <QtCore/private/qglobal_p.h>
21
22#include <optional>
23
24QT_BEGIN_NAMESPACE
25
26#define QT_MM_CAT(x, y) QT_MM_IMPL_CAT(x, y)
27#define QT_MM_IMPL_CAT(x, y) x##y
28
29// clang-format off
30
31#define QT_MM_IMPL_GEN_CASE_MAP_ENUM_TO_STRING(SYMBOL, STRING)
32 case SYMBOL:
33 return QStringLiteral(STRING);
34
35// clang-format on
36
37#define QT_MM_IMPL_GEN_CASES_ENUM_TO_STRING(seq)
39 static_assert(true, "force semicolon")
40#define QT_MM_IMPL_GEN_CASES_ENUM_TO_STRING_1(x, y)
42#define QT_MM_IMPL_GEN_CASES_ENUM_TO_STRING_2(x, y)
44#define QT_MM_IMPL_GEN_CASES_ENUM_TO_STRING_1_END
45#define QT_MM_IMPL_GEN_CASES_ENUM_TO_STRING_2_END
46
47namespace QtMultimediaPrivate {
48
50{
51};
52
53template <typename Enum, typename Role = EnumName>
55{
56 static std::optional<QString> toQString(Enum);
57};
58
59} // namespace QtMultimediaPrivate
60
61// clang-format off
62
63#define QT_MM_MAKE_STRING_RESOLVER(Enum, EnumName, ...)
64 template <>
65 struct QtMultimediaPrivate::StringResolver<Enum, EnumName>
66 {
67 static std::optional<QString> toQString(Enum arg)
68 {
69 switch (arg) {
71 default:
72 return std::nullopt;
73 }
74 }
75 };
76 static_assert(true, "force semicolon")
77
78// clang-format on
79
80#define QT_MM_DEFINE_QDEBUG_ENUM(EnumType)
81 QDebug operator<<(QDebug dbg, EnumType arg)
82 {
83 QDebugStateSaver saver(dbg);
84 dbg.noquote();
85 std::optional<QString> resolved =
86 QtMultimediaPrivate::StringResolver<EnumType>::toQString(arg);
87 if (resolved)
88 dbg << *resolved;
89 else
90 dbg << "Unknown Enum value";
91 return dbg;
92 }
93 static_assert(true, "force semicolon")
94
95QT_END_NAMESPACE
96
97#endif // QMULTIMEDIA_ENUM_TO_STRING_CONVERTER_P_H
#define QT_MM_IMPL_GEN_CASES_ENUM_TO_STRING_1(x, y)
#define QT_MM_IMPL_GEN_CASES_ENUM_TO_STRING_2(x, y)
#define QT_MM_IMPL_CAT(x, y)
#define QT_MM_IMPL_GEN_CASE_MAP_ENUM_TO_STRING(SYMBOL, STRING)
#define QT_MM_IMPL_GEN_CASES_ENUM_TO_STRING(seq)
static std::optional< QString > toQString(Enum)