add EnumSerializer
This commit is contained in:
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
|
Reference in New Issue
Block a user