use more stringrefs
parent
7eaf3679a4
commit
fb8668a508
|
@ -92,6 +92,10 @@ struct OSTD_EXPORT cs_strref {
|
|||
return ostd::string_range{*this}.length();
|
||||
}
|
||||
|
||||
char const *data() const {
|
||||
return ostd::string_range{*this}.data();
|
||||
}
|
||||
|
||||
bool operator==(cs_strref const &s) const;
|
||||
|
||||
private:
|
||||
|
@ -234,9 +238,9 @@ struct OSTD_EXPORT cs_ident {
|
|||
}
|
||||
|
||||
protected:
|
||||
cs_ident(cs_ident_type tp, ostd::string_range name, int flags = 0);
|
||||
cs_ident(cs_ident_type tp, cs_strref name, int flags = 0);
|
||||
|
||||
cs_string p_name;
|
||||
cs_strref p_name;
|
||||
/* represents the cs_ident_type above, but internally it has a wider variety
|
||||
* of values, so it's an int here (maps to an internal enum)
|
||||
*/
|
||||
|
@ -251,7 +255,7 @@ struct OSTD_EXPORT cs_var: cs_ident {
|
|||
friend struct cs_shared_state;
|
||||
|
||||
protected:
|
||||
cs_var(cs_ident_type tp, ostd::string_range name, cs_var_cb func, int flags = 0);
|
||||
cs_var(cs_ident_type tp, cs_strref name, cs_var_cb func, int flags = 0);
|
||||
|
||||
private:
|
||||
cs_var_cb cb_var;
|
||||
|
@ -279,7 +283,7 @@ struct OSTD_EXPORT cs_ivar: cs_var {
|
|||
|
||||
private:
|
||||
cs_ivar(
|
||||
ostd::string_range n, cs_int m, cs_int x, cs_int v, cs_var_cb f, int flags
|
||||
cs_strref n, cs_int m, cs_int x, cs_int v, cs_var_cb f, int flags
|
||||
);
|
||||
|
||||
cs_int p_storage, p_minval, p_maxval, p_overrideval;
|
||||
|
@ -299,7 +303,7 @@ struct OSTD_EXPORT cs_fvar: cs_var {
|
|||
|
||||
private:
|
||||
cs_fvar(
|
||||
ostd::string_range n, cs_float m, cs_float x, cs_float v,
|
||||
cs_strref n, cs_float m, cs_float x, cs_float v,
|
||||
cs_var_cb f, int flags
|
||||
);
|
||||
|
||||
|
@ -310,15 +314,15 @@ struct OSTD_EXPORT cs_svar: cs_var {
|
|||
friend struct cs_state;
|
||||
friend struct cs_shared_state;
|
||||
|
||||
ostd::string_range get_value() const;
|
||||
void set_value(cs_string val);
|
||||
cs_strref get_value() const;
|
||||
void set_value(cs_strref val);
|
||||
|
||||
cs_string to_printable() const final;
|
||||
|
||||
private:
|
||||
cs_svar(ostd::string_range n, cs_string v, cs_var_cb f, int flags);
|
||||
cs_svar(cs_strref n, cs_strref v, cs_strref ov, cs_var_cb f, int flags);
|
||||
|
||||
cs_string p_storage, p_overrideval;
|
||||
cs_strref p_storage, p_overrideval;
|
||||
};
|
||||
|
||||
struct OSTD_EXPORT cs_alias: cs_ident {
|
||||
|
@ -332,12 +336,12 @@ struct OSTD_EXPORT cs_alias: cs_ident {
|
|||
|
||||
void get_cval(cs_value &v) const;
|
||||
private:
|
||||
cs_alias(cs_state &cs, ostd::string_range n, cs_strref a, int flags);
|
||||
cs_alias(cs_state &cs, ostd::string_range n, ostd::string_range a, int flags);
|
||||
cs_alias(cs_state &cs, ostd::string_range n, cs_int a, int flags);
|
||||
cs_alias(cs_state &cs, ostd::string_range n, cs_float a, int flags);
|
||||
cs_alias(cs_state &cs, ostd::string_range n, int flags);
|
||||
cs_alias(cs_state &cs, ostd::string_range n, cs_value v, int flags);
|
||||
cs_alias(cs_state &cs, cs_strref n, cs_strref a, int flags);
|
||||
cs_alias(cs_state &cs, cs_strref n, ostd::string_range a, int flags);
|
||||
cs_alias(cs_state &cs, cs_strref n, cs_int a, int flags);
|
||||
cs_alias(cs_state &cs, cs_strref n, cs_float a, int flags);
|
||||
cs_alias(cs_state &cs, cs_strref n, int flags);
|
||||
cs_alias(cs_state &cs, cs_strref n, cs_value v, int flags);
|
||||
|
||||
cs_bcode *p_acode;
|
||||
cs_ident_stack *p_astack;
|
||||
|
@ -353,12 +357,9 @@ struct cs_command: cs_ident {
|
|||
int get_num_args() const;
|
||||
|
||||
private:
|
||||
cs_command(
|
||||
ostd::string_range name, ostd::string_range args,
|
||||
int numargs, cs_command_cb func
|
||||
);
|
||||
cs_command(cs_strref name, cs_strref args, int numargs, cs_command_cb func);
|
||||
|
||||
cs_string p_cargs;
|
||||
cs_strref p_cargs;
|
||||
cs_command_cb p_cb_cftv;
|
||||
int p_numargs;
|
||||
};
|
||||
|
@ -445,7 +446,7 @@ struct OSTD_EXPORT cs_state {
|
|||
cs_var_cb f = cs_var_cb(), int flags = 0
|
||||
);
|
||||
cs_svar *new_svar(
|
||||
ostd::string_range n, cs_string v,
|
||||
ostd::string_range n, ostd::string_range v,
|
||||
cs_var_cb f = cs_var_cb(), int flags = 0
|
||||
);
|
||||
|
||||
|
|
|
@ -30,72 +30,71 @@ bool cs_check_num(ostd::string_range s) {
|
|||
}
|
||||
}
|
||||
|
||||
cs_ident::cs_ident(cs_ident_type tp, ostd::string_range nm, int fl):
|
||||
cs_ident::cs_ident(cs_ident_type tp, cs_strref nm, int fl):
|
||||
p_name(nm), p_type(int(tp)), p_flags(fl)
|
||||
{}
|
||||
|
||||
cs_var::cs_var(cs_ident_type tp, ostd::string_range name, cs_var_cb f, int fl):
|
||||
cs_var::cs_var(cs_ident_type tp, cs_strref name, cs_var_cb f, int fl):
|
||||
cs_ident(tp, name, fl), cb_var(std::move(f))
|
||||
{}
|
||||
|
||||
cs_ivar::cs_ivar(
|
||||
ostd::string_range name, cs_int m, cs_int x, cs_int v, cs_var_cb f, int fl
|
||||
cs_strref name, cs_int m, cs_int x, cs_int v, cs_var_cb f, int fl
|
||||
):
|
||||
cs_var(cs_ident_type::Ivar, name, std::move(f), fl | ((m > x) ? CS_IDF_READONLY : 0)),
|
||||
p_storage(v), p_minval(m), p_maxval(x), p_overrideval(0)
|
||||
{}
|
||||
|
||||
cs_fvar::cs_fvar(
|
||||
ostd::string_range name, cs_float m, cs_float x, cs_float v, cs_var_cb f, int fl
|
||||
cs_strref name, cs_float m, cs_float x, cs_float v, cs_var_cb f, int fl
|
||||
):
|
||||
cs_var(cs_ident_type::Fvar, name, std::move(f), fl | ((m > x) ? CS_IDF_READONLY : 0)),
|
||||
p_storage(v), p_minval(m), p_maxval(x), p_overrideval(0)
|
||||
{}
|
||||
|
||||
cs_svar::cs_svar(ostd::string_range name, cs_string v, cs_var_cb f, int fl):
|
||||
cs_svar::cs_svar(cs_strref name, cs_strref v, cs_strref ov, cs_var_cb f, int fl):
|
||||
cs_var(cs_ident_type::Svar, name, std::move(f), fl),
|
||||
p_storage(std::move(v)), p_overrideval()
|
||||
p_storage{v}, p_overrideval{ov}
|
||||
{}
|
||||
|
||||
cs_alias::cs_alias(cs_state &cs, ostd::string_range name, cs_strref a, int fl):
|
||||
cs_alias::cs_alias(cs_state &cs, cs_strref name, cs_strref a, int fl):
|
||||
cs_ident(cs_ident_type::Alias, name, fl),
|
||||
p_acode(nullptr), p_astack(nullptr), p_val{cs}
|
||||
{
|
||||
p_val.set_str(a);
|
||||
}
|
||||
cs_alias::cs_alias(cs_state &cs, ostd::string_range name, ostd::string_range a, int fl):
|
||||
cs_alias::cs_alias(cs_state &cs, cs_strref name, ostd::string_range a, int fl):
|
||||
cs_ident(cs_ident_type::Alias, name, fl),
|
||||
p_acode(nullptr), p_astack(nullptr), p_val{cs}
|
||||
{
|
||||
p_val.set_str(a);
|
||||
}
|
||||
cs_alias::cs_alias(cs_state &cs, ostd::string_range name, cs_int a, int fl):
|
||||
cs_alias::cs_alias(cs_state &cs, cs_strref name, cs_int a, int fl):
|
||||
cs_ident(cs_ident_type::Alias, name, fl),
|
||||
p_acode(nullptr), p_astack(nullptr), p_val{cs}
|
||||
{
|
||||
p_val.set_int(a);
|
||||
}
|
||||
cs_alias::cs_alias(cs_state &cs, ostd::string_range name, cs_float a, int fl):
|
||||
cs_alias::cs_alias(cs_state &cs, cs_strref name, cs_float a, int fl):
|
||||
cs_ident(cs_ident_type::Alias, name, fl),
|
||||
p_acode(nullptr), p_astack(nullptr), p_val{cs}
|
||||
{
|
||||
p_val.set_float(a);
|
||||
}
|
||||
cs_alias::cs_alias(cs_state &cs, ostd::string_range name, int fl):
|
||||
cs_alias::cs_alias(cs_state &cs, cs_strref name, int fl):
|
||||
cs_ident(cs_ident_type::Alias, name, fl),
|
||||
p_acode(nullptr), p_astack(nullptr), p_val{cs}
|
||||
{
|
||||
p_val.set_null();
|
||||
}
|
||||
/* FIXME: use cs rather than val's cs */
|
||||
cs_alias::cs_alias(cs_state &, ostd::string_range name, cs_value v, int fl):
|
||||
cs_alias::cs_alias(cs_state &, cs_strref name, cs_value v, int fl):
|
||||
cs_ident(cs_ident_type::Alias, name, fl),
|
||||
p_acode(nullptr), p_astack(nullptr), p_val(std::move(v))
|
||||
p_acode(nullptr), p_astack(nullptr), p_val(v)
|
||||
{}
|
||||
|
||||
cs_command::cs_command(
|
||||
ostd::string_range name, ostd::string_range args,
|
||||
int nargs, cs_command_cb f
|
||||
cs_strref name, cs_strref args, int nargs, cs_command_cb f
|
||||
):
|
||||
cs_ident(cs_ident_type::Command, name, 0),
|
||||
p_cargs(args), p_cb_cftv(std::move(f)), p_numargs(nargs)
|
||||
|
@ -275,11 +274,11 @@ cs_string cs_fvar::to_printable() const {
|
|||
return std::move(app.get());
|
||||
}
|
||||
|
||||
ostd::string_range cs_svar::get_value() const {
|
||||
return ostd::iter(p_storage);
|
||||
cs_strref cs_svar::get_value() const {
|
||||
return p_storage;
|
||||
}
|
||||
void cs_svar::set_value(cs_string val) {
|
||||
p_storage = std::move(val);
|
||||
void cs_svar::set_value(cs_strref val) {
|
||||
p_storage = val;
|
||||
}
|
||||
|
||||
cs_string cs_svar::to_printable() const {
|
||||
|
@ -529,7 +528,9 @@ OSTD_EXPORT cs_ident *cs_state::new_ident(ostd::string_range name, int flags) {
|
|||
*this, "number %s is not a valid identifier name", name
|
||||
);
|
||||
}
|
||||
id = add_ident(p_state->create<cs_alias>(*this, name, flags));
|
||||
id = add_ident(p_state->create<cs_alias>(
|
||||
*this, cs_strref{*p_state, name}, flags
|
||||
));
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
@ -585,25 +586,26 @@ OSTD_EXPORT cs_const_ident_r cs_state::get_idents() const {
|
|||
OSTD_EXPORT cs_ivar *cs_state::new_ivar(
|
||||
ostd::string_range n, cs_int m, cs_int x, cs_int v, cs_var_cb f, int flags
|
||||
) {
|
||||
return add_ident(
|
||||
p_state->create<cs_ivar>(n, m, x, v, std::move(f), flags)
|
||||
)->get_ivar();
|
||||
return add_ident(p_state->create<cs_ivar>(
|
||||
cs_strref{*p_state, n}, m, x, v, std::move(f), flags
|
||||
))->get_ivar();
|
||||
}
|
||||
|
||||
OSTD_EXPORT cs_fvar *cs_state::new_fvar(
|
||||
ostd::string_range n, cs_float m, cs_float x, cs_float v, cs_var_cb f, int flags
|
||||
) {
|
||||
return add_ident(
|
||||
p_state->create<cs_fvar>(n, m, x, v, std::move(f), flags)
|
||||
)->get_fvar();
|
||||
return add_ident(p_state->create<cs_fvar>(
|
||||
cs_strref{*p_state, n}, m, x, v, std::move(f), flags
|
||||
))->get_fvar();
|
||||
}
|
||||
|
||||
OSTD_EXPORT cs_svar *cs_state::new_svar(
|
||||
ostd::string_range n, cs_string v, cs_var_cb f, int flags
|
||||
ostd::string_range n, ostd::string_range v, cs_var_cb f, int flags
|
||||
) {
|
||||
return add_ident(
|
||||
p_state->create<cs_svar>(n, std::move(v), std::move(f), flags)
|
||||
)->get_svar();
|
||||
return add_ident(p_state->create<cs_svar>(
|
||||
cs_strref{*p_state, n}, cs_strref{*p_state, v},
|
||||
cs_strref{*p_state, ""}, std::move(f), flags
|
||||
))->get_svar();
|
||||
}
|
||||
|
||||
OSTD_EXPORT void cs_state::reset_var(ostd::string_range name) {
|
||||
|
@ -656,7 +658,7 @@ OSTD_EXPORT void cs_state::set_alias(ostd::string_range name, cs_value v) {
|
|||
throw cs_error(*this, "cannot alias number %s", name);
|
||||
} else {
|
||||
add_ident(p_state->create<cs_alias>(
|
||||
*this, name, std::move(v), identflags
|
||||
*this, cs_strref{*p_state, name}, std::move(v), identflags
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -776,7 +778,7 @@ OSTD_EXPORT void cs_state::set_var_str(
|
|||
*this, sv, sv->p_flags,
|
||||
[&sv]() { sv->p_overrideval = sv->get_value(); }
|
||||
);
|
||||
sv->set_value(cs_string{v});
|
||||
sv->set_value(cs_strref{*p_state, v});
|
||||
if (dofunc) {
|
||||
sv->changed(*this);
|
||||
}
|
||||
|
@ -950,7 +952,7 @@ OSTD_EXPORT void cs_state::set_var_str_checked(
|
|||
*this, sv, sv->p_flags,
|
||||
[&sv]() { sv->p_overrideval = sv->get_value(); }
|
||||
);
|
||||
sv->set_value(cs_string{v});
|
||||
sv->set_value(cs_strref{*p_state, v});
|
||||
sv->changed(*this);
|
||||
}
|
||||
|
||||
|
@ -1000,9 +1002,10 @@ OSTD_EXPORT cs_command *cs_state::new_command(
|
|||
return nullptr;
|
||||
}
|
||||
}
|
||||
return static_cast<cs_command *>(
|
||||
add_ident(p_state->create<cs_command>(name, args, nargs, std::move(func)))
|
||||
);
|
||||
return static_cast<cs_command *>(add_ident(p_state->create<cs_command>(
|
||||
cs_strref{*p_state, name}, cs_strref{*p_state, args}, nargs,
|
||||
std::move(func))
|
||||
));
|
||||
}
|
||||
|
||||
static inline void cs_do_loop(
|
||||
|
|
Loading…
Reference in New Issue