add EnumSerializer
This commit is contained in:
parent
c5590092fa
commit
dcbd3594cf
@ -116,6 +116,7 @@ target_sources(nf7
|
|||||||
common/util_string.hh
|
common/util_string.hh
|
||||||
common/value.hh
|
common/value.hh
|
||||||
common/yas_audio.hh
|
common/yas_audio.hh
|
||||||
|
common/yas_enum.hh
|
||||||
common/yas_imgui.hh
|
common/yas_imgui.hh
|
||||||
common/yas_imnodes.hh
|
common/yas_imnodes.hh
|
||||||
common/yas_nf7.hh
|
common/yas_nf7.hh
|
||||||
|
29
common/yas_enum.hh
Normal file
29
common/yas_enum.hh
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
#include <yas/serialize.hpp>
|
||||||
|
#include <yas/types/std/string.hpp>
|
||||||
|
|
||||||
|
namespace nf7 {
|
||||||
|
|
||||||
|
template <
|
||||||
|
typename T,
|
||||||
|
const char* (*Stringify)(T),
|
||||||
|
T (*Parse)(std::string_view)>
|
||||||
|
struct EnumSerializer {
|
||||||
|
public:
|
||||||
|
static auto& save(auto& ar, auto t) {
|
||||||
|
const std::string v = Stringify(t);
|
||||||
|
ar(v);
|
||||||
|
return ar;
|
||||||
|
}
|
||||||
|
static auto& load(auto& ar, auto& t) {
|
||||||
|
std::string v;
|
||||||
|
ar(v);
|
||||||
|
t = Parse(v);
|
||||||
|
return ar;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace nf7
|
Loading…
x
Reference in New Issue
Block a user