TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
ttksuperenum.h
Go to the documentation of this file.
1 #ifndef TTKSUPERENUM_H
2 #define TTKSUPERENUM_H
3 
4 /***************************************************************************
5  * This file is part of the TTK Library Module project
6  * Copyright (C) 2015 - 2024 Greedysky Studio
7 
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Lesser General Public License for more details.
17 
18  * You should have received a copy of the GNU Lesser General Public License along
19  * with this program; If not, see <http://www.gnu.org/licenses/>.
20  ***************************************************************************/
21 
22 #include <unordered_map>
23 #include "ttkmoduleexport.h"
24 
29 {
30 public:
31  static constexpr int Null = -1;
32 
33 public:
37  TTKSuperEnum(const QString &value);
38 
42  QString keyToString(int value) const;
46  int stringToKey(const QString &name) const;
47 
48 private:
49  std::unordered_map<int, QString> m_enumValue;
50 
51 };
52 
53 #define TTK_SUPER_ENUM(Type, ...) \
54  static const TTKSuperEnum Type ## EnumObject(#__VA_ARGS__); \
55  class TTK_MODULE_EXPORT Type { \
56  public: \
57  enum { kNull = TTKSuperEnum::Null, __VA_ARGS__ }; \
58  public: \
59  Type() : m_data(Type::kNull) {} \
60  Type(const Type &v) : m_data(v.m_data) {} \
61  Type(int v) : m_data(v) {} \
62  Type(const QString &v) : m_data(Type ## EnumObject.stringToKey(v)) {} \
63  QString toString() const { return Type ## EnumObject.keyToString(m_data); } \
64  int toInt() const { return m_data; } \
65  operator int () const { return m_data; } \
66  operator QString () const { return toString(); } \
67  Type& operator =(int v) { m_data = v; return *this; } \
68  Type& operator =(const Type &v) { data_ = v.data_; return *this; } \
69  Type& operator =(const QString &v) { m_data = Type ## EnumObject.stringToKey(v); return *this; } \
70  private: \
71  int m_data; \
72  }
73 
74 #define TTK_ENUM_TYPE(Enum) std::underlying_type<Enum>::type
75 #define TTK_DECLARE_OPERATORS_FOR_ENUM(Enum) \
76 inline constexpr Enum operator~(const Enum lhs) { return TTKStaticCast(Enum, ~TTKStaticCast(TTK_ENUM_TYPE(Enum), lhs)); } \
77 inline constexpr Enum operator!(const Enum lhs) { return TTKStaticCast(Enum, !TTKStaticCast(TTK_ENUM_TYPE(Enum), lhs)); } \
78 inline constexpr bool operator>(const Enum lhs, const Enum rhs) { return TTKStaticCast(TTK_ENUM_TYPE(Enum), lhs) > TTKStaticCast(TTK_ENUM_TYPE(Enum), rhs); } \
79 inline constexpr bool operator<(const Enum lhs, const Enum rhs) { return TTKStaticCast(TTK_ENUM_TYPE(Enum), lhs) < TTKStaticCast(TTK_ENUM_TYPE(Enum), rhs); } \
80 inline constexpr bool operator>=(const Enum lhs, const Enum rhs) { return TTKStaticCast(TTK_ENUM_TYPE(Enum), lhs) >= TTKStaticCast(TTK_ENUM_TYPE(Enum), rhs); } \
81 inline constexpr bool operator<=(const Enum lhs, const Enum rhs) { return TTKStaticCast(TTK_ENUM_TYPE(Enum), lhs) <= TTKStaticCast(TTK_ENUM_TYPE(Enum), rhs); } \
82 inline constexpr bool operator==(const Enum lhs, const Enum rhs) { return TTKStaticCast(TTK_ENUM_TYPE(Enum), lhs) == TTKStaticCast(TTK_ENUM_TYPE(Enum), rhs); } \
83 inline constexpr bool operator!=(const Enum lhs, const Enum rhs) { return TTKStaticCast(TTK_ENUM_TYPE(Enum), lhs) != TTKStaticCast(TTK_ENUM_TYPE(Enum), rhs); } \
84 inline constexpr Enum operator&(const Enum lhs, const Enum rhs) { return TTKStaticCast(Enum, TTKStaticCast(TTK_ENUM_TYPE(Enum), lhs) & TTKStaticCast(TTK_ENUM_TYPE(Enum), rhs)); } \
85 inline constexpr Enum operator|(const Enum lhs, const Enum rhs) { return TTKStaticCast(Enum, TTKStaticCast(TTK_ENUM_TYPE(Enum), lhs) | TTKStaticCast(TTK_ENUM_TYPE(Enum), rhs)); } \
86 inline constexpr Enum operator^(const Enum lhs, const Enum rhs) { return TTKStaticCast(Enum, TTKStaticCast(TTK_ENUM_TYPE(Enum), lhs) ^ TTKStaticCast(TTK_ENUM_TYPE(Enum), rhs)); } \
87 inline constexpr bool operator||(const Enum lhs, const Enum rhs) { return TTKStaticCast(TTK_ENUM_TYPE(Enum), lhs) || TTKStaticCast(TTK_ENUM_TYPE(Enum), rhs); } \
88 inline constexpr bool operator&&(const Enum lhs, const Enum rhs) { return TTKStaticCast(TTK_ENUM_TYPE(Enum), lhs) && TTKStaticCast(TTK_ENUM_TYPE(Enum), rhs); } \
89 inline const Enum& operator|=(Enum& lhs, const Enum rhs) { return lhs = (lhs | rhs); } \
90 inline const Enum& operator&=(Enum& lhs, const Enum rhs) { return lhs = (lhs & rhs); } \
91 inline const Enum& operator^=(Enum& lhs, const Enum rhs) { return lhs = (lhs ^ rhs); }
92 
93 #endif // TTKSUPERENUM_H
#define TTK_MODULE_EXPORT
The class of the super enum.
Definition: ttksuperenum.h:28
const char * name
Definition: http_parser.c:458
std::unordered_map< int, QString > m_enumValue
Definition: ttksuperenum.h:49