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 <string> 11 #include <fcitx-utils/color.h> 12 #include <fcitx-utils/i18nstring.h> 13 #include <fcitx-utils/key.h> 14 #include <fcitx-utils/semver.h> 15 16 namespace fcitx { 17 18 #define FCITX_SPECIALIZE_TYPENAME(TYPE, NAME) \ 19 static inline std::string _FCITX_UNUSED_ configTypeNameHelper(TYPE *) { \ 20 return NAME; \ 21 } 22 23 FCITX_SPECIALIZE_TYPENAME(bool, "Boolean"); 24 FCITX_SPECIALIZE_TYPENAME(int, "Integer"); 25 FCITX_SPECIALIZE_TYPENAME(std::string, "String"); 26 FCITX_SPECIALIZE_TYPENAME(SemanticVersion, "Version"); 27 FCITX_SPECIALIZE_TYPENAME(fcitx::Key, "Key"); 28 FCITX_SPECIALIZE_TYPENAME(fcitx::Color, "Color"); 29 FCITX_SPECIALIZE_TYPENAME(fcitx::I18NString, "I18NString"); 30 31 template <typename T, typename = void> 32 struct OptionTypeName { getOptionTypeName33 static std::string get() { 34 using ::fcitx::configTypeNameHelper; 35 return configTypeNameHelper(static_cast<T *>(nullptr)); 36 } 37 }; 38 39 template <typename T> 40 struct OptionTypeName<std::vector<T>> { 41 static std::string get() { return "List|" + OptionTypeName<T>::get(); } 42 }; 43 44 template <typename T> 45 struct OptionTypeName<T, 46 typename std::enable_if<std::is_enum<T>::value>::type> { 47 static std::string get() { return "Enum"; } 48 }; 49 } // namespace fcitx 50 51 #endif // _FCITX_CONFIG_TYPENAME_H_ 52