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
+2 -2
View File
@@ -21,7 +21,7 @@ DECLARE_TYPEOF_COLLECTION(KeywordModeP);
AddKeywordAction::AddKeywordAction(Set& set)
: KeywordListAction(set)
, action(ADD, new_intrusive<Keyword>(), set.keywords)
, action(ADD, intrusive(new Keyword()), set.keywords)
{
Keyword& keyword = *action.steps.front().item;
// find default mode
@@ -184,7 +184,7 @@ bool KeywordReminderTextValue::checkScript(const ScriptP& script) {
const KeywordParam& kwp = *keyword.parameters[i];
String param_name = String(_("param")) << (int)(i+1);
String param_value = _("<atom-kwpph>") + (kwp.placeholder.empty() ? kwp.name : kwp.placeholder) + _("</atom-kwpph>");
ctx.setVariable(param_name, new_intrusive4<KeywordParamValue>(kwp.name, _(""), _(""), param_value));
ctx.setVariable(param_name, intrusive(new KeywordParamValue(kwp.name, _(""), _(""), param_value)));
}
script->eval(ctx);
errors.clear();
+1 -1
View File
@@ -23,7 +23,7 @@ DECLARE_TYPEOF_COLLECTION(int);
AddCardAction::AddCardAction(Set& set)
: CardListAction(set)
, action(ADD, new_intrusive1<Card>(*set.game), set.cards)
, action(ADD, intrusive(new Card(*set.game)), set.cards)
{}
AddCardAction::AddCardAction(AddingOrRemoving ar, Set& set, const CardP& card)
+2 -2
View File
@@ -398,7 +398,7 @@ ControlPointRemoveAction::ControlPointRemoveAction(const SymbolShapeP& shape, co
FOR_EACH(point, shape->points) {
if (to_delete.find(point) != to_delete.end()) {
// remove this point
removals.push_back(new_intrusive2<SinglePointRemoveAction>(shape, index));
removals.push_back(intrusive(new SinglePointRemoveAction(shape, index)));
}
++index;
}
@@ -422,7 +422,7 @@ void ControlPointRemoveAction::perform(bool to_undo) {
Action* control_point_remove_action(const SymbolShapeP& shape, const set<ControlPointP>& to_delete) {
if (shape->points.size() - to_delete.size() < 2) {
// TODO : remove part?
//new_intrusive<ControlPointRemoveAllAction>(part);
//intrusive(new ControlPointRemoveAllAction(part));
return 0; // no action
} else {
return new ControlPointRemoveAction(shape, to_delete);
+1 -1
View File
@@ -34,7 +34,7 @@ void AddCardsScript::perform(Set& set, vector<CardP>& out) {
// is this a new card?
if (contains(set.cards,card) || contains(out,card)) {
// make copy
card = new_intrusive1<Card>(*card);
card = intrusive(new Card(*card));
}
out.push_back(card);
}
+9 -9
View File
@@ -74,15 +74,15 @@ intrusive_ptr<Field> read_new<Field>(Reader& reader) {
// there must be a type specified
String type;
reader.handle(_("type"), type);
if (type == _("text")) return new_intrusive<TextField>();
else if (type == _("choice")) return new_intrusive<ChoiceField>();
else if (type == _("multiple choice")) return new_intrusive<MultipleChoiceField>();
else if (type == _("boolean")) return new_intrusive<BooleanField>();
else if (type == _("image")) return new_intrusive<ImageField>();
else if (type == _("symbol")) return new_intrusive<SymbolField>();
else if (type == _("color")) return new_intrusive<ColorField>();
else if (type == _("info")) return new_intrusive<InfoField>();
else if (type == _("package choice")) return new_intrusive<PackageChoiceField>();
if (type == _("text")) return intrusive(new TextField());
else if (type == _("choice")) return intrusive(new ChoiceField());
else if (type == _("multiple choice")) return intrusive(new MultipleChoiceField());
else if (type == _("boolean")) return intrusive(new BooleanField());
else if (type == _("image")) return intrusive(new ImageField());
else if (type == _("symbol")) return intrusive(new SymbolField());
else if (type == _("color")) return intrusive(new ColorField());
else if (type == _("info")) return intrusive(new InfoField());
else if (type == _("package choice")) return intrusive(new PackageChoiceField());
else if (type.empty()) {
reader.warning(_ERROR_1_("expected key", _("type")));
throw ParseError(_ERROR_("aborting parsing"));
+4 -4
View File
@@ -266,17 +266,17 @@ inline String type_name(const Value&) {
#define IMPLEMENT_FIELD_TYPE(Type, NAME) \
StyleP Type ## Field::newStyle(const FieldP& thisP) const { \
assert(thisP.get() == this); \
return new_intrusive1<Type ## Style>(static_pointer_cast<Type ## Field>(thisP));\
return intrusive(new Type ## Style(static_pointer_cast<Type ## Field>(thisP))); \
} \
ValueP Type ## Field::newValue(const FieldP& thisP) const { \
assert(thisP.get() == this); \
return new_intrusive1<Type ## Value>(static_pointer_cast<Type ## Field>(thisP));\
return intrusive(new Type ## Value(static_pointer_cast<Type ## Field>(thisP))); \
} \
StyleP Type ## Style::clone() const { \
return new_intrusive1<Type ## Style>(*this); \
return intrusive(new Type ## Style(*this)); \
} \
ValueP Type ## Value::clone() const { \
return new_intrusive1<Type ## Value>(*this); \
return intrusive(new Type ## Value(*this)); \
} \
String Type ## Field::typeName() const { \
return _(NAME); \
+4 -4
View File
@@ -12,8 +12,8 @@
// ----------------------------------------------------------------------------- : BooleanField
BooleanField::BooleanField() {
choices->choices.push_back(new_intrusive1<Choice>(_("yes")));
choices->choices.push_back(new_intrusive1<Choice>(_("no")));
choices->choices.push_back(intrusive(new Choice(_("yes"))));
choices->choices.push_back(intrusive(new Choice(_("no"))));
choices->initIds();
}
@@ -34,8 +34,8 @@ BooleanStyle::BooleanStyle(const ChoiceFieldP& field)
render_style = RENDER_BOTH;
//choice_images[_("yes")] = ScriptableImage(_("buildin_image(\"bool_yes\")"));
//choice_images[_("no")] = ScriptableImage(_("buildin_image(\"bool_no\")"));
choice_images[_("yes")] = ScriptableImage(new_intrusive1<BuiltInImage>(_("bool_yes")));
choice_images[_("no")] = ScriptableImage(new_intrusive1<BuiltInImage>(_("bool_no")));
choice_images[_("yes")] = ScriptableImage(intrusive(new BuiltInImage(_("bool_yes"))));
choice_images[_("no")] = ScriptableImage(intrusive(new BuiltInImage(_("bool_no"))));
}
IMPLEMENT_REFLECTION(BooleanStyle) {
+1 -1
View File
@@ -48,5 +48,5 @@ void ImageValue::reflect(Writer& tag) {
void ImageValue::reflect(GetMember& tag) {}
void ImageValue::reflect(GetDefaultMember& tag) {
// convert to ScriptImageP for scripting
tag.handle( (ScriptValueP)new_intrusive2<ImageValueToImage>(filename, last_update) );
tag.handle( (ScriptValueP)intrusive(new ImageValueToImage(filename, last_update)) );
}
+2 -2
View File
@@ -538,7 +538,7 @@ void ApprCardDatabase::doRead(wxInputStream& in) {
progress_target->onProgress(0.4f * float(i) / cards.size(),
String(_("reading card ")) << i << _(" of ") << (int)cards.size());
}
card = new_intrusive<ApprCardRecord>();
card = intrusive(new ApprCardRecord());
card->readHead(data);
head_pos = in.TellI();
in.SeekI(card->data_pos);
@@ -753,7 +753,7 @@ bool ApprenticeExportWindow::exportSet() {
cardlist.removeSet(set->apprentice_code);
// add cards from set
FOR_EACH(card, set->cards) {
ApprCardRecordP rec = new_intrusive2<ApprCardRecord>(*card, set->apprentice_code);
ApprCardRecordP rec = intrusive(new ApprCardRecord(*card, set->apprentice_code));
cardlist.cards.push_back(rec);
}
cardlist.write();
+2 -2
View File
@@ -187,10 +187,10 @@ SymbolShapeP read_symbol_shape(const ImageData& data) {
}
// add to shape and place a mark
shape->points.push_back(new_intrusive2<ControlPoint>(
shape->points.push_back(intrusive(new ControlPoint(
double(x) / data.width,
double(y) / data.height
));
)));
if (x > old_x) data(old_x, y) |= MARKED; // mark when moving right -> only mark the top of the shape
last_move = (x + y) - (old_x + old_y);
old_x = x;
+1 -1
View File
@@ -30,7 +30,7 @@ class MSE1FileFormat : public FileFormat {
};
FileFormatP mse1_file_format() {
return new_intrusive<MSE1FileFormat>();
return intrusive(new MSE1FileFormat());
}
// ----------------------------------------------------------------------------- : Importing
+1 -1
View File
@@ -45,5 +45,5 @@ class MSE2FileFormat : public FileFormat {
};
FileFormatP mse2_file_format() {
return new_intrusive<MSE2FileFormat>();
return intrusive(new MSE2FileFormat());
}
+3 -3
View File
@@ -44,7 +44,7 @@ class MtgEditorFileFormat : public FileFormat {
};
FileFormatP mtg_editor_file_format() {
return new_intrusive<MtgEditorFileFormat>();
return intrusive(new MtgEditorFileFormat());
}
// ----------------------------------------------------------------------------- : Importing
@@ -69,7 +69,7 @@ SetP MtgEditorFileFormat::importSet(const String& filename) {
// read file
while (!f.Eof()) {
// read a line
if (!current_card) current_card = new_intrusive1<Card>(*set->game);
if (!current_card) current_card = intrusive(new Card(*set->game));
String line = file.ReadLine();
if (line == _("#SET###########")) { // set.title
target = &set->value<TextValue>(_("title")).value;
@@ -104,7 +104,7 @@ SetP MtgEditorFileFormat::importSet(const String& filename) {
set->cards.push_back(current_card);
}
first = false;
current_card = new_intrusive1<Card>(*set->game);
current_card = intrusive(new Card(*set->game));
target = &current_card->value<TextValue>(_("name")).value;
} else if (line == _("#DATE##########")) { // date
// remember date for generation of illustration filename
+2 -2
View File
@@ -77,7 +77,7 @@ void Game::validate(Version v) {
vector<StatsDimensionP> dims;
FOR_EACH(f, card_fields) {
if (f->show_statistics) {
dims.push_back(new_intrusive1<StatsDimension>(*f));
dims.push_back(intrusive(new StatsDimension(*f)));
}
}
statistics_dimensions.insert(statistics_dimensions.begin(), dims.begin(), dims.end()); // push front
@@ -86,7 +86,7 @@ void Game::validate(Version v) {
{
vector<StatsCategoryP> cats;
FOR_EACH(dim, statistics_dimensions) {
cats.push_back(new_intrusive1<StatsCategory>(dim));
cats.push_back(intrusive(new StatsCategory(dim)));
}
statistics_categories.insert(statistics_categories.begin(), cats.begin(), cats.end()); // push front
}
+9 -9
View File
@@ -105,12 +105,12 @@ void Installer::install(bool local, bool check_dependencies) {
}
PackagedP pack;
wxString fn(wxFileName(p).GetExt());
if (fn == _("mse-game")) pack = new_intrusive<Game>();
else if (fn == _("mse-style")) pack = new_intrusive<StyleSheet>();
else if (fn == _("mse-locale")) pack = new_intrusive<Locale>();
else if (fn == _("mse-include")) pack = new_intrusive<IncludePackage>();
else if (fn == _("mse-symbol-font")) pack = new_intrusive<SymbolFont>();
else if (fn == _("mse-export-template")) pack = new_intrusive<ExportTemplate>();
if (fn == _("mse-game")) pack = intrusive(new Game());
else if (fn == _("mse-style")) pack = intrusive(new StyleSheet());
else if (fn == _("mse-locale")) pack = intrusive(new Locale());
else if (fn == _("mse-include")) pack = intrusive(new IncludePackage());
else if (fn == _("mse-symbol-font")) pack = intrusive(new SymbolFont());
else if (fn == _("mse-export-template")) pack = intrusive(new ExportTemplate());
else {
throw PackageError(_("Unrecognized package type: '") + fn + _("'\nwhile trying to install: ") + p);
}
@@ -186,7 +186,7 @@ void Installer::addPackage(Packaged& package) {
return; // already added
}
}
packages.push_back(new_intrusive1<PackageDescription>(package));
packages.push_back(intrusive(new PackageDescription(package)));
// use this as a filename?
if (prefered_filename.empty()) {
prefered_filename = package.name() + _(".mse-installer");
@@ -387,7 +387,7 @@ void merge(InstallablePackages& list1, const InstallablePackages& list2) {
void merge(InstallablePackages& installed, const DownloadableInstallerP& installer) {
InstallablePackages ips;
FOR_EACH(p, installer->packages) {
ips.push_back(new_intrusive2<InstallablePackage>(p,installer));
ips.push_back(intrusive(new InstallablePackage(p,installer)));
}
sort(ips);
merge(installed, ips);
@@ -625,5 +625,5 @@ InstallablePackageP mse_installable_package() {
mse_description->position_hint = -100;
mse_description->icon = load_resource_image(_("installer_program"));
//mse_description->description = _LABEL_("magic set editor package");
return new_intrusive2<InstallablePackage>(mse_description, mse_version);
return intrusive(new InstallablePackage(mse_description, mse_version));
}
+4 -4
View File
@@ -77,7 +77,7 @@ SubLocaleP find_wildcard(map<String,SubLocaleP>& items, const String& name) {
FOR_EACH_CONST(i, items) {
if (i.second && match_wildcard(i.first, name)) return i.second;
}
return new_intrusive<SubLocale>(); // so we don't search again
return intrusive(new SubLocale()); // so we don't search again
}
SubLocaleP find_wildcard_and_set(map<String,SubLocaleP>& items, const String& name) {
return items[name] = find_wildcard(items, name);
@@ -208,12 +208,12 @@ InputStreamP load_resource_text(const String& name) {
char* data = (char *)::LockResource(hData);
if ( !data ) throw InternalError(String::Format(_("Resource cannot be locked: %s"), name));
int len = ::SizeofResource(wxGetInstance(), hResource);
return new_shared2<wxMemoryInputStream>(data, len);
return shared(new wxMemoryInputStream(data, len));
#else
static String path = wxStandardPaths::Get().GetDataDir() + _("/resource/");
static String local_path = wxStandardPaths::Get().GetUserDataDir() + _("/resource/");
if (wxFileExists(path + name)) return new_shared1<wxFileInputStream>(path + name);
else return new_shared1<wxFileInputStream>(local_path + name);
if (wxFileExists(path + name)) return shared(new wxFileInputStream(path + name));
else return shared(new wxFileInputStream(local_path + name));
#endif
}
+6 -6
View File
@@ -28,13 +28,13 @@ DECLARE_TYPEOF_NO_REV(IndexMap<FieldP COMMA ValueP>);
// ----------------------------------------------------------------------------- : Set
Set::Set()
: vcs (new_intrusive<VCS>())
: vcs (intrusive(new VCS()))
, script_manager(new SetScriptManager(*this))
{}
Set::Set(const GameP& game)
: game(game)
, vcs (new_intrusive<VCS>())
, vcs (intrusive(new VCS()))
, script_manager(new SetScriptManager(*this))
{
data.init(game->set_fields);
@@ -43,7 +43,7 @@ Set::Set(const GameP& game)
Set::Set(const StyleSheetP& stylesheet)
: game(stylesheet->game)
, stylesheet(stylesheet)
, vcs (new_intrusive<VCS>())
, vcs (intrusive(new VCS()))
, script_manager(new SetScriptManager(*this))
{
data.init(game->set_fields);
@@ -163,7 +163,7 @@ void Set::validate(Version file_app_version) {
}
*/ }
// we want at least one card
if (cards.empty()) cards.push_back(new_intrusive1<Card>(*game));
if (cards.empty()) cards.push_back(intrusive(new Card(*game)));
// update scripts
script_manager->updateAll();
}
@@ -231,7 +231,7 @@ void Set::reflect_cards<Writer> (Writer& tag) {
// ----------------------------------------------------------------------------- : Script utilities
ScriptValueP make_iterator(const Set& set) {
return new_intrusive1<ScriptCollectionIterator<vector<CardP> > >(&set.cards);
return intrusive(new ScriptCollectionIterator<vector<CardP> >(&set.cards));
}
void mark_dependency_member(const Set& set, const String& name, const Dependency& dep) {
@@ -276,7 +276,7 @@ int Set::positionOfCard(const CardP& card, const ScriptValueP& order_by, const S
Profiler prof(t, order_by.get(), _("init order cache"));
#endif
// 3. initialize order cache
order = new_intrusive3<OrderCache<CardP> >(cards, values, filter ? &keep : nullptr);
order = intrusive(new OrderCache<CardP>(cards, values, filter ? &keep : nullptr));
}
return order->find(card);
}
+4 -4
View File
@@ -195,7 +195,7 @@ void Settings::addRecentFile(const String& filename) {
GameSettings& Settings::gameSettingsFor(const Game& game) {
GameSettingsP& gs = game_settings[game.name()];
if (!gs) gs = new_intrusive<GameSettings>();
if (!gs) gs = intrusive(new GameSettings);
gs->initDefaults(game);
return *gs;
}
@@ -214,7 +214,7 @@ ColumnSettings& Settings::columnSettingsFor(const Game& game, const Field& field
}
StyleSheetSettings& Settings::stylesheetSettingsFor(const StyleSheet& stylesheet) {
StyleSheetSettingsP& ss = stylesheet_settings[stylesheet.name()];
if (!ss) ss = new_intrusive<StyleSheetSettings>();
if (!ss) ss = intrusive(new StyleSheetSettings);
ss->useDefault(default_stylesheet_settings); // update default settings
return *ss;
}
@@ -286,7 +286,7 @@ void Settings::read() {
String filename = settingsFile();
if (wxFileExists(filename)) {
// settings file not existing is not an error
shared_ptr<wxFileInputStream> file = new_shared1<wxFileInputStream>(filename);
shared_ptr<wxFileInputStream> file = shared(new wxFileInputStream(filename));
if (!file->Ok()) return; // failure is not an error
Reader reader(file, nullptr, filename);
reader.handle_greedy(*this);
@@ -294,6 +294,6 @@ void Settings::read() {
}
void Settings::write() {
Writer writer(new_shared1<wxFileOutputStream>(settingsFile()), app_version);
Writer writer(shared(new wxFileOutputStream(settingsFile())), app_version);
writer.handle(*this);
}
+10 -10
View File
@@ -139,9 +139,9 @@ SymbolPartP read_new<SymbolPart>(Reader& reader) {
// there must be a type specified
String type;
reader.handle(_("type"), type);
if (type == _("shape") || type.empty()) return new_intrusive<SymbolShape>();
else if (type == _("symmetry")) return new_intrusive<SymbolSymmetry>();
else if (type == _("group")) return new_intrusive<SymbolGroup>();
if (type == _("shape") || type.empty()) return intrusive(new SymbolShape);
else if (type == _("symmetry")) return intrusive(new SymbolSymmetry);
else if (type == _("group")) return intrusive(new SymbolGroup);
else {
throw ParseError(_("Unsupported symbol part type: '") + type + _("'"));
}
@@ -200,7 +200,7 @@ SymbolPartP SymbolShape::clone() const {
SymbolShapeP part(new SymbolShape(*this));
// also clone the control points
FOR_EACH(p, part->points) {
p = new_intrusive1<ControlPoint>(*p);
p = intrusive(new ControlPoint(*p));
}
return part;
}
@@ -357,18 +357,18 @@ double Symbol::aspectRatio() const {
// A default symbol part, a square, moved by d
SymbolShapeP default_symbol_part(double d) {
SymbolShapeP part = new_intrusive<SymbolShape>();
part->points.push_back(new_intrusive2<ControlPoint>(d + .2, d + .2));
part->points.push_back(new_intrusive2<ControlPoint>(d + .2, d + .8));
part->points.push_back(new_intrusive2<ControlPoint>(d + .8, d + .8));
part->points.push_back(new_intrusive2<ControlPoint>(d + .8, d + .2));
SymbolShapeP part = intrusive(new SymbolShape);
part->points.push_back(intrusive(new ControlPoint(d + .2, d + .2)));
part->points.push_back(intrusive(new ControlPoint(d + .2, d + .8)));
part->points.push_back(intrusive(new ControlPoint(d + .8, d + .8)));
part->points.push_back(intrusive(new ControlPoint(d + .8, d + .2)));
part->name = _("Square");
return part;
}
// A default symbol, a square
SymbolP default_symbol() {
SymbolP symbol = new_intrusive<Symbol>();
SymbolP symbol = intrusive(new Symbol);
symbol->parts.push_back(default_symbol_part(0));
return symbol;
}
+1 -1
View File
@@ -54,7 +54,7 @@ class AutoReplace : public IntrusivePtrVirtualBase {
String match;
String replace;
inline AutoReplaceP clone() const { return new_intrusive1<AutoReplace>(*this); }
inline AutoReplaceP clone() const { return intrusive(new AutoReplace(*this)); }
DECLARE_REFLECTION();
};