Go to the documentation of this file. 8 #ifndef XGBOOST_COMMON_ENUM_CLASS_PARAM_H_ 9 #define XGBOOST_COMMON_ENUM_CLASS_PARAM_H_ 11 #include <dmlc/parameter.h> 13 #include <type_traits> 49 #define DECLARE_FIELD_ENUM_CLASS(EnumClass) \ 51 namespace parameter { \ 53 class FieldEntry<EnumClass> : public FieldEntry<int> { \ 55 FieldEntry<EnumClass>() { \ 57 std::is_same<int, typename std::underlying_type<EnumClass>::type>::value, \ 58 "enum class must be backed by int"); \ 61 using Super = FieldEntry<int>; \ 62 void Set(void *head, const std::string &value) const override { \ 63 Super::Set(head, value); \ 65 inline FieldEntry<EnumClass>& add_enum(const std::string &key, EnumClass value) { \ 66 Super::add_enum(key, static_cast<int>(value)); \ 69 inline FieldEntry<EnumClass>& set_default(const EnumClass& default_value) { \ 70 default_value_ = static_cast<int>(default_value); \ 71 has_default_ = true; \ 74 inline void Init(const std::string &key, void *head, EnumClass& ref) { \ 75 Super::Init(key, head, *reinterpret_cast<int*>(&ref)); \ 81 #endif // XGBOOST_COMMON_ENUM_CLASS_PARAM_H_