From e638b388f2455747a7fdf5495683585dd646dd52 Mon Sep 17 00:00:00 2001 From: q66 Date: Thu, 25 Aug 2016 21:24:23 +0100 Subject: [PATCH] move some implementations --- cubescript.cc | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ cubescript.hh | 65 +++++++++----------------------------------------- 2 files changed, 77 insertions(+), 54 deletions(-) diff --git a/cubescript.cc b/cubescript.cc index 96df3a1d..1c5846e3 100644 --- a/cubescript.cc +++ b/cubescript.cc @@ -498,6 +498,72 @@ void CsValue::cleanup() { } } +int CsValue::get_type() const { + return p_type; +} + +void CsValue::set_int(CsInt val) { + p_type = VAL_INT; + i = val; +} + +void CsValue::set_float(CsFloat val) { + p_type = VAL_FLOAT; + f = val; +} + +void CsValue::set_str(CsString val) { + if (val.size() == 0) { + /* ostd zero length strings cannot be disowned */ + char *buf = new char[1]; + buf[0] = '\0'; + set_mstr(buf); + return; + } + ostd::CharRange cr = val.iter(); + val.disown(); + set_mstr(cr); +} + +void CsValue::set_null() { + p_type = VAL_NULL; + i = 0; +} + +void CsValue::set_code(Bytecode const *val) { + p_type = VAL_CODE; + code = val; +} + +void CsValue::set_cstr(ostd::ConstCharRange val) { + p_type = VAL_CSTR; + len = val.size(); + cstr = val.data(); +} + +void CsValue::set_mstr(ostd::CharRange val) { + p_type = VAL_STR; + len = val.size(); + s = val.data(); +} + +void CsValue::set_ident(Ident *val) { + p_type = VAL_IDENT; + id = val; +} + +void CsValue::set_macro(Bytecode const *val, ostd::Size ln) { + p_type = VAL_MACRO; + len = ln; + code = val; +} + +void CsValue::set(CsValue &tv) { + *this = tv; + tv.p_type = VAL_NULL; +} + + void CsValue::force_null() { if (get_type() == VAL_NULL) { return; diff --git a/cubescript.hh b/cubescript.hh index 48cc4ef9..0a94e3fe 100644 --- a/cubescript.hh +++ b/cubescript.hh @@ -77,62 +77,19 @@ struct OSTD_EXPORT CsValue { }; ostd::Size len; - int get_type() const { - return p_type; - } + int get_type() const; - void set_int(CsInt val) { - p_type = VAL_INT; - i = val; - } - void set_float(CsFloat val) { - p_type = VAL_FLOAT; - f = val; - } - void set_str(CsString val) { - if (val.size() == 0) { - /* ostd zero length strings cannot be disowned */ - char *buf = new char[1]; - buf[0] = '\0'; - set_mstr(buf); - return; - } - ostd::CharRange cr = val.iter(); - val.disown(); - set_mstr(cr); - } - void set_null() { - p_type = VAL_NULL; - i = 0; - } - void set_code(Bytecode const *val) { - p_type = VAL_CODE; - code = val; - } - void set_cstr(ostd::ConstCharRange val) { - p_type = VAL_CSTR; - len = val.size(); - cstr = val.data(); - } - void set_mstr(ostd::CharRange val) { - p_type = VAL_STR; - len = val.size(); - s = val.data(); - } - void set_ident(Ident *val) { - p_type = VAL_IDENT; - id = val; - } - void set_macro(Bytecode const *val, ostd::Size ln) { - p_type = VAL_MACRO; - len = ln; - code = val; - } + void set_int(CsInt val); + void set_float(CsFloat val); + void set_str(CsString val); + void set_null(); + void set_code(Bytecode const *val); + void set_cstr(ostd::ConstCharRange val); + void set_mstr(ostd::CharRange val); + void set_ident(Ident *val); + void set_macro(Bytecode const *val, ostd::Size ln); - void set(CsValue &tv) { - *this = tv; - tv.p_type = VAL_NULL; - } + void set(CsValue &tv); CsString get_str() const; ostd::ConstCharRange get_strr() const;