Use make_intrusive/make_shared for smart pointer construction.

This commit is contained in:
Twan van Laarhoven
2020-04-23 23:51:34 +02:00
parent 815df01ba5
commit 708b4389a0
67 changed files with 313 additions and 329 deletions
+7 -7
View File
@@ -100,7 +100,7 @@ SCRIPT_FUNCTION(to_string) {
SCRIPT_RETURN(input->toString());
}
} catch (const ScriptError& e) {
return intrusive(new ScriptDelayedError(e));
return make_intrusive<ScriptDelayedError>(e);
}
}
@@ -715,7 +715,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 intrusive(new ScriptRule(input));
return make_intrusive<ScriptRule>(input);
}
// ----------------------------------------------------------------------------- : Init
@@ -760,17 +760,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"), intrusive(new ScriptRule(script_format)));
ctx.setVariable(_("format_rule"), make_intrusive<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"), intrusive(new ScriptRule(script_sort_text)));
ctx.setVariable(_("sort_rule"), make_intrusive<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"), intrusive(new ScriptRule(script_tag_contents)));
ctx.setVariable(_("tag_remove_rule"), intrusive(new ScriptRule(script_remove_tag)));
ctx.setVariable(_("tag_contents_rule"), make_intrusive<ScriptRule>(script_tag_contents));
ctx.setVariable(_("tag_remove_rule"), make_intrusive<ScriptRule>(script_remove_tag));
// collection
ctx.setVariable(_("position"), script_position_of);
ctx.setVariable(_("length"), script_length);
@@ -782,6 +782,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"), intrusive(new ScriptRule(script_expand_keywords)));
ctx.setVariable(_("expand_keywords_rule"), make_intrusive<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 = intrusive(new Card(*game));
CardP new_card = make_intrusive<Card>(*game);
// set field values
SCRIPT_PARAM(ScriptValueP, input);
ScriptValueP it = input->makeIterator();
+22 -23
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 intrusive(new LinearBlendImage(image1, image2, x1,y1, x2,y2));
return make_intrusive<LinearBlendImage>(image1, image2, x1,y1, x2,y2);
}
SCRIPT_FUNCTION(masked_blend) {
SCRIPT_PARAM(GeneratedImageP, light);
SCRIPT_PARAM(GeneratedImageP, dark);
SCRIPT_PARAM(GeneratedImageP, mask);
return intrusive(new MaskedBlendImage(light, dark, mask));
return make_intrusive<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 intrusive(new CombineBlendImage(image1, image2, image_combine));
return make_intrusive<CombineBlendImage>(image1, image2, image_combine);
}
SCRIPT_FUNCTION(set_mask) {
SCRIPT_PARAM(GeneratedImageP, image);
SCRIPT_PARAM(GeneratedImageP, mask);
return intrusive(new SetMaskImage(image, mask));
return make_intrusive<SetMaskImage>(image, mask);
}
SCRIPT_FUNCTION(set_alpha) {
SCRIPT_PARAM_C(GeneratedImageP, input);
SCRIPT_PARAM(double, alpha);
return intrusive(new SetAlphaImage(input, alpha));
return make_intrusive<SetAlphaImage>(input, alpha);
}
SCRIPT_FUNCTION(set_combine) {
@@ -77,18 +77,18 @@ SCRIPT_FUNCTION(set_combine) {
SCRIPT_PARAM_C(GeneratedImageP, input);
ImageCombine image_combine;
parse_enum(combine, image_combine);
return intrusive(new SetCombineImage(input, image_combine));
return make_intrusive<SetCombineImage>(input, image_combine);
}
SCRIPT_FUNCTION(saturate) {
SCRIPT_PARAM_C(GeneratedImageP, input);
SCRIPT_PARAM(double, amount);
return intrusive(new SaturateImage(input, amount));
return make_intrusive<SaturateImage>(input, amount);
}
SCRIPT_FUNCTION(invert_image) {
SCRIPT_PARAM_C(GeneratedImageP, input);
return intrusive(new InvertImage(input));
return make_intrusive<InvertImage>(input);
}
SCRIPT_FUNCTION(recolor_image) {
@@ -97,17 +97,17 @@ SCRIPT_FUNCTION(recolor_image) {
SCRIPT_PARAM(Color, green);
SCRIPT_PARAM(Color, blue);
SCRIPT_PARAM_DEFAULT(Color, white, *wxWHITE);
return intrusive(new RecolorImage2(input,red,green,blue,white));
return make_intrusive<RecolorImage2>(input,red,green,blue,white);
} else {
SCRIPT_PARAM(Color, color);
return intrusive(new RecolorImage(input,color));
return make_intrusive<RecolorImage>(input,color);
}
}
SCRIPT_FUNCTION(enlarge) {
SCRIPT_PARAM_C(GeneratedImageP, input);
SCRIPT_PARAM(double, border_size);
return intrusive(new EnlargeImage(input, border_size));
return make_intrusive<EnlargeImage>(input, border_size);
}
SCRIPT_FUNCTION(crop) {
@@ -116,23 +116,23 @@ SCRIPT_FUNCTION(crop) {
SCRIPT_PARAM(int, height);
SCRIPT_PARAM(double, offset_x);
SCRIPT_PARAM(double, offset_y);
return intrusive(new CropImage(input, width, height, offset_x, offset_y));
return make_intrusive<CropImage>(input, width, height, offset_x, offset_y);
}
SCRIPT_FUNCTION(flip_horizontal) {
SCRIPT_PARAM_C(GeneratedImageP, input);
return intrusive(new FlipImageHorizontal(input));
return make_intrusive<FlipImageHorizontal>(input);
}
SCRIPT_FUNCTION(flip_vertical) {
SCRIPT_PARAM_C(GeneratedImageP, input);
return intrusive(new FlipImageVertical(input));
return make_intrusive<FlipImageVertical>(input);
}
SCRIPT_FUNCTION(rotate) {
SCRIPT_PARAM_C(GeneratedImageP, input);
SCRIPT_PARAM(Degrees, angle);
return intrusive(new RotateImage(input,deg_to_rad(angle)));
return make_intrusive<RotateImage>(input,deg_to_rad(angle));
}
SCRIPT_FUNCTION(drop_shadow) {
@@ -142,7 +142,7 @@ SCRIPT_FUNCTION(drop_shadow) {
SCRIPT_OPTIONAL_PARAM_(double, alpha);
SCRIPT_OPTIONAL_PARAM_(double, blur_radius);
SCRIPT_OPTIONAL_PARAM_(Color, color);
return intrusive(new DropShadowImage(input, offset_x, offset_y, alpha, blur_radius, color));
return make_intrusive<DropShadowImage>(input, offset_x, offset_y, alpha, blur_radius, color);
}
SCRIPT_FUNCTION(symbol_variation) {
@@ -170,7 +170,7 @@ SCRIPT_FUNCTION(symbol_variation) {
FOR_EACH(v, style->variations) {
if (v->name == variation) {
// found it
return intrusive(new SymbolToImage(value, filename, value->last_update, v));
return make_intrusive<SymbolToImage>(value, filename, value->last_update, v);
}
}
throw ScriptError(_("Variation of symbol not found ('") + variation + _("')"));
@@ -183,7 +183,7 @@ SCRIPT_FUNCTION(symbol_variation) {
if (fill_type == _("solid") || fill_type.empty()) {
SCRIPT_PARAM(Color, fill_color);
SCRIPT_PARAM(Color, border_color);
var->filter = intrusive(new SolidFillSymbolFilter(fill_color, border_color));
var->filter = make_intrusive<SolidFillSymbolFilter>(fill_color, border_color);
} else if (fill_type == _("linear gradient")) {
SCRIPT_PARAM(Color, fill_color_1);
SCRIPT_PARAM(Color, border_color_1);
@@ -193,24 +193,23 @@ SCRIPT_FUNCTION(symbol_variation) {
SCRIPT_PARAM(double, center_y);
SCRIPT_PARAM(double, end_x);
SCRIPT_PARAM(double, 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));
var->filter = make_intrusive<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(Color, fill_color_1);
SCRIPT_PARAM(Color, border_color_1);
SCRIPT_PARAM(Color, fill_color_2);
SCRIPT_PARAM(Color, border_color_2);
var->filter = intrusive(new RadialGradientSymbolFilter(fill_color_1, border_color_1, fill_color_2, border_color_2));
var->filter = make_intrusive<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 intrusive(new SymbolToImage(value, filename, value ? value->last_update : Age(0), var));
return make_intrusive<SymbolToImage>(value, filename, value ? value->last_update : Age(0), var);
}
}
SCRIPT_FUNCTION(built_in_image) {
SCRIPT_PARAM_C(String, input);
return intrusive(new BuiltInImage(input));
return make_intrusive<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 = intrusive(new ScriptRegex(*value));
regex = make_intrusive<ScriptRegex>(*value);
}
return regex;
}
@@ -251,8 +251,8 @@ void init_script_regex_functions(Context& ctx) {
ctx.setVariable(_("split_text"), script_split_text);
ctx.setVariable(_("match_text"), script_match_text);
ctx.setVariable(_("match"), script_match_text); // old name
ctx.setVariable(_("replace_rule"), intrusive(new ScriptRule(script_replace_text)));
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_text)));
ctx.setVariable(_("replace_rule"), make_intrusive<ScriptRule>(script_replace_text));
ctx.setVariable(_("filter_rule"), make_intrusive<ScriptRule>(script_filter_text));
ctx.setVariable(_("break_rule"), make_intrusive<ScriptRule>(script_break_text));
ctx.setVariable(_("match_rule"), make_intrusive<ScriptRule>(script_match_text));
}
+43 -43
View File
@@ -154,25 +154,25 @@ inline Type from_script(const ScriptValueP& v, Variable var) {
#define SCRIPT_RULE_1_C(funname, type1, name1) \
SCRIPT_RULE_1_N(funname, type1, SCRIPT_VAR_ ## name1, name1)
/// Utility for defining a script rule with a single named parameter
#define SCRIPT_RULE_1_N(funname, type1, str1, name1) \
class ScriptRule_##funname: public ScriptValue { \
public: \
inline ScriptRule_##funname(const type1& name1) : name1(name1) {} \
virtual ScriptType type() const { return SCRIPT_FUNCTION; } \
virtual String typeName() const { return _(#funname)_("_rule"); } \
protected: \
virtual ScriptValueP do_eval(Context& ctx, bool) const; \
private: \
type1 name1; \
}; \
SCRIPT_FUNCTION(funname##_rule) { \
SCRIPT_PARAM_N(type1, str1, name1); \
return intrusive(new ScriptRule_##funname(name1)); \
} \
SCRIPT_FUNCTION(funname) { \
SCRIPT_PARAM_N(type1, str1, name1); \
return ScriptRule_##funname(name1).eval(ctx); \
} \
#define SCRIPT_RULE_1_N(funname, type1, str1, name1) \
class ScriptRule_##funname: public ScriptValue { \
public: \
inline ScriptRule_##funname(const type1& name1) : name1(name1) {} \
virtual ScriptType type() const { return SCRIPT_FUNCTION; } \
virtual String typeName() const { return _(#funname)_("_rule"); } \
protected: \
virtual ScriptValueP do_eval(Context& ctx, bool) const; \
private: \
type1 name1; \
}; \
SCRIPT_FUNCTION(funname##_rule) { \
SCRIPT_PARAM_N(type1, str1, name1) \
return make_intrusive<ScriptRule_##funname>(name1); \
} \
SCRIPT_FUNCTION(funname) { \
SCRIPT_PARAM_N(type1, str1, name1); \
return ScriptRule_##funname(name1).eval(ctx); \
} \
ScriptValueP ScriptRule_##funname::do_eval(Context& ctx, bool) const
/// Utility for defining a script rule with two parameters
@@ -194,30 +194,30 @@ inline Type from_script(const ScriptValueP& v, Variable var) {
})
#define SCRIPT_RULE_2_N_AUX(funname, type1, str1, name1, type2, str2, name2, dep, more) \
class ScriptRule_##funname: public ScriptValue { \
public: \
inline ScriptRule_##funname(const type1& name1, const type2& name2) \
: name1(name1), name2(name2) {} \
virtual ScriptType type() const { return SCRIPT_FUNCTION; } \
virtual String typeName() const { return _(#funname)_("_rule"); } \
dep \
protected: \
virtual ScriptValueP do_eval(Context& ctx, bool) const; \
private: \
type1 name1; \
type2 name2; \
}; \
SCRIPT_FUNCTION(funname##_rule) { \
SCRIPT_PARAM_N(type1, str1, name1); \
SCRIPT_PARAM_N(type2, str2, name2); \
return intrusive(new ScriptRule_##funname(name1, name2)); \
} \
SCRIPT_FUNCTION_AUX(funname, dep) { \
SCRIPT_PARAM_N(type1, str1, name1); \
SCRIPT_PARAM_N(type2, str2, name2); \
return ScriptRule_##funname(name1, name2).eval(ctx); \
} \
more \
class ScriptRule_##funname: public ScriptValue { \
public: \
inline ScriptRule_##funname(const type1& name1, const type2& name2) \
: name1(name1), name2(name2) {} \
virtual ScriptType type() const { return SCRIPT_FUNCTION; } \
virtual String typeName() const { return _(#funname)_("_rule"); } \
dep \
protected: \
virtual ScriptValueP do_eval(Context& ctx, bool) const; \
private: \
type1 name1; \
type2 name2; \
}; \
SCRIPT_FUNCTION(funname##_rule) { \
SCRIPT_PARAM_N(type1, str1, name1); \
SCRIPT_PARAM_N(type2, str2, name2); \
return make_intrusive<ScriptRule_##funname>(name1, name2); \
} \
SCRIPT_FUNCTION_AUX(funname, dep) { \
SCRIPT_PARAM_N(type1, str1, name1); \
SCRIPT_PARAM_N(type2, str2, name2); \
return ScriptRule_##funname(name1, name2).eval(ctx); \
} \
more \
ScriptValueP ScriptRule_##funname::do_eval(Context& ctx, bool) const
#define SCRIPT_RULE_2_DEPENDENCIES(name) \