clean up the other var interfaces

master
Daniel Kolesa 2016-08-18 03:14:55 +01:00
parent f3b3751f76
commit 8418b8bb9e
3 changed files with 143 additions and 87 deletions

View File

@ -983,16 +983,16 @@ static ostd::Uint32 const *runcode(
)); ));
continue; continue;
case ID_SVAR: case ID_SVAR:
arg.set_str(*static_cast<Svar *>(id)->storage); arg.set_str(static_cast<Svar *>(id)->get_var_value());
continue; continue;
case ID_IVAR: case ID_IVAR:
arg.set_str(ostd::move( arg.set_str(ostd::move(
intstr(*static_cast<Ivar *>(id)->storage) intstr(static_cast<Ivar *>(id)->get_var_value())
)); ));
continue; continue;
case ID_FVAR: case ID_FVAR:
arg.set_str(ostd::move( arg.set_str(ostd::move(
floatstr(*static_cast<Fvar *>(id)->storage) floatstr(static_cast<Fvar *>(id)->get_var_value())
)); ));
continue; continue;
case ID_UNKNOWN: case ID_UNKNOWN:
@ -1025,14 +1025,16 @@ static ostd::Uint32 const *runcode(
continue; continue;
case ID_SVAR: case ID_SVAR:
arg.set_int(cs_parse_int( arg.set_int(cs_parse_int(
*static_cast<Svar *>(id)->storage static_cast<Svar *>(id)->get_var_value()
)); ));
continue; continue;
case ID_IVAR: case ID_IVAR:
arg.set_int(*static_cast<Ivar *>(id)->storage); arg.set_int(static_cast<Ivar *>(id)->get_var_value());
continue; continue;
case ID_FVAR: case ID_FVAR:
arg.set_int(CsInt(*static_cast<Fvar *>(id)->storage)); arg.set_int(
CsInt(static_cast<Fvar *>(id)->get_var_value())
);
continue; continue;
case ID_UNKNOWN: case ID_UNKNOWN:
arg.set_int(0); arg.set_int(0);
@ -1066,16 +1068,18 @@ static ostd::Uint32 const *runcode(
continue; continue;
case ID_SVAR: case ID_SVAR:
arg.set_float(cs_parse_float( arg.set_float(cs_parse_float(
*static_cast<Svar *>(id)->storage static_cast<Svar *>(id)->get_var_value()
)); ));
continue; continue;
case ID_IVAR: case ID_IVAR:
arg.set_float(CsFloat( arg.set_float(CsFloat(
*static_cast<Ivar *>(id)->storage static_cast<Ivar *>(id)->get_var_value()
)); ));
continue; continue;
case ID_FVAR: case ID_FVAR:
arg.set_float(*static_cast<Fvar *>(id)->storage); arg.set_float(
static_cast<Fvar *>(id)->get_var_value()
);
continue; continue;
case ID_UNKNOWN: case ID_UNKNOWN:
arg.set_float(CsFloat(0)); arg.set_float(CsFloat(0));
@ -1106,13 +1110,15 @@ static ostd::Uint32 const *runcode(
static_cast<Alias *>(id)->val_v.get_val(arg); static_cast<Alias *>(id)->val_v.get_val(arg);
continue; continue;
case ID_SVAR: case ID_SVAR:
arg.set_str(*static_cast<Svar *>(id)->storage); arg.set_str(static_cast<Svar *>(id)->get_var_value());
continue; continue;
case ID_IVAR: case ID_IVAR:
arg.set_int(*static_cast<Ivar *>(id)->storage); arg.set_int(static_cast<Ivar *>(id)->get_var_value());
continue; continue;
case ID_FVAR: case ID_FVAR:
arg.set_float(*static_cast<Fvar *>(id)->storage); arg.set_float(
static_cast<Fvar *>(id)->get_var_value()
);
continue; continue;
case ID_UNKNOWN: case ID_UNKNOWN:
arg.set_null(); arg.set_null();
@ -1142,16 +1148,16 @@ static ostd::Uint32 const *runcode(
static_cast<Alias *>(id)->get_cstr(arg); static_cast<Alias *>(id)->get_cstr(arg);
continue; continue;
case ID_SVAR: case ID_SVAR:
arg.set_cstr(*static_cast<Svar *>(id)->storage); arg.set_cstr(static_cast<Svar *>(id)->get_var_value());
continue; continue;
case ID_IVAR: case ID_IVAR:
arg.set_str(ostd::move( arg.set_str(ostd::move(
intstr(*static_cast<Ivar *>(id)->storage) intstr(static_cast<Ivar *>(id)->get_var_value())
)); ));
continue; continue;
case ID_FVAR: case ID_FVAR:
arg.set_str(ostd::move( arg.set_str(ostd::move(
floatstr(*static_cast<Fvar *>(id)->storage) floatstr(static_cast<Fvar *>(id)->get_var_value())
)); ));
continue; continue;
case ID_UNKNOWN: case ID_UNKNOWN:
@ -1181,13 +1187,13 @@ static ostd::Uint32 const *runcode(
static_cast<Alias *>(id)->get_cval(arg); static_cast<Alias *>(id)->get_cval(arg);
continue; continue;
case ID_SVAR: case ID_SVAR:
arg.set_cstr(*static_cast<Svar *>(id)->storage); arg.set_cstr(static_cast<Svar *>(id)->get_var_value());
continue; continue;
case ID_IVAR: case ID_IVAR:
arg.set_int(*static_cast<Ivar *>(id)->storage); arg.set_int(static_cast<Ivar *>(id)->get_var_value());
continue; continue;
case ID_FVAR: case ID_FVAR:
arg.set_float(*static_cast<Fvar *>(id)->storage); arg.set_float(static_cast<Fvar *>(id)->get_var_value());
continue; continue;
case ID_UNKNOWN: case ID_UNKNOWN:
arg.set_null(); arg.set_null();
@ -1212,22 +1218,22 @@ static ostd::Uint32 const *runcode(
case CODE_SVAR | RET_STR: case CODE_SVAR | RET_STR:
case CODE_SVAR | RET_NULL: case CODE_SVAR | RET_NULL:
args[numargs++].set_str( args[numargs++].set_str(
*static_cast<Svar *>(cs.identmap[op >> 8])->storage static_cast<Svar *>(cs.identmap[op >> 8])->get_var_value()
); );
continue; continue;
case CODE_SVAR | RET_INT: case CODE_SVAR | RET_INT:
args[numargs++].set_int(cs_parse_int( args[numargs++].set_int(cs_parse_int(
*static_cast<Svar *>(cs.identmap[op >> 8])->storage static_cast<Svar *>(cs.identmap[op >> 8])->get_var_value()
)); ));
continue; continue;
case CODE_SVAR | RET_FLOAT: case CODE_SVAR | RET_FLOAT:
args[numargs++].set_float(cs_parse_float( args[numargs++].set_float(cs_parse_float(
*static_cast<Svar *>(cs.identmap[op >> 8])->storage static_cast<Svar *>(cs.identmap[op >> 8])->get_var_value()
)); ));
continue; continue;
case CODE_SVARM: case CODE_SVARM:
args[numargs++].set_cstr( args[numargs++].set_cstr(
*static_cast<Svar *>(cs.identmap[op >> 8])->storage static_cast<Svar *>(cs.identmap[op >> 8])->get_var_value()
); );
continue; continue;
case CODE_SVAR1: case CODE_SVAR1:
@ -1240,17 +1246,17 @@ static ostd::Uint32 const *runcode(
case CODE_IVAR | RET_INT: case CODE_IVAR | RET_INT:
case CODE_IVAR | RET_NULL: case CODE_IVAR | RET_NULL:
args[numargs++].set_int( args[numargs++].set_int(
*static_cast<Ivar *>(cs.identmap[op >> 8])->storage static_cast<Ivar *>(cs.identmap[op >> 8])->get_var_value()
); );
continue; continue;
case CODE_IVAR | RET_STR: case CODE_IVAR | RET_STR:
args[numargs++].set_str(ostd::move(intstr( args[numargs++].set_str(ostd::move(intstr(
*static_cast<Ivar *>(cs.identmap[op >> 8])->storage static_cast<Ivar *>(cs.identmap[op >> 8])->get_var_value()
))); )));
continue; continue;
case CODE_IVAR | RET_FLOAT: case CODE_IVAR | RET_FLOAT:
args[numargs++].set_float(CsFloat( args[numargs++].set_float(CsFloat(
*static_cast<Ivar *>(cs.identmap[op >> 8])->storage static_cast<Ivar *>(cs.identmap[op >> 8])->get_var_value()
)); ));
continue; continue;
case CODE_IVAR1: case CODE_IVAR1:
@ -1276,17 +1282,17 @@ static ostd::Uint32 const *runcode(
case CODE_FVAR | RET_FLOAT: case CODE_FVAR | RET_FLOAT:
case CODE_FVAR | RET_NULL: case CODE_FVAR | RET_NULL:
args[numargs++].set_float( args[numargs++].set_float(
*static_cast<Fvar *>(cs.identmap[op >> 8])->storage static_cast<Fvar *>(cs.identmap[op >> 8])->get_var_value()
); );
continue; continue;
case CODE_FVAR | RET_STR: case CODE_FVAR | RET_STR:
args[numargs++].set_str(ostd::move(floatstr( args[numargs++].set_str(ostd::move(floatstr(
*static_cast<Fvar *>(cs.identmap[op >> 8])->storage static_cast<Fvar *>(cs.identmap[op >> 8])->get_var_value()
))); )));
continue; continue;
case CODE_FVAR | RET_INT: case CODE_FVAR | RET_INT:
args[numargs++].set_int(int( args[numargs++].set_int(int(
*static_cast<Fvar *>(cs.identmap[op >> 8])->storage static_cast<Fvar *>(cs.identmap[op >> 8])->get_var_value()
)); ));
continue; continue;
case CODE_FVAR1: case CODE_FVAR1:

View File

@ -50,19 +50,19 @@ Ivar::Ivar(
ostd::ConstCharRange name, CsInt m, CsInt x, CsInt *s, VarCb f, int fl ostd::ConstCharRange name, CsInt m, CsInt x, CsInt *s, VarCb f, int fl
): ):
Var(IdentType::ivar, name, ostd::move(f), fl | ((m > x) ? IDF_READONLY : 0)), Var(IdentType::ivar, name, ostd::move(f), fl | ((m > x) ? IDF_READONLY : 0)),
minval(m), maxval(x), overrideval(0), storage(s) p_storage(s), p_minval(m), p_maxval(x), p_overrideval(0)
{} {}
Fvar::Fvar( Fvar::Fvar(
ostd::ConstCharRange name, CsFloat m, CsFloat x, CsFloat *s, VarCb f, int fl ostd::ConstCharRange name, CsFloat m, CsFloat x, CsFloat *s, VarCb f, int fl
): ):
Var(IdentType::fvar, name, ostd::move(f), fl | ((m > x) ? IDF_READONLY : 0)), Var(IdentType::fvar, name, ostd::move(f), fl | ((m > x) ? IDF_READONLY : 0)),
minval(m), maxval(x), overrideval(0), storage(s) p_storage(s), p_minval(m), p_maxval(x), p_overrideval(0)
{} {}
Svar::Svar(ostd::ConstCharRange name, char **s, VarCb f, int fl): Svar::Svar(ostd::ConstCharRange name, char **s, VarCb f, int fl):
Var(IdentType::svar, name, ostd::move(f), fl), Var(IdentType::svar, name, ostd::move(f), fl),
overrideval(nullptr), storage(s) p_storage(s), p_overrideval(nullptr)
{} {}
Alias::Alias(ostd::ConstCharRange name, char *a, int fl): Alias::Alias(ostd::ConstCharRange name, char *a, int fl):
@ -204,6 +204,32 @@ Svar const *Ident::get_svar() const {
return static_cast<Svar const *>(this); return static_cast<Svar const *>(this);
} }
CsInt Ivar::get_val_min() const {
return p_minval;
}
CsInt Ivar::get_val_max() const {
return p_maxval;
}
CsInt Ivar::get_var_value() const {
return *p_storage;
}
CsFloat Fvar::get_val_min() const {
return p_minval;
}
CsFloat Fvar::get_val_max() const {
return p_maxval;
}
CsFloat Fvar::get_var_value() const {
return *p_storage;
}
ostd::ConstCharRange Svar::get_var_value() const {
return *p_storage;
}
void cs_init_lib_base(CsState &cs); void cs_init_lib_base(CsState &cs);
CsState::CsState() { CsState::CsState() {
@ -250,20 +276,20 @@ void CsState::clear_override(Ident &id) {
} }
case IdentType::ivar: { case IdentType::ivar: {
Ivar &iv = static_cast<Ivar &>(id); Ivar &iv = static_cast<Ivar &>(id);
*iv.storage = iv.overrideval; *iv.p_storage = iv.p_overrideval;
iv.changed(); iv.changed();
break; break;
} }
case IdentType::fvar: { case IdentType::fvar: {
Fvar &fv = static_cast<Fvar &>(id); Fvar &fv = static_cast<Fvar &>(id);
*fv.storage = fv.overrideval; *fv.p_storage = fv.p_overrideval;
fv.changed(); fv.changed();
break; break;
} }
case IdentType::svar: { case IdentType::svar: {
Svar &sv = static_cast<Svar &>(id); Svar &sv = static_cast<Svar &>(id);
delete[] *sv.storage; delete[] *sv.p_storage;
*sv.storage = sv.overrideval; *sv.p_storage = sv.p_overrideval;
sv.changed(); sv.changed();
break; break;
} }
@ -388,7 +414,7 @@ void CsState::print_var_int(Ivar *iv, CsInt i) {
return; return;
} }
if (iv->get_flags() & IDF_HEX) { if (iv->get_flags() & IDF_HEX) {
if (iv->maxval == 0xFFFFFF) { if (iv->get_val_max() == 0xFFFFFF) {
writefln( writefln(
"%s = 0x%.6X (%d, %d, %d)", iv->get_name(), "%s = 0x%.6X (%d, %d, %d)", iv->get_name(),
i, (i >> 16) & 0xFF, (i >> 8) & 0xFF, i & 0xFF i, (i >> 16) & 0xFF, (i >> 8) & 0xFF, i & 0xFF
@ -417,17 +443,17 @@ void CsState::print_var(Var *v) {
switch (v->get_type()) { switch (v->get_type()) {
case IdentType::ivar: { case IdentType::ivar: {
Ivar *iv = static_cast<Ivar *>(v); Ivar *iv = static_cast<Ivar *>(v);
print_var_int(iv, *iv->storage); print_var_int(iv, *iv->p_storage);
break; break;
} }
case IdentType::fvar: { case IdentType::fvar: {
Fvar *fv = static_cast<Fvar *>(v); Fvar *fv = static_cast<Fvar *>(v);
print_var_float(fv, *fv->storage); print_var_float(fv, *fv->p_storage);
break; break;
} }
case IdentType::svar: { case IdentType::svar: {
Svar *sv = static_cast<Svar *>(v); Svar *sv = static_cast<Svar *>(v);
print_var_str(sv, *sv->storage); print_var_str(sv, *sv->p_storage);
break; break;
} }
default: default:
@ -817,16 +843,16 @@ void CsState::set_var_int(
Ivar *iv = static_cast<Ivar *>(id); Ivar *iv = static_cast<Ivar *>(id);
bool success = cs_override_var( bool success = cs_override_var(
*this, iv, iv->p_flags, *this, iv, iv->p_flags,
[&iv]() { iv->overrideval = *iv->storage; }, [&iv]() { iv->p_overrideval = *iv->p_storage; },
[]() {}, []() {} []() {}, []() {}
); );
if (!success) { if (!success) {
return; return;
} }
if (doclamp) { if (doclamp) {
*iv->storage = ostd::clamp(v, iv->minval, iv->maxval); *iv->p_storage = ostd::clamp(v, iv->get_val_min(), iv->get_val_max());
} else { } else {
*iv->storage = v; *iv->p_storage = v;
} }
if (dofunc) { if (dofunc) {
iv->changed(); iv->changed();
@ -843,16 +869,16 @@ void CsState::set_var_float(
Fvar *fv = static_cast<Fvar *>(id); Fvar *fv = static_cast<Fvar *>(id);
bool success = cs_override_var( bool success = cs_override_var(
*this, fv, fv->p_flags, *this, fv, fv->p_flags,
[&fv]() { fv->overrideval = *fv->storage; }, [&fv]() { fv->p_overrideval = *fv->p_storage; },
[]() {}, []() {} []() {}, []() {}
); );
if (!success) { if (!success) {
return; return;
} }
if (doclamp) { if (doclamp) {
*fv->storage = ostd::clamp(v, fv->minval, fv->maxval); *fv->p_storage = ostd::clamp(v, fv->get_val_min(), fv->get_val_max());
} else { } else {
*fv->storage = v; *fv->p_storage = v;
} }
if (dofunc) { if (dofunc) {
fv->changed(); fv->changed();
@ -869,14 +895,14 @@ void CsState::set_var_str(
Svar *sv = static_cast<Svar *>(id); Svar *sv = static_cast<Svar *>(id);
bool success = cs_override_var( bool success = cs_override_var(
*this, sv, sv->p_flags, *this, sv, sv->p_flags,
[&sv]() { sv->overrideval = *sv->storage; }, [&sv]() { sv->p_overrideval = *sv->p_storage; },
[&sv]() { delete[] sv->overrideval; }, [&sv]() { delete[] sv->p_overrideval; },
[&sv]() { delete[] *sv->storage; } [&sv]() { delete[] *sv->p_storage; }
); );
if (!success) { if (!success) {
return; return;
} }
*sv->storage = cs_dup_ostr(v); *sv->p_storage = cs_dup_ostr(v);
if (dofunc) { if (dofunc) {
sv->changed(); sv->changed();
} }
@ -887,7 +913,7 @@ ostd::Maybe<CsInt> CsState::get_var_int(ostd::ConstCharRange name) {
if (!id || id->is_ivar()) { if (!id || id->is_ivar()) {
return ostd::nothing; return ostd::nothing;
} }
return *static_cast<Ivar *>(id)->storage; return *static_cast<Ivar *>(id)->p_storage;
} }
ostd::Maybe<CsFloat> CsState::get_var_float(ostd::ConstCharRange name) { ostd::Maybe<CsFloat> CsState::get_var_float(ostd::ConstCharRange name) {
@ -895,7 +921,7 @@ ostd::Maybe<CsFloat> CsState::get_var_float(ostd::ConstCharRange name) {
if (!id || id->is_fvar()) { if (!id || id->is_fvar()) {
return ostd::nothing; return ostd::nothing;
} }
return *static_cast<Fvar *>(id)->storage; return *static_cast<Fvar *>(id)->p_storage;
} }
ostd::Maybe<ostd::String> CsState::get_var_str(ostd::ConstCharRange name) { ostd::Maybe<ostd::String> CsState::get_var_str(ostd::ConstCharRange name) {
@ -903,7 +929,7 @@ ostd::Maybe<ostd::String> CsState::get_var_str(ostd::ConstCharRange name) {
if (!id || id->is_svar()) { if (!id || id->is_svar()) {
return ostd::nothing; return ostd::nothing;
} }
return ostd::String(*static_cast<Svar *>(id)->storage); return ostd::String(*static_cast<Svar *>(id)->p_storage);
} }
ostd::Maybe<CsInt> CsState::get_var_min_int(ostd::ConstCharRange name) { ostd::Maybe<CsInt> CsState::get_var_min_int(ostd::ConstCharRange name) {
@ -911,7 +937,7 @@ ostd::Maybe<CsInt> CsState::get_var_min_int(ostd::ConstCharRange name) {
if (!id || id->is_ivar()) { if (!id || id->is_ivar()) {
return ostd::nothing; return ostd::nothing;
} }
return static_cast<Ivar *>(id)->minval; return static_cast<Ivar *>(id)->get_val_min();
} }
ostd::Maybe<CsInt> CsState::get_var_max_int(ostd::ConstCharRange name) { ostd::Maybe<CsInt> CsState::get_var_max_int(ostd::ConstCharRange name) {
@ -919,7 +945,7 @@ ostd::Maybe<CsInt> CsState::get_var_max_int(ostd::ConstCharRange name) {
if (!id || id->is_ivar()) { if (!id || id->is_ivar()) {
return ostd::nothing; return ostd::nothing;
} }
return static_cast<Ivar *>(id)->maxval; return static_cast<Ivar *>(id)->get_val_max();
} }
ostd::Maybe<CsFloat> CsState::get_var_min_float(ostd::ConstCharRange name) { ostd::Maybe<CsFloat> CsState::get_var_min_float(ostd::ConstCharRange name) {
@ -927,7 +953,7 @@ ostd::Maybe<CsFloat> CsState::get_var_min_float(ostd::ConstCharRange name) {
if (!id || id->is_fvar()) { if (!id || id->is_fvar()) {
return ostd::nothing; return ostd::nothing;
} }
return static_cast<Fvar *>(id)->minval; return static_cast<Fvar *>(id)->get_val_min();
} }
ostd::Maybe<CsFloat> CsState::get_var_max_float(ostd::ConstCharRange name) { ostd::Maybe<CsFloat> CsState::get_var_max_float(ostd::ConstCharRange name) {
@ -935,7 +961,7 @@ ostd::Maybe<CsFloat> CsState::get_var_max_float(ostd::ConstCharRange name) {
if (!id || id->is_fvar()) { if (!id || id->is_fvar()) {
return ostd::nothing; return ostd::nothing;
} }
return static_cast<Fvar *>(id)->maxval; return static_cast<Fvar *>(id)->get_val_max();
} }
ostd::Maybe<ostd::String> ostd::Maybe<ostd::String>
@ -954,10 +980,10 @@ CsState::get_alias_val(ostd::ConstCharRange name) {
} }
CsInt cs_clamp_var(CsState &cs, Ivar *iv, CsInt v) { CsInt cs_clamp_var(CsState &cs, Ivar *iv, CsInt v) {
if (v < iv->minval) { if (v < iv->get_val_min()) {
v = iv->minval; v = iv->get_val_min();
} else if (v > iv->maxval) { } else if (v > iv->get_val_max()) {
v = iv->maxval; v = iv->get_val_max();
} else { } else {
return v; return v;
} }
@ -965,12 +991,12 @@ CsInt cs_clamp_var(CsState &cs, Ivar *iv, CsInt v) {
cs, cs,
(iv->get_flags() & IDF_HEX) (iv->get_flags() & IDF_HEX)
? ( ? (
(iv->minval <= 255) (iv->get_val_min() <= 255)
? "valid range for '%s' is %d..0x%X" ? "valid range for '%s' is %d..0x%X"
: "valid range for '%s' is 0x%X..0x%X" : "valid range for '%s' is 0x%X..0x%X"
) )
: "valid range for '%s' is %d..%d", : "valid range for '%s' is %d..%d",
iv->get_name(), iv->minval, iv->maxval iv->get_name(), iv->get_val_min(), iv->get_val_max()
); );
return v; return v;
} }
@ -982,16 +1008,16 @@ void CsState::set_var_int_checked(Ivar *iv, CsInt v) {
} }
bool success = cs_override_var( bool success = cs_override_var(
*this, iv, iv->p_flags, *this, iv, iv->p_flags,
[&iv]() { iv->overrideval = *iv->storage; }, [&iv]() { iv->p_overrideval = *iv->p_storage; },
[]() {}, []() {} []() {}, []() {}
); );
if (!success) { if (!success) {
return; return;
} }
if ((v < iv->minval) || (v > iv->maxval)) { if ((v < iv->get_val_min()) || (v > iv->get_val_max())) {
v = cs_clamp_var(*this, iv, v); v = cs_clamp_var(*this, iv, v);
} }
*iv->storage = v; *iv->p_storage = v;
iv->changed(); iv->changed();
} }
@ -1007,16 +1033,16 @@ void CsState::set_var_int_checked(Ivar *iv, TvalRange args) {
} }
CsFloat cs_clamp_fvar(CsState &cs, Fvar *fv, CsFloat v) { CsFloat cs_clamp_fvar(CsState &cs, Fvar *fv, CsFloat v) {
if (v < fv->minval) { if (v < fv->get_val_min()) {
v = fv->minval; v = fv->get_val_min();
} else if (v > fv->maxval) { } else if (v > fv->get_val_max()) {
v = fv->maxval; v = fv->get_val_max();
} else { } else {
return v; return v;
} }
cs_debug_code( cs_debug_code(
cs, "valid range for '%s' is %s..%s", floatstr(fv->minval), cs, "valid range for '%s' is %s..%s", floatstr(fv->get_val_min()),
floatstr(fv->maxval) floatstr(fv->get_val_max())
); );
return v; return v;
} }
@ -1028,16 +1054,16 @@ void CsState::set_var_float_checked(Fvar *fv, CsFloat v) {
} }
bool success = cs_override_var( bool success = cs_override_var(
*this, fv, fv->p_flags, *this, fv, fv->p_flags,
[&fv]() { fv->overrideval = *fv->storage; }, [&fv]() { fv->p_overrideval = *fv->p_storage; },
[]() {}, []() {} []() {}, []() {}
); );
if (!success) { if (!success) {
return; return;
} }
if ((v < fv->minval) || (v > fv->maxval)) { if ((v < fv->get_val_min()) || (v > fv->get_val_max())) {
v = cs_clamp_fvar(*this, fv, v); v = cs_clamp_fvar(*this, fv, v);
} }
*fv->storage = v; *fv->p_storage = v;
fv->changed(); fv->changed();
} }
@ -1048,14 +1074,14 @@ void CsState::set_var_str_checked(Svar *sv, ostd::ConstCharRange v) {
} }
bool success = cs_override_var( bool success = cs_override_var(
*this, sv, sv->p_flags, *this, sv, sv->p_flags,
[&sv]() { sv->overrideval = *sv->storage; }, [&sv]() { sv->p_overrideval = *sv->p_storage; },
[&sv]() { delete[] sv->overrideval; }, [&sv]() { delete[] sv->p_overrideval; },
[&sv]() { delete[] *sv->storage; } [&sv]() { delete[] *sv->p_storage; }
); );
if (!success) { if (!success) {
return; return;
} }
*sv->storage = cs_dup_ostr(v); *sv->p_storage = cs_dup_ostr(v);
sv->changed(); sv->changed();
} }

View File

@ -228,6 +228,12 @@ private:
using VarCb = ostd::Function<void(Ident &)>; using VarCb = ostd::Function<void(Ident &)>;
struct OSTD_EXPORT Var: Ident { struct OSTD_EXPORT Var: Ident {
friend struct CsState;
protected:
Var(IdentType tp, ostd::ConstCharRange name, VarCb func, int flags = 0);
private:
VarCb cb_var; VarCb cb_var;
void changed() { void changed() {
@ -235,39 +241,57 @@ struct OSTD_EXPORT Var: Ident {
cb_var(*this); cb_var(*this);
} }
} }
protected:
Var(IdentType tp, ostd::ConstCharRange name, VarCb func, int flags = 0);
}; };
struct OSTD_EXPORT Ivar: Var { struct OSTD_EXPORT Ivar: Var {
CsInt minval, maxval, overrideval; friend struct CsState;
CsInt *storage;
CsInt get_val_min() const;
CsInt get_val_max() const;
CsInt get_var_value() const;
Ivar( Ivar(
ostd::ConstCharRange n, CsInt m, CsInt x, CsInt *s, ostd::ConstCharRange n, CsInt m, CsInt x, CsInt *s,
VarCb f = VarCb(), int flags = 0 VarCb f = VarCb(), int flags = 0
); );
private:
CsInt *p_storage;
CsInt p_minval, p_maxval, p_overrideval;
}; };
struct OSTD_EXPORT Fvar: Var { struct OSTD_EXPORT Fvar: Var {
CsFloat minval, maxval, overrideval; friend struct CsState;
CsFloat *storage;
CsFloat get_val_min() const;
CsFloat get_val_max() const;
CsFloat get_var_value() const;
Fvar( Fvar(
ostd::ConstCharRange n, CsFloat m, CsFloat x, CsFloat *s, ostd::ConstCharRange n, CsFloat m, CsFloat x, CsFloat *s,
VarCb f = VarCb(), int flags = 0 VarCb f = VarCb(), int flags = 0
); );
private:
CsFloat *p_storage;
CsFloat p_minval, p_maxval, p_overrideval;
}; };
struct OSTD_EXPORT Svar: Var { struct OSTD_EXPORT Svar: Var {
char *overrideval; friend struct CsState;
char **storage;
ostd::ConstCharRange get_var_value() const;
Svar( Svar(
ostd::ConstCharRange n, char **s, VarCb f = VarCb(), ostd::ConstCharRange n, char **s, VarCb f = VarCb(),
int flags = 0 int flags = 0
); );
private:
char **p_storage;
char *p_overrideval;
}; };
struct OSTD_EXPORT Alias: Ident { struct OSTD_EXPORT Alias: Ident {