1#ifndef IMGUI_PARTINTERFACE_HH
2#define IMGUI_PARTINTERFACE_HH
11#include <initializer_list>
25 virtual void save(ImGuiTextBuffer& ) {}
38 :
name(name_),
p(p_) {}
43 T&
get(
C& c)
const {
return c.*
p; }
47template<
typename C,
typename T>
49template<
typename C,
typename T>
55 void save(ImGuiTextBuffer& buf,
C& c)
const {
56 buf.appendf(
"%s=%d\n", this->name.c_str(), this->get(c));
59 if (
auto r = StringOp::stringTo<int>(value)) {
71 void load(
C& c, std::string_view value)
const {
72 if (
auto r = StringOp::stringTo<int>(value)) {
73 if (0 <= *r && *r <
max) this->
get(c) = *r;
84 void load(
C& c, std::string_view value)
const {
85 if (
auto r = StringOp::stringTo<int>(value)) {
86 if (
min <= *r && *r <
max) this->
get(c) = *r;
93 std::initializer_list<int>
valid;
97 void load(
C& c, std::string_view value)
const {
98 if (
auto r = StringOp::stringTo<int>(value)) {
107 void save(ImGuiTextBuffer& buf,
C& c)
const {
108 buf.appendf(
"%s=%u\n", this->name.c_str(), this->get(c));
111 if (
auto r = StringOp::stringTo<unsigned>(value)) {
120 void save(ImGuiTextBuffer& buf,
C& c)
const {
121 buf.appendf(
"%s=%d\n", this->name.c_str(), this->get(c));
131 void save(ImGuiTextBuffer& buf,
C& c)
const {
132 buf.appendf(
"%s=%f\n", this->name.c_str(),
double(this->get(c)));
135 this->get(c) = strtof(value.
c_str(),
nullptr);
142 void save(ImGuiTextBuffer& buf,
C& c)
const {
153 void save(ImGuiTextBuffer& buf,
C& c)
const {
154 const auto& v = this->get(c);
155 buf.appendf(
"%s=[ %d %d ]\n", this->name.c_str(), v.x, v.y);
159 if (sscanf(value.
c_str(),
"[ %d %d ]", &
t.x, &
t.y) == 2) {
168 void save(ImGuiTextBuffer& buf,
C& c)
const {
169 const auto& v = this->get(c);
170 buf.appendf(
"%s=[ %f %f ]\n", this->name.c_str(),
171 double(v.x),
double(v.y));
175 if (sscanf(value.
c_str(),
"[ %f %f ]", &
t.x, &
t.y) == 2) {
184 void save(ImGuiTextBuffer& buf,
C& c)
const {
185 const auto& v = this->get(c);
186 buf.appendf(
"%s=[ %f %f %f %f ]\n", this->name.c_str(),
187 double(v.x),
double(v.y),
double(v.z),
double(v.w));
191 if (sscanf(value.
c_str(),
"[ %f %f %f %f ]", &
t.x, &
t.y, &
t.z, &
t.w) == 4) {
200 void save(ImGuiTextBuffer& buf,
C& c)
const {
201 buf.appendf(
"%s=%d\n", this->name.c_str(), this->get(c).open);
209template<
typename C,
typename... Elements>
212 std::apply([&](
auto& ...elem){(..., elem.save(buf, c));}, tup);
215template<
typename C,
typename Elem>
219 if (name != elem.name)
return false;
223template<
typename C,
typename... Elements>
225 C& c,
const std::tuple<Elements...>& tup)
227 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)
std::string decode(std::string_view input)
std::string encode(std::string_view input)
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 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