Commit 4017a911 authored by twanvl's avatar twanvl

Use toXXX() instead of operator XXX in ScriptValue.

This means that we are more explicit about type conversions.
parent a754df74
......@@ -680,7 +680,7 @@ bool KeywordDatabase::tryExpand(const Keyword& kw,
ctx.setVariable(_("used_placeholders"), to_script(used_placeholders));
// Final check whether the keyword matches
if (match_condition && (bool)*match_condition->eval(ctx) == false) {
if (match_condition && match_condition->eval(ctx)->toBool() == false) {
return false;
}
......@@ -688,7 +688,7 @@ bool KeywordDatabase::tryExpand(const Keyword& kw,
bool expand = expand_type == _('1');
if (!expand && expand_type != _('0')) {
// default expand, determined by script
expand = expand_default ? (bool)*expand_default->eval(ctx) : true;
expand = expand_default ? expand_default->eval(ctx)->toBool() : true;
expand_type = expand ? _('A') : _('a');
}
......@@ -726,7 +726,7 @@ bool KeywordDatabase::tryExpand(const Keyword& kw,
ScriptType KeywordParamValue::type() const { return SCRIPT_STRING; }
String KeywordParamValue::typeName() const { return _("keyword parameter"); }
KeywordParamValue::operator String() const {
String KeywordParamValue::toString() const {
String safe_type = replace_all(replace_all(replace_all(type_name,
_("("),_("-")),
_(")"),_("-")),
......@@ -734,11 +734,11 @@ KeywordParamValue::operator String() const {
return _("<param-") + safe_type + _(">") + value + _("</param-") + safe_type + _(">");
}
KeywordParamValue::operator int() const { return *to_script(value); } // a bit of a hack
KeywordParamValue::operator double() const { return *to_script(value); }
KeywordParamValue::operator bool() const { return *to_script(value); }
KeywordParamValue::operator AColor() const { return *to_script(value); }
int KeywordParamValue::itemCount() const { return to_script(value)->itemCount(); }
int KeywordParamValue::toInt() const { return to_script(value)->toInt(); } // a bit of a hack
double KeywordParamValue::toDouble() const { return to_script(value)->toDouble(); }
bool KeywordParamValue::toBool() const { return to_script(value)->toBool(); }
AColor KeywordParamValue::toColor() const { return to_script(value)->toColor(); }
int KeywordParamValue::itemCount() const { return to_script(value)->itemCount(); }
ScriptValueP KeywordParamValue::getMember(const String& name) const {
if (name == _("type")) return to_script(type_name);
......
......@@ -193,11 +193,11 @@ class KeywordParamValue : public ScriptValue {
virtual ScriptType type() const;
virtual String typeName() const;
virtual operator String() const;
virtual operator int() const;
virtual operator bool() const;
virtual operator double() const;
virtual operator AColor() const;
virtual String toString() const;
virtual int toInt() const;
virtual bool toBool() const;
virtual double toDouble() const;
virtual AColor toColor() const;
virtual int itemCount() const;
virtual ScriptValueP getMember(const String& name) const;
};
......
......@@ -116,7 +116,7 @@ PackInstance::PackInstance(const PackType& pack_type, PackGenerator& parent)
if (pack_type.filter) {
FOR_EACH(card, parent.set->cards) {
Context& ctx = parent.set->getContext(card);
bool keep = *pack_type.filter.invoke(ctx);
bool keep = pack_type.filter.invoke(ctx)->toBool();
if (keep) {
cards.push_back(card);
}
......
......@@ -270,9 +270,9 @@ int Set::positionOfCard(const CardP& card, const ScriptValueP& order_by, const S
vector<int> keep; if(filter) keep.reserve(cards.size());
FOR_EACH_CONST(c, cards) {
Context& ctx = getContext(c);
values.push_back(*order_by->eval(ctx));
values.push_back(order_by->eval(ctx)->toString());
if (filter) {
keep.push_back((bool)*filter->eval(ctx));
keep.push_back(filter->eval(ctx)->toBool());
}
}
#if USE_SCRIPT_PROFILING
......@@ -292,7 +292,7 @@ int Set::numberOfCards(const ScriptValueP& filter) {
} else {
int n = 0;
FOR_EACH_CONST(c, cards) {
if (*filter->eval(getContext(c))) ++n;
if (filter->eval(getContext(c))->toBool()) ++n;
}
filter_cache.insert(make_pair(filter,n));
return n;
......
......@@ -324,7 +324,7 @@ int CardListBase::OnGetItemImage(long pos) const {
wxListItemAttr* CardListBase::OnGetItemAttr(long pos) const {
if (!set->game->card_list_color_script) return nullptr;
Context& ctx = set->getContext(getCard(pos));
item_attr.SetTextColour(*set->game->card_list_color_script.invoke(ctx));
item_attr.SetTextColour(set->game->card_list_color_script.invoke(ctx)->toColor());
return &item_attr;
}
......
......@@ -83,7 +83,7 @@ ScriptValueP export_set(SetP const& set, vector<CardP> const& cards, ExportTempl
// write as string
wxFileOutputStream file(outname);
wxTextOutputStream stream(file);
stream.WriteString(*result);
stream.WriteString(result->toString());
}
return result;
}
......
......@@ -412,7 +412,7 @@ void ConsolePanel::exec(String const& command) {
message->bitmap = wxBitmap(image);
} else if (type == SCRIPT_COLOR) {
message->text = result->toCode();
AColor color = (AColor)*result;
AColor color = result->toColor();
wxImage image(30,20);
fill_image(image,color);
set_alpha(image, color.alpha / 255.0);
......
......@@ -255,7 +255,7 @@ size_t DropDownChoiceList::selection() const {
return 0;
} else {
// run default script to find out what the default choice would be
String default_choice = *field().default_script.invoke( cve.viewer.getContext() );
String default_choice = field().default_script.invoke( cve.viewer.getContext() )->toString();
default_id = group->choiceId(default_choice);
}
}
......
......@@ -109,7 +109,7 @@ size_t DropDownColorList::selection() const {
return 0;
} else if (hasDefault()) {
// evaluate script to find default color
default_color = *field().default_script.invoke(cve.viewer.getContext());
default_color = field().default_script.invoke(cve.viewer.getContext())->toColor();
}
return selection;
}
......
......@@ -67,7 +67,7 @@ ScriptValueP Context::eval(const Script& script, bool useScope) {
}
// Conditional jump
case I_JUMP_IF_NOT: {
bool condition = *stack.back();
bool condition = stack.back()->toBool();
stack.pop_back();
if (!condition) {
instr = &script.instructions[0] + i.data;
......@@ -76,7 +76,7 @@ ScriptValueP Context::eval(const Script& script, bool useScope) {
}
// Short-circuiting and/or = conditional jump without pop
case I_JUMP_SC_AND: {
bool condition = *stack.back();
bool condition = stack.back()->toBool();
if (!condition) {
instr = &script.instructions[0] + i.data;
} else {
......@@ -85,7 +85,7 @@ ScriptValueP Context::eval(const Script& script, bool useScope) {
break;
}
case I_JUMP_SC_OR: {
bool condition = *stack.back();
bool condition = stack.back()->toBool();
if (condition) {
instr = &script.instructions[0] + i.data;
} else {
......@@ -109,7 +109,7 @@ ScriptValueP Context::eval(const Script& script, bool useScope) {
// Get an object member
case I_MEMBER_C: {
stack.back() = stack.back()->getMember(*script.constants[i.data]);
stack.back() = stack.back()->getMember(script.constants[i.data]->toString());
break;
}
// Loop over a container, push next value or jump
......@@ -367,13 +367,13 @@ void instrUnary (UnaryInstructionType i, ScriptValueP& a) {
case I_NEGATE: {
ScriptType at = a->type();
if (at == SCRIPT_DOUBLE) {
a = to_script(-(double)*a);
a = to_script(-a->toDouble());
} else {
a = to_script(-(int)*a);
a = to_script(-a->toInt());
}
break;
} case I_NOT:
a = to_script(!(bool)*a);
a = to_script(!a->toBool());
break;
}
}
......@@ -424,41 +424,41 @@ class ScriptCompose : public ScriptValue {
// ----------------------------------------------------------------------------- : Simple instructions : binary
// operator on ints
#define OPERATOR_I(OP) \
a = to_script((int)*a OP (int)*b); \
#define OPERATOR_I(OP) \
a = to_script(a->toInt() OP b->toInt()); \
break
// operator on bools
#define OPERATOR_B(OP) \
a = to_script((bool)*a OP (bool)*b); \
#define OPERATOR_B(OP) \
a = to_script(a->toBool() OP b->toBool()); \
break
// operator on doubles or ints
#define OPERATOR_DI(OP) \
if (at == SCRIPT_DOUBLE || bt == SCRIPT_DOUBLE) { \
a = to_script((double)*a OP (double)*b); \
} else { \
a = to_script((int)*a OP (int)*b); \
} \
#define OPERATOR_DI(OP) \
if (at == SCRIPT_DOUBLE || bt == SCRIPT_DOUBLE) { \
a = to_script(a->toDouble() OP b->toDouble()); \
} else { \
a = to_script(a->toInt() OP b->toInt()); \
} \
break
// operator on doubles or ints, defined as a function
#define OPERATOR_FUN_DI(OP) \
if (at == SCRIPT_DOUBLE || bt == SCRIPT_DOUBLE) { \
a = to_script(OP((double)*a, (double)*b)); \
} else { \
a = to_script(OP((int)*a, (int)*b)); \
} \
#define OPERATOR_FUN_DI(OP) \
if (at == SCRIPT_DOUBLE || bt == SCRIPT_DOUBLE) { \
a = to_script(OP(a->toDouble(), b->toDouble())); \
} else { \
a = to_script(OP(a->toInt(), b->toInt())); \
} \
break
void instrBinary (BinaryInstructionType i, ScriptValueP& a, const ScriptValueP& b) {
switch (i) {
case I_MEMBER:
a = a->getMember(*b);
a = a->getMember(b->toString());
break;
case I_ITERATOR_R:
a = rangeIterator(*a, *b);
a = rangeIterator(a->toInt(), b->toInt());
break;
default:
ScriptType at = a->type(), bt = b->type();
......@@ -472,46 +472,46 @@ void instrBinary (BinaryInstructionType i, ScriptValueP& a, const ScriptValueP&
a = intrusive(new ScriptCompose(a, b));
} else if (at == SCRIPT_COLLECTION && bt == SCRIPT_COLLECTION) {
a = intrusive(new ScriptConcatCollection(a, b));
} else if (at == SCRIPT_INT && bt == SCRIPT_INT) {
a = to_script((int)*a + (int)*b);
} else if (at == SCRIPT_INT && bt == SCRIPT_INT) {
a = to_script(a->toInt() + b->toInt());
} else if ((at == SCRIPT_INT || at == SCRIPT_DOUBLE) &&
(bt == SCRIPT_INT || bt == SCRIPT_DOUBLE)) {
a = to_script((double)*a + (double)*b);
a = to_script(a->toDouble() + b->toDouble());
} else {
a = to_script(a->toString() + b->toString());
a = to_script(a->toString() + b->toString());
}
break;
case I_SUB: OPERATOR_DI(-);
case I_MUL: OPERATOR_DI(*);
case I_FDIV:
a = to_script((double)*a / (double)*b);
a = to_script(a->toDouble() / b->toDouble());
break;
case I_DIV:
if (at == SCRIPT_DOUBLE || bt == SCRIPT_DOUBLE) {
a = to_script((int)((double)*a / (double)*b));
a = to_script((int)(a->toDouble() / b->toDouble()));
} else {
a = to_script((int)*a / (int)*b);
a = to_script(a->toInt() / b->toInt());
}
break;
case I_MOD:
if (at == SCRIPT_DOUBLE || bt == SCRIPT_DOUBLE) {
a = to_script(fmod((double)*a, (double)*b));
a = to_script(fmod(a->toDouble(), b->toDouble()));
} else {
a = to_script((int)*a % (int)*b);
a = to_script(a->toInt() % b->toInt());
}
break;
case I_POW:
if (bt == SCRIPT_INT) {
int bi = *b;
int bi = b->toInt();
if (at == SCRIPT_DOUBLE) {
double aa = *a;
double aa = a->toDouble();
if (bi == 0) a = to_script(1);
else if (bi == 1) a = to_script(aa);
else if (bi == 2) a = to_script(aa * aa);
else if (bi == 3) a = to_script(aa * aa * aa);
else a = to_script(pow(aa,bi));
} else {
int aa = *a;
int aa = a->toInt();
if (bi == 0) a = to_script(1);
else if (bi == 1) a = to_script(aa);
else if (bi == 2) a = to_script(aa * aa);
......@@ -519,7 +519,7 @@ void instrBinary (BinaryInstructionType i, ScriptValueP& a, const ScriptValueP&
else a = to_script(pow((double)aa,bi));
}
} else {
a = to_script(pow((double)*a, (double)*b));
a = to_script(pow(a->toDouble(), b->toDouble()));
}
break;
case I_AND: OPERATOR_B(&&);
......@@ -546,7 +546,7 @@ void instrBinary (BinaryInstructionType i, ScriptValueP& a, const ScriptValueP&
void instrTernary(TernaryInstructionType i, ScriptValueP& a, const ScriptValueP& b, const ScriptValueP& c) {
switch (i) {
case I_RGB:
a = to_script(Color((int)*a, (int)*b, (int)*c));
a = to_script(Color(a->toInt(), b->toInt(), c->toInt()));
break;
}
}
......@@ -556,7 +556,7 @@ void instrTernary(TernaryInstructionType i, ScriptValueP& a, const ScriptValueP&
void instrQuaternary(QuaternaryInstructionType i, ScriptValueP& a, const ScriptValueP& b, const ScriptValueP& c, const ScriptValueP& d) {
switch (i) {
case I_RGBA:
a = to_script(AColor((int)*a, (int)*b, (int)*c, (int)*d));
a = to_script(AColor(a->toInt(), b->toInt(), c->toInt(), d->toInt()));
break;
}
}
......
......@@ -83,10 +83,10 @@ class ScriptMissingVariable : public ScriptValue {
ScriptMissingVariable(const String& name) : name(name) {}
virtual ScriptType type() const { return SCRIPT_NIL; }
virtual String typeName() const { return _("missing variable '") + name + _("'"); }
virtual operator String() const { return wxEmptyString; }
virtual operator double() const { return 0.0; }
virtual operator int() const { return 0; }
virtual operator bool() const { return false; }
virtual String toString() const { return wxEmptyString; }
virtual double toDouble() const { return 0.0; }
virtual int toInt() const { return 0; }
virtual bool toBool() const { return false; }
virtual ScriptValueP eval(Context&) const { return script_nil; } // nil() == nil
private:
String name; ///< Name of the variable
......@@ -227,7 +227,7 @@ ScriptValueP Context::dependencies(const Dependency& dep, const Script& script)
// Get an object member (almost as normal)
case I_MEMBER_C: {
String name = *script.constants[i.data];
String name = script.constants[i.data]->toString();
stack.back() = stack.back()->dependencyMember(name, dep); // dependency on member
break;
}
......
......@@ -68,9 +68,9 @@ String format_input(const String& format, const ScriptValue& input) {
// determine type expected by format string
String fmt = _("%") + replace_all(format, _("%"), _(""));
if (format.find_first_of(_("DdIiOoXx")) != String::npos) {
return String::Format(fmt, (int)input);
return String::Format(fmt, input.toInt());
} else if (format.find_first_of(_("EeFfGg")) != String::npos) {
return String::Format(fmt, (double)input);
return String::Format(fmt, input.toDouble());
} else if (format.find_first_of(_("Ss")) != String::npos) {
return format_string(fmt, input.toString());
} else {
......@@ -85,7 +85,7 @@ SCRIPT_FUNCTION(to_string) {
try {
if (format && format->type() == SCRIPT_STRING) {
// format specifier. Be careful, the built in function 'format' has the same name
SCRIPT_RETURN(format_input(*format, *input));
SCRIPT_RETURN(format_input(format->toString(), *input));
} else {
// simple conversion
SCRIPT_RETURN(input->toString());
......@@ -101,9 +101,9 @@ SCRIPT_FUNCTION(to_int) {
try {
int result;
if (t == SCRIPT_BOOL) {
result = (bool)*input ? 1 : 0;
result = input->toBool() ? 1 : 0;
} else if (t == SCRIPT_COLOR) {
AColor c = (AColor)*input;
AColor c = input->toColor();
result = (c.Red() + c.Blue() + c.Green()) / 3;
} else if (t == SCRIPT_STRING) {
long l;
......@@ -116,7 +116,7 @@ SCRIPT_FUNCTION(to_int) {
return delay_error(ScriptErrorConversion(str, input->typeName(), _TYPE_("integer")));
}
} else {
result = (int)*input;
result = input->toInt();
}
SCRIPT_RETURN(result);
} catch (const ScriptError& e) {
......@@ -130,9 +130,9 @@ SCRIPT_FUNCTION(to_real) {
try {
double result;
if (t == SCRIPT_BOOL) {
result = (bool)*input ? 1.0 : 0.0;
result = input->toBool() ? 1.0 : 0.0;
} else if (t == SCRIPT_COLOR) {
AColor c = (AColor)*input;
AColor c = input->toColor();
result = (c.Red() + c.Blue() + c.Green()) / 3.0;
} else if (t == SCRIPT_STRING) {
String str = input->toString();
......@@ -142,7 +142,7 @@ SCRIPT_FUNCTION(to_real) {
return delay_error(ScriptErrorConversion(str, input->typeName(), _TYPE_("double")));
}
} else {
result = (double)*input;
result = input->toDouble();
}
SCRIPT_RETURN(result);
} catch (const ScriptError& e) {
......@@ -155,12 +155,12 @@ SCRIPT_FUNCTION(to_number) {
ScriptType t = input->type();
try {
if (t == SCRIPT_BOOL) {
SCRIPT_RETURN((bool)*input ? 1 : 0);
SCRIPT_RETURN(input->toBool() ? 1 : 0);
} else if (t == SCRIPT_COLOR) {
AColor c = (AColor)*input;
AColor c = input->toColor();
SCRIPT_RETURN( (c.Red() + c.Blue() + c.Green()) / 3 );
} else if (t == SCRIPT_DOUBLE) {
SCRIPT_RETURN((double)*input);
} else if (t == SCRIPT_DOUBLE || t == SCRIPT_INT) {
return input;
} else if (t == SCRIPT_NIL) {
SCRIPT_RETURN(0);
} else {
......@@ -187,9 +187,9 @@ SCRIPT_FUNCTION(to_boolean) {
ScriptType t = input->type();
bool result;
if (t == SCRIPT_INT) {
result = (int)*input != 0;
result = input->toInt() != 0;
} else {
result = (bool)*input;
result = input->toBool();
}
SCRIPT_RETURN(result);
} catch (const ScriptError& e) {
......@@ -226,9 +226,9 @@ SCRIPT_FUNCTION(abs) {
ScriptValueP input = ctx.getVariable(SCRIPT_VAR_input);
ScriptType t = input->type();
if (t == SCRIPT_DOUBLE) {
SCRIPT_RETURN(fabs((double)*input));
SCRIPT_RETURN(fabs(input->toDouble()));
} else {
SCRIPT_RETURN(abs((int)*input));
SCRIPT_RETURN(abs(input->toInt()));
}
}
......@@ -566,7 +566,7 @@ SCRIPT_FUNCTION(filter_list) {
ScriptValueP it = input->makeIterator(input);
while (ScriptValueP v = it->next()) {
ctx.setVariable(SCRIPT_VAR_input, v);
if (*filter->eval(ctx)) {
if (filter->eval(ctx)->toBool()) {
ret->value.push_back(v);
}
}
......@@ -609,7 +609,7 @@ SCRIPT_FUNCTION(random_select_many) {
SCRIPT_PARAM_C(ScriptValueP, input);
SCRIPT_PARAM(int, count) ;
SCRIPT_OPTIONAL_PARAM_C_(ScriptValueP, replace);
bool with_replace = replace && replace->type() != SCRIPT_FUNCTION && (bool)*replace;
bool with_replace = replace && replace->type() != SCRIPT_FUNCTION && replace->toBool();
// pick many
ScriptCustomCollectionP ret(new ScriptCustomCollection);
int itemCount = input->itemCount();
......
......@@ -44,7 +44,7 @@ SCRIPT_FUNCTION(new_card) {
} else if (PackageChoiceValue* pvalue = dynamic_cast<PackageChoiceValue*>(value)) {
pvalue->package_name = v->toString();
} else if (ColorValue* cvalue = dynamic_cast<ColorValue*>(value)) {
cvalue->value = (AColor)*v;
cvalue->value = v->toColor();
} else {
throw ScriptError(format_string(_("Can not set value '%s', it is not of the right type"),name));
}
......
......@@ -53,7 +53,7 @@ ScriptRegexP regex_from_script(const ScriptValueP& value) {
ScriptRegexP regex = dynamic_pointer_cast<ScriptRegex>(value);
if (!regex) {
// TODO: introduce some kind of caching?
regex = intrusive(new ScriptRegex(*value));
regex = intrusive(new ScriptRegex(value->toString()));
}
return regex;
}
......
......@@ -37,12 +37,12 @@ inline size_t spelled_correctly(const String& input, size_t start, size_t end, S
if (extra_test) {
// try on untagged
ctx.setVariable(SCRIPT_VAR_input, to_script(word));
if (*extra_test->eval(ctx)) {
if (extra_test->eval(ctx)->toBool()) {
return true;
}
// try on tagged
ctx.setVariable(SCRIPT_VAR_input, to_script(input.substr(start,end-start)));
if (*extra_test->eval(ctx)) {
if (extra_test->eval(ctx)->toBool()) {
return true;
}
}
......
......@@ -21,15 +21,16 @@ DECLARE_TYPEOF_COLLECTION(ScriptParseError);
// ----------------------------------------------------------------------------- : Store
// TODO: reduce duplication, see from_script
void store(const ScriptValueP& val, String& var) { var = val->toString(); }
void store(const ScriptValueP& val, int& var) { var = *val; }
void store(const ScriptValueP& val, double& var) { var = *val; }
void store(const ScriptValueP& val, bool& var) { var = *val; }
void store(const ScriptValueP& val, Color& var) { var = (AColor)*val; }
void store(const ScriptValueP& val, AColor& var) { var = *val; }
void store(const ScriptValueP& val, Defaultable<String>& var) { var.assign(*val); }
void store(const ScriptValueP& val, Defaultable<Color>& var) { var.assign((AColor)*val); }
void store(const ScriptValueP& val, Defaultable<AColor>& var) { var.assign(*val); }
void store(const ScriptValueP& val, int& var) { var = val->toInt(); }
void store(const ScriptValueP& val, double& var) { var = val->toDouble(); }
void store(const ScriptValueP& val, bool& var) { var = val->toBool(); }
void store(const ScriptValueP& val, Color& var) { var = val->toColor(); }
void store(const ScriptValueP& val, AColor& var) { var = val->toColor(); }
void store(const ScriptValueP& val, Defaultable<String>& var) { var.assign(val->toString()); }
void store(const ScriptValueP& val, Defaultable<Color>& var) { var.assign(val->toColor()); }
void store(const ScriptValueP& val, Defaultable<AColor>& var) { var.assign(val->toColor()); }
void store(const ScriptValueP& val, Alignment& var) { var = from_string(val->toString()); }
void store(const ScriptValueP& val, Direction& var) { parse_enum(val->toString(),var); }
......
......@@ -74,11 +74,11 @@ class ScriptDelayedError : public ScriptValue {
// all of these throw
virtual String typeName() const;
virtual operator String() const;
virtual operator double() const;
virtual operator int() const;
virtual operator bool() const;
virtual operator AColor() const;
virtual String toString() const;
virtual double toDouble() const;
virtual int toInt() const;
virtual bool toBool() const;
virtual AColor toColor() const;
virtual int itemCount() const;
virtual CompareWhat compareAs(String&, void const*&) const;
// these can propagate the error
......@@ -273,12 +273,12 @@ class ScriptObject : public ScriptValue {
inline ScriptObject(const T& v) : value(v) {}
virtual ScriptType type() const { ScriptValueP d = getDefault(); return d ? d->type() : SCRIPT_OBJECT; }
virtual String typeName() const { return type_name(*value); }
virtual operator String() const { ScriptValueP d = getDefault(); return d ? *d : ScriptValue::operator String(); }
virtual operator double() const { ScriptValueP d = getDefault(); return d ? *d : ScriptValue::operator double(); }
virtual operator int() const { ScriptValueP d = getDefault(); return d ? *d : ScriptValue::operator int(); }
virtual operator bool() const { ScriptValueP d = getDefault(); return d ? *d : ScriptValue::operator bool(); }
virtual operator AColor() const { ScriptValueP d = getDefault(); return d ? *d : ScriptValue::operator AColor(); }
virtual String toCode() const { ScriptValueP d = getDefault(); return d ? d->toCode() : to_code(*value); }
virtual String toString() const { ScriptValueP d = getDefault(); return d ? d->toString() : ScriptValue::toString(); }
virtual int toInt() const { ScriptValueP d = getDefault(); return d ? d->toInt() : ScriptValue::toInt(); }
virtual double toDouble() const { ScriptValueP d = getDefault(); return d ? d->toDouble() : ScriptValue::toDouble(); }
virtual bool toBool() const { ScriptValueP d = getDefault(); return d ? d->toBool() : ScriptValue::toBool(); }
virtual AColor toColor() const { ScriptValueP d = getDefault(); return d ? d->toColor() : ScriptValue::toColor(); }
virtual String toCode() const { ScriptValueP d = getDefault(); return d ? d->toCode() : to_code(*value); }
virtual GeneratedImageP toImage(const ScriptValueP& thisP) const {
ScriptValueP d = getDefault(); return d ? d->toImage(d) : ScriptValue::toImage(thisP);
}
......@@ -422,13 +422,13 @@ template <typename T> inline T from_script (const ScriptValueP& va
return o->getValue();
}
template <> inline ScriptValueP from_script<ScriptValueP>(const ScriptValueP& value) { return value; }
template <> inline String from_script<String> (const ScriptValueP& value) { return *value; }
template <> inline int from_script<int> (const ScriptValueP& value) { return *value; }
template <> inline double from_script<double> (const ScriptValueP& value) { return *value; }
template <> inline bool from_script<bool> (const ScriptValueP& value) { return *value; }
template <> inline Color from_script<Color> (const ScriptValueP& value) { return (AColor)*value; }
template <> inline AColor from_script<AColor> (const ScriptValueP& value) { return *value; }
template <> inline wxDateTime from_script<wxDateTime> (const ScriptValueP& value) { return *value; }
template <> inline String from_script<String> (const ScriptValueP& value) { return value->toString(); }
template <> inline int from_script<int> (const ScriptValueP& value) { return value->toInt(); }
template <> inline double from_script<double> (const ScriptValueP& value) { return value->toDouble(); }
template <> inline bool from_script<bool> (const ScriptValueP& value) { return value->toBool(); }
template <> inline Color from_script<Color> (const ScriptValueP& value) { return value->toColor(); }
template <> inline AColor from_script<AColor> (const ScriptValueP& value) { return value->toColor(); }
template <> inline wxDateTime from_script<wxDateTime> (const ScriptValueP& value) { return value->toDateTime(); }
// ----------------------------------------------------------------------------- : EOF
#endif
This diff is collapsed.
......@@ -59,28 +59,19 @@ class ScriptValue : public IntrusivePtrBaseWithDelete {
virtual CompareWhat compareAs(String& compare_str, void const*& compare_ptr) const;
/// Convert this value to a string
virtual operator String() const;
virtual String toString() const;
/// Script code to generate this value
virtual String toCode() const;
/// Convert this value to a double
virtual operator double() const;
virtual double toDouble() const;
/// Convert this value to an integer
virtual operator int() const;
virtual int toInt() const;
/// Convert this value to a boolean
virtual operator bool() const;
virtual bool toBool() const;
/// Convert this value to a color
virtual operator AColor() const;
virtual AColor toColor() const;
/// Convert this value to a wxDateTime
virtual operator wxDateTime() const;
/// Script code to generate this value
virtual String toCode() const;
/// Explicit overload to convert to a string
/** This is sometimes necessary, because wxString has an int constructor,
* which confuses gcc. */
inline String toString() const { return *this; }
/// Explicit overload to convert to a wxDateTime
/** Overload resolution is sometimes confused by other conversions */
inline wxDateTime toDateTime() const { return *this; }
virtual wxDateTime toDateTime() const;
/// Convert this value to an image
virtual GeneratedImageP toImage(const ScriptValueP& thisP) const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment