1#ifndef IMGUI_PARTINTERFACE_HH
2#define IMGUI_PARTINTERFACE_HH
10#include <initializer_list>
24 virtual void save(ImGuiTextBuffer& ) {}
37 :
name(name_),
p(p_) {}
42 T&
get(
C& c)
const {
return c.*
p; }
46template<
typename C,
typename T>
48template<
typename C,
typename T>
54 void save(ImGuiTextBuffer& buf,
C& c)
const {
55 buf.appendf(
"%s=%d\n", this->name.c_str(), this->get(c));
58 if (
auto r = StringOp::stringTo<int>(value)) {
70 void load(
C& c, std::string_view value)
const {
71 if (
auto r = StringOp::stringTo<int>(value)) {
72 if (0 <= *r && *r <
max) this->
get(c) = *r;
83 void load(
C& c, std::string_view value)
const {
84 if (
auto r = StringOp::stringTo<int>(value)) {
85 if (
min <= *r && *r <
max) this->
get(c) = *r;
92 std::initializer_list<int>
valid;
96 void load(
C& c, std::string_view value)
const {
97 if (
auto r = StringOp::stringTo<int>(value)) {
106 void save(ImGuiTextBuffer& buf,
C& c)
const {
107 buf.appendf(
"%s=%u\n", this->name.c_str(), this->get(c));
110 if (
auto r = StringOp::stringTo<unsigned>(value)) {
119 void save(ImGuiTextBuffer& buf,
C& c)
const {
120 buf.appendf(
"%s=%d\n", this->name.c_str(), this->get(c));
130 void save(ImGuiTextBuffer& buf,
C& c)
const {
131 buf.appendf(
"%s=%f\n", this->name.c_str(),
double(this->get(c)));
134 this->get(c) = strtof(value.
c_str(),
nullptr);
141 void save(ImGuiTextBuffer& buf,
C& c)
const {
142 buf.appendf(
"%s=%s\n", this->name.c_str(), this->get(c).c_str());
145 this->get(c) = std::string(value);
152 void save(ImGuiTextBuffer& buf,
C& c)
const {
153 const auto& v = this->get(c);
154 buf.appendf(
"%s=[ %d %d ]\n", this->name.c_str(), v.x, v.y);
158 if (sscanf(value.
c_str(),
"[ %d %d ]", &
t.x, &
t.y) == 2) {
167 void save(ImGuiTextBuffer& buf,
C& c)
const {
168 const auto& v = this->get(c);
169 buf.appendf(
"%s=[ %f %f %f %f ]\n", this->name.c_str(),
170 double(v.x),
double(v.y),
double(v.z),
double(v.w));
174 if (sscanf(value.
c_str(),
"[ %f %f %f %f ]", &
t.x, &
t.y, &
t.z, &
t.w) == 4) {
183 void save(ImGuiTextBuffer& buf,
C& c)
const {
184 buf.appendf(
"%s=%d\n", this->name.c_str(), this->get(c).open);
192template<
typename C,
typename... Elements>
195 std::apply([&](
auto& ...elem){(..., elem.save(buf, c));}, tup);
198template<
typename C,
typename Elem>
202 if (name != elem.name)
return false;
206template<
typename C,
typename... Elements>
208 C& c,
const std::tuple<Elements...>& tup)
210 return std::apply([&](
auto& ...elem){
return (... ||
checkLoad(name, value, c, elem));}, tup);
virtual zstring_view iniName() const
virtual void showMenu(MSXMotherBoard *)
virtual void loadLine(std::string_view, zstring_view)
virtual void paint(MSXMotherBoard *)
virtual void save(ImGuiTextBuffer &)
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
constexpr const char * c_str() const
bool stringToBool(string_view str)
This file implemented 3 utility functions:
bool loadOnePersistent(std::string_view name, zstring_view value, C &c, const std::tuple< Elements... > &tup)
void savePersistent(ImGuiTextBuffer &buf, C &c, const std::tuple< Elements... > &tup)
bool checkLoad(std::string_view name, zstring_view value, C &c, Elem &elem)
constexpr bool contains(ITER first, ITER last, const VAL &val)
Check if a range contains a given value, using linear search.
constexpr PersistentElementBase(zstring_view name_, T C::*p_)
void load(C &c, std::string_view value) const
constexpr PersistentElementEnum(zstring_view name_, int C::*p_, std::initializer_list< int > valid_)
std::initializer_list< int > valid
void load(C &c, std::string_view value) const
constexpr PersistentElementMax(zstring_view name_, int C::*p_, int max_)
void load(C &c, std::string_view value) const
constexpr PersistentElementMinMax(zstring_view name_, int C::*p_, int min_, int max_)
void save(ImGuiTextBuffer &buf, C &c) const
void load(C &c, zstring_view value) const
void load(C &c, zstring_view value) const
void save(ImGuiTextBuffer &buf, C &c) const
void load(C &c, zstring_view value) const
void save(ImGuiTextBuffer &buf, C &c) const
void save(ImGuiTextBuffer &buf, C &c) const
void load(C &c, zstring_view value) const
void load(C &c, zstring_view value) const
void save(ImGuiTextBuffer &buf, C &c) const
void save(ImGuiTextBuffer &buf, C &c) const
void load(C &c, zstring_view value) const
void load(C &c, zstring_view value) const
void save(ImGuiTextBuffer &buf, C &c) const
void load(C &c, zstring_view value) const
void save(ImGuiTextBuffer &buf, C &c) const