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
+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 = intrusive(new ApprCardRecord());
card = make_intrusive<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 = intrusive(new ApprCardRecord(*card, set->apprentice_code));
ApprCardRecordP rec = make_intrusive<ApprCardRecord>(*card, set->apprentice_code);
cardlist.cards.push_back(rec);
}
cardlist.write();
+3 -6
View File
@@ -10,9 +10,6 @@
#include <data/format/formats.hpp>
#include <data/set.hpp>
DECLARE_POINTER_TYPE(FileFormat);
DECLARE_TYPEOF_COLLECTION(FileFormatP);
// ----------------------------------------------------------------------------- : Formats
// All supported file formats
@@ -49,11 +46,11 @@ String export_formats(const Game& game) {
}
void export_set(Set& set, const String& filename, size_t format_index, bool is_copy) {
FileFormatP format = file_formats.at(format_index);
if (!format->canExport(*set.game)) {
FileFormat& format = *file_formats.at(format_index);
if (!format.canExport(*set.game)) {
throw InternalError(_("File format doesn't apply to set"));
}
format->exportSet(set, filename, is_copy);
format.exportSet(set, filename, is_copy);
}
SetP import_set(String name) {
+2 -1
View File
@@ -16,7 +16,6 @@
class Game;
DECLARE_POINTER_TYPE(Set);
DECLARE_POINTER_TYPE(Card);
DECLARE_POINTER_TYPE(FileFormat);
// ----------------------------------------------------------------------------- : FileFormat
@@ -47,6 +46,8 @@ class FileFormat : public IntrusivePtrVirtualBase {
}
};
using FileFormatP = unique_ptr<FileFormat>;
// ----------------------------------------------------------------------------- : Formats
/// Initialize the list of file formats
+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(intrusive(new ControlPoint(
shape->points.push_back(make_intrusive<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 intrusive(new MSE1FileFormat());
return make_unique<MSE1FileFormat>();
}
// ----------------------------------------------------------------------------- : Importing
+1 -1
View File
@@ -45,5 +45,5 @@ class MSE2FileFormat : public FileFormat {
};
FileFormatP mse2_file_format() {
return intrusive(new MSE2FileFormat());
return make_unique<MSE2FileFormat>();
}
+3 -3
View File
@@ -44,7 +44,7 @@ class MtgEditorFileFormat : public FileFormat {
};
FileFormatP mtg_editor_file_format() {
return intrusive(new MtgEditorFileFormat());
return make_unique<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 = intrusive(new Card(*set->game));
if (!current_card) current_card = make_intrusive<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 = intrusive(new Card(*set->game));
current_card = make_intrusive<Card>(*set->game);
target = &current_card->value<TextValue>(_("name")).value;
} else if (line == _("#DATE##########")) { // date
// remember date for generation of illustration filename