Fcitx
optiontypename.h
1 /*
2  * SPDX-FileCopyrightText: 2015-2015 CSSlayer <wengxt@gmail.com>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  *
6  */
7 #ifndef _FCITX_CONFIG_TYPENAME_H_
8 #define _FCITX_CONFIG_TYPENAME_H_
9 
10 #include <optional>
11 #include <string>
12 #include <type_traits>
13 #include <vector>
14 #include <fcitx-utils/color.h>
15 #include <fcitx-utils/i18nstring.h>
16 #include <fcitx-utils/key.h>
17 #include <fcitx-utils/macros.h>
18 #include <fcitx-utils/semver.h>
19 
20 namespace fcitx {
21 
22 #define FCITX_SPECIALIZE_TYPENAME(TYPE, NAME) \
23  static inline std::string _FCITX_UNUSED_ configTypeNameHelper(TYPE *) { \
24  return NAME; \
25  }
26 
27 FCITX_SPECIALIZE_TYPENAME(bool, "Boolean");
28 FCITX_SPECIALIZE_TYPENAME(int, "Integer");
29 FCITX_SPECIALIZE_TYPENAME(std::string, "String");
30 FCITX_SPECIALIZE_TYPENAME(SemanticVersion, "Version");
31 FCITX_SPECIALIZE_TYPENAME(fcitx::Key, "Key");
32 FCITX_SPECIALIZE_TYPENAME(fcitx::Color, "Color");
33 FCITX_SPECIALIZE_TYPENAME(fcitx::I18NString, "I18NString");
34 
35 template <typename T, typename = void>
37  static std::string get() {
38  using ::fcitx::configTypeNameHelper;
39  return configTypeNameHelper(static_cast<T *>(nullptr));
40  }
41 };
42 
43 template <typename T>
44 struct OptionTypeName<std::vector<T>> {
45  static std::string get() { return "List|" + OptionTypeName<T>::get(); }
46 };
47 
48 template <typename T>
49 struct OptionTypeName<T, std::enable_if_t<std::is_enum_v<T>>> {
50  static std::string get() { return "Enum"; }
51 };
52 
53 template <typename T>
54 struct OptionTypeName<std::optional<T>> {
55  static std::string get() { return "Optional|" + OptionTypeName<T>::get(); }
56 };
57 
58 } // namespace fcitx
59 
60 #endif // _FCITX_CONFIG_TYPENAME_H_
Describe a Key in fcitx.
Definition: key.h:41
Definition: action.cpp:17
Definition: matchrule.h:78
Color class for handling color.
Definition: color.h:28
Simple color class that represent a 64bit color.
Class to represent a key.