add new thirdparty library, magic_enum
this is awesome X)
This commit is contained in:
parent
dcbd3594cf
commit
6e820daef8
@ -155,6 +155,7 @@ target_link_libraries(nf7
|
||||
implot
|
||||
linalg.h
|
||||
luajit
|
||||
magic_enum
|
||||
miniaudio
|
||||
source_location
|
||||
yas
|
||||
|
@ -2,26 +2,31 @@
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include <magic_enum.hpp>
|
||||
|
||||
#include <yas/serialize.hpp>
|
||||
#include <yas/types/std/string.hpp>
|
||||
|
||||
#include "nf7.hh"
|
||||
|
||||
|
||||
namespace nf7 {
|
||||
|
||||
template <
|
||||
typename T,
|
||||
const char* (*Stringify)(T),
|
||||
T (*Parse)(std::string_view)>
|
||||
template <typename T>
|
||||
struct EnumSerializer {
|
||||
public:
|
||||
static auto& save(auto& ar, auto t) {
|
||||
const std::string v = Stringify(t);
|
||||
ar(v);
|
||||
ar(magic_enum::enum_name(t));
|
||||
return ar;
|
||||
}
|
||||
static auto& load(auto& ar, auto& t) {
|
||||
std::string v;
|
||||
ar(v);
|
||||
t = Parse(v);
|
||||
if (auto ot = magic_enum::enum_cast<T>(v)) {
|
||||
t = *ot;
|
||||
} else {
|
||||
throw nf7::DeserializeException {"unknown enum: "+v};
|
||||
}
|
||||
return ar;
|
||||
}
|
||||
};
|
||||
|
8
thirdparty/CMakeLists.txt
vendored
8
thirdparty/CMakeLists.txt
vendored
@ -177,6 +177,14 @@ endfunction()
|
||||
include_luajit()
|
||||
|
||||
|
||||
# ---- magic_enum ----
|
||||
FetchContent_Declare(
|
||||
magic_enum
|
||||
URL "https://github.com/Neargye/magic_enum/archive/refs/tags/v0.8.1.zip"
|
||||
)
|
||||
FetchContent_MakeAvailable(magic_enum)
|
||||
|
||||
|
||||
# ---- miniaudio ----
|
||||
# repository: https://github.com/mackron/miniaudio
|
||||
# license : Unlicense
|
||||
|
Loading…
x
Reference in New Issue
Block a user