27 lines
791 B
C++
27 lines
791 B
C++
#pragma once
|
|
#include "adminive/adapter.hpp"
|
|
#include "magic_enum/magic_enum.hpp"
|
|
#include <optional>
|
|
#include <string_view>
|
|
#include <type_traits>
|
|
#include <vector>
|
|
namespace adminive {
|
|
template <class Enum>
|
|
requires std::is_enum_v<Enum>
|
|
struct Enum_Adapter<Enum> {
|
|
static std::vector<Enum> values() {
|
|
const auto source = magic_enum::enum_values<Enum>();
|
|
return std::vector<Enum>(source.begin(), source.end());
|
|
}
|
|
static std::string_view name(Enum value) {
|
|
return magic_enum::enum_name(value);
|
|
}
|
|
static std::optional<Enum> cast(std::string_view value) {
|
|
return magic_enum::enum_cast<Enum>(value);
|
|
}
|
|
static std::optional<Enum> cast(std::underlying_type_t<Enum> value) {
|
|
return magic_enum::enum_cast<Enum>(value);
|
|
}
|
|
};
|
|
}
|