Instead of the new_intrusive<T>() functions, use intrusive(new T)

This means we no longer need 8 different functions for different numbers of arguments, and non-const references can now also be passed to constructors without problems.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1443 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2010-07-21 14:32:28 +00:00
parent 8800500d86
commit 51dfed69b4
66 changed files with 304 additions and 353 deletions
+7 -7
View File
@@ -91,7 +91,7 @@ SCRIPT_FUNCTION(to_string) {
SCRIPT_RETURN(input->toString());
}
} catch (const ScriptError& e) {
return new_intrusive1<ScriptDelayedError>(e);
return intrusive(new ScriptDelayedError(e));
}
}
@@ -649,7 +649,7 @@ SCRIPT_FUNCTION(keyword_usage) {
/// Turn a script function into a rule, a.k.a. a delayed closure
SCRIPT_FUNCTION(rule) {
SCRIPT_PARAM(ScriptValueP, input);
return new_intrusive1<ScriptRule>(input);
return intrusive(new ScriptRule(input));
}
// ----------------------------------------------------------------------------- : Init
@@ -680,17 +680,17 @@ void init_script_basic_functions(Context& ctx) {
ctx.setVariable(_("substring"), script_substring);
ctx.setVariable(_("contains"), script_contains);
ctx.setVariable(_("format"), script_format);
ctx.setVariable(_("format rule"), new_intrusive1<ScriptRule>(script_format));
ctx.setVariable(_("format rule"), intrusive(new ScriptRule(script_format)));
ctx.setVariable(_("curly quotes"), script_curly_quotes);
ctx.setVariable(_("regex escape"), script_regex_escape);
ctx.setVariable(_("sort text"), script_sort_text);
ctx.setVariable(_("sort rule"), new_intrusive1<ScriptRule>(script_sort_text));
ctx.setVariable(_("sort rule"), intrusive(new ScriptRule(script_sort_text)));
// tagged string
ctx.setVariable(_("tag contents"), script_tag_contents);
ctx.setVariable(_("remove tag"), script_remove_tag);
ctx.setVariable(_("remove tags"), script_remove_tags);
ctx.setVariable(_("tag contents rule"), new_intrusive1<ScriptRule>(script_tag_contents));
ctx.setVariable(_("tag remove rule"), new_intrusive1<ScriptRule>(script_remove_tag));
ctx.setVariable(_("tag contents rule"), intrusive(new ScriptRule(script_tag_contents)));
ctx.setVariable(_("tag remove rule"), intrusive(new ScriptRule(script_remove_tag)));
// collection
ctx.setVariable(_("position"), script_position_of);
ctx.setVariable(_("length"), script_length);
@@ -702,6 +702,6 @@ void init_script_basic_functions(Context& ctx) {
ctx.setVariable(_("random select many"), script_random_select_many);
// keyword
ctx.setVariable(_("expand keywords"), script_expand_keywords);
ctx.setVariable(_("expand keywords rule"), new_intrusive1<ScriptRule>(script_expand_keywords));
ctx.setVariable(_("expand keywords rule"), intrusive(new ScriptRule(script_expand_keywords)));
ctx.setVariable(_("keyword usage"), script_keyword_usage);
}
+1 -1
View File
@@ -22,7 +22,7 @@
SCRIPT_FUNCTION(new_card) {
SCRIPT_PARAM(GameP, game);
CardP new_card = new_intrusive1<Card>(*game);
CardP new_card = intrusive(new Card(*game));
// set field values
SCRIPT_PARAM(ScriptValueP, input);
ScriptValueP it = input->makeIterator(input);
+17 -17
View File
@@ -41,14 +41,14 @@ SCRIPT_FUNCTION(linear_blend) {
SCRIPT_PARAM(GeneratedImageP, image2);
SCRIPT_PARAM(double, x1); SCRIPT_PARAM(double, y1);
SCRIPT_PARAM(double, x2); SCRIPT_PARAM(double, y2);
return new_intrusive6<LinearBlendImage>(image1, image2, x1,y1, x2,y2);
return intrusive(new LinearBlendImage(image1, image2, x1,y1, x2,y2));
}
SCRIPT_FUNCTION(masked_blend) {
SCRIPT_PARAM(GeneratedImageP, light);
SCRIPT_PARAM(GeneratedImageP, dark);
SCRIPT_PARAM(GeneratedImageP, mask);
return new_intrusive3<MaskedBlendImage>(light, dark, mask);
return intrusive(new MaskedBlendImage(light, dark, mask));
}
SCRIPT_FUNCTION(combine_blend) {
@@ -57,19 +57,19 @@ SCRIPT_FUNCTION(combine_blend) {
SCRIPT_PARAM(GeneratedImageP, image2);
ImageCombine image_combine;
parse_enum(combine, image_combine);
return new_intrusive3<CombineBlendImage>(image1, image2, image_combine);
return intrusive(new CombineBlendImage(image1, image2, image_combine));
}
SCRIPT_FUNCTION(set_mask) {
SCRIPT_PARAM(GeneratedImageP, image);
SCRIPT_PARAM(GeneratedImageP, mask);
return new_intrusive2<SetMaskImage>(image, mask);
return intrusive(new SetMaskImage(image, mask));
}
SCRIPT_FUNCTION(set_alpha) {
SCRIPT_PARAM_C(GeneratedImageP, input);
SCRIPT_PARAM(double, alpha);
return new_intrusive2<SetAlphaImage>(input, alpha);
return intrusive(new SetAlphaImage(input, alpha));
}
SCRIPT_FUNCTION(set_combine) {
@@ -77,19 +77,19 @@ SCRIPT_FUNCTION(set_combine) {
SCRIPT_PARAM_C(GeneratedImageP, input);
ImageCombine image_combine;
parse_enum(combine, image_combine);
return new_intrusive2<SetCombineImage>(input, image_combine);
return intrusive(new SetCombineImage(input, image_combine));
}
SCRIPT_FUNCTION(saturate) {
SCRIPT_PARAM_C(GeneratedImageP, input);
SCRIPT_PARAM(double, amount);
return new_intrusive2<SaturateImage>(input, amount);
return intrusive(new SaturateImage(input, amount));
}
SCRIPT_FUNCTION(enlarge) {
SCRIPT_PARAM_C(GeneratedImageP, input);
SCRIPT_PARAM_N(double, _("border size"), border_size);
return new_intrusive2<EnlargeImage>(input, border_size);
return intrusive(new EnlargeImage(input, border_size));
}
SCRIPT_FUNCTION(crop) {
@@ -98,7 +98,7 @@ SCRIPT_FUNCTION(crop) {
SCRIPT_PARAM_N(int, _("height"), height);
SCRIPT_PARAM_N(double, _("offset x"), offset_x);
SCRIPT_PARAM_N(double, _("offset y"), offset_y);
return new_intrusive5<CropImage>(input, width, height, offset_x, offset_y);
return intrusive(new CropImage(input, width, height, offset_x, offset_y));
}
SCRIPT_FUNCTION(drop_shadow) {
@@ -108,7 +108,7 @@ SCRIPT_FUNCTION(drop_shadow) {
SCRIPT_OPTIONAL_PARAM_N_(double, _("alpha"), alpha);
SCRIPT_OPTIONAL_PARAM_N_(double, _("blur radius"), blur_radius);
SCRIPT_OPTIONAL_PARAM_N_(Color, _("color"), color);
return new_intrusive6<DropShadowImage>(input, offset_x, offset_y, alpha, blur_radius, color);
return intrusive(new DropShadowImage(input, offset_x, offset_y, alpha, blur_radius, color));
}
SCRIPT_FUNCTION(symbol_variation) {
@@ -136,7 +136,7 @@ SCRIPT_FUNCTION(symbol_variation) {
FOR_EACH(v, style->variations) {
if (v->name == variation) {
// found it
return new_intrusive4<SymbolToImage>(value, filename, value->last_update, v);
return intrusive(new SymbolToImage(value, filename, value->last_update, v));
}
}
throw ScriptError(_("Variation of symbol not found ('") + variation + _("')"));
@@ -149,7 +149,7 @@ SCRIPT_FUNCTION(symbol_variation) {
if (fill_type == _("solid") || fill_type.empty()) {
SCRIPT_PARAM_N(Color, _("fill color"), fill_color);
SCRIPT_PARAM_N(Color, _("border color"), border_color);
var->filter = new_intrusive2<SolidFillSymbolFilter>(fill_color, border_color);
var->filter = intrusive(new SolidFillSymbolFilter(fill_color, border_color));
} else if (fill_type == _("linear gradient")) {
SCRIPT_PARAM_N(Color, _("fill color 1"), fill_color_1);
SCRIPT_PARAM_N(Color, _("border color 1"), border_color_1);
@@ -159,24 +159,24 @@ SCRIPT_FUNCTION(symbol_variation) {
SCRIPT_PARAM_N(double, _("center y"), center_y);
SCRIPT_PARAM_N(double, _("end x"), end_x);
SCRIPT_PARAM_N(double, _("end y"), end_y);
var->filter = new_intrusive8<LinearGradientSymbolFilter>(fill_color_1, border_color_1, fill_color_2, border_color_2
,center_x, center_y, end_x, end_y);
var->filter = intrusive(new LinearGradientSymbolFilter(fill_color_1, border_color_1, fill_color_2, border_color_2
,center_x, center_y, end_x, end_y));
} else if (fill_type == _("radial gradient")) {
SCRIPT_PARAM_N(Color, _("fill color 1"), fill_color_1);
SCRIPT_PARAM_N(Color, _("border color 1"), border_color_1);
SCRIPT_PARAM_N(Color, _("fill color 2"), fill_color_2);
SCRIPT_PARAM_N(Color, _("border color 2"), border_color_2);
var->filter = new_intrusive4<RadialGradientSymbolFilter>(fill_color_1, border_color_1, fill_color_2, border_color_2);
var->filter = intrusive(new RadialGradientSymbolFilter(fill_color_1, border_color_1, fill_color_2, border_color_2));
} else {
throw ScriptError(_("Unknown fill type for symbol_variation: ") + fill_type);
}
return new_intrusive4<SymbolToImage>(value, filename, value ? value->last_update : Age(0), var);
return intrusive(new SymbolToImage(value, filename, value ? value->last_update : Age(0), var));
}
}
SCRIPT_FUNCTION(built_in_image) {
SCRIPT_PARAM_C(String, input);
return new_intrusive1<BuiltInImage>(input);
return intrusive(new BuiltInImage(input));
}
// ----------------------------------------------------------------------------- : Init
+5 -5
View File
@@ -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 = new_intrusive1<ScriptRegex>(*value);
regex = intrusive(new ScriptRegex(*value));
}
return regex;
}
@@ -250,8 +250,8 @@ void init_script_regex_functions(Context& ctx) {
ctx.setVariable(_("break text"), script_break_text);
ctx.setVariable(_("split text"), script_split_text);
ctx.setVariable(_("match"), script_match);
ctx.setVariable(_("replace rule"), new_intrusive1<ScriptRule>(script_replace));
ctx.setVariable(_("filter rule"), new_intrusive1<ScriptRule>(script_filter_text));
ctx.setVariable(_("break rule"), new_intrusive1<ScriptRule>(script_break_text));
ctx.setVariable(_("match rule"), new_intrusive1<ScriptRule>(script_match));
ctx.setVariable(_("replace rule"), intrusive(new ScriptRule(script_replace)));
ctx.setVariable(_("filter rule"), intrusive(new ScriptRule(script_filter_text)));
ctx.setVariable(_("break rule"), intrusive(new ScriptRule(script_break_text)));
ctx.setVariable(_("match rule"), intrusive(new ScriptRule(script_match)));
}
+2 -2
View File
@@ -167,7 +167,7 @@ inline Type from_script(const ScriptValueP& v, Variable var) {
}; \
SCRIPT_FUNCTION(funname##_rule) { \
SCRIPT_PARAM_N(type1, str1, name1); \
return new_intrusive1<ScriptRule_##funname>(name1); \
return intrusive(new ScriptRule_##funname(name1)); \
} \
SCRIPT_FUNCTION(funname) { \
SCRIPT_PARAM_N(type1, str1, name1); \
@@ -210,7 +210,7 @@ inline Type from_script(const ScriptValueP& v, Variable var) {
SCRIPT_FUNCTION(funname##_rule) { \
SCRIPT_PARAM_N(type1, str1, name1); \
SCRIPT_PARAM_N(type2, str2, name2); \
return new_intrusive2<ScriptRule_##funname>(name1, name2); \
return intrusive(new ScriptRule_##funname(name1, name2)); \
} \
SCRIPT_FUNCTION_AUX(funname, dep) { \
SCRIPT_PARAM_N(type1, str1, name1); \