mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 21:06:59 -04:00
Clean up pointer use:
* Use unique_ptr for Actions instead of manual memory management * Use unique_ptr in KeywordDatabase * Use unique_ptr instead of shared_ptr for file formats * Don't pass shared_ptr to Reader/Writer, use references instead Also * Switch to C++17 so we can use map::try_emplace
This commit is contained in:
@@ -58,8 +58,8 @@ bool DataEditor::viewerIsCurrent(const ValueViewer* viewer) const {
|
||||
}
|
||||
|
||||
|
||||
void DataEditor::addAction(Action* action) {
|
||||
set->actions.addAction(action);
|
||||
void DataEditor::addAction(unique_ptr<Action> action) {
|
||||
set->actions.addAction(move(action));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Selection
|
||||
|
||||
@@ -27,7 +27,7 @@ class DataEditor : public CardViewer {
|
||||
virtual DrawWhat drawWhat(const ValueViewer*) const;
|
||||
virtual bool viewerIsCurrent(const ValueViewer*) const;
|
||||
|
||||
virtual void addAction(Action* action);
|
||||
virtual void addAction(unique_ptr<Action> action);
|
||||
inline SetP getSetForActions() { return set; }
|
||||
|
||||
// --------------------------------------------------- : Selection
|
||||
|
||||
@@ -179,7 +179,7 @@ bool CardListBase::doPaste() {
|
||||
ok = data.getCards(set, new_cards);
|
||||
if (!ok) return false;
|
||||
// add card to set
|
||||
set->actions.addAction(new AddCardAction(ADD, *set, new_cards));
|
||||
set->actions.addAction(make_unique<AddCardAction>(ADD, *set, new_cards));
|
||||
return true;
|
||||
}
|
||||
bool CardListBase::doDelete() {
|
||||
@@ -188,7 +188,7 @@ bool CardListBase::doDelete() {
|
||||
getSelection(cards_to_delete);
|
||||
if (cards_to_delete.empty()) return false;
|
||||
// delete cards
|
||||
set->actions.addAction(new AddCardAction(REMOVE, *set, cards_to_delete));
|
||||
set->actions.addAction(make_unique<AddCardAction>(REMOVE, *set, cards_to_delete));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -378,7 +378,7 @@ void CardListBase::onDrag(wxMouseEvent& ev) {
|
||||
findSelectedItemPos();
|
||||
if (item != selected_item_pos) {
|
||||
// move card in the set
|
||||
set->actions.addAction(new ReorderCardsAction(*set, item, selected_item_pos));
|
||||
set->actions.addAction(make_unique<ReorderCardsAction>(*set, item, selected_item_pos));
|
||||
}
|
||||
ev.Skip(false);
|
||||
}
|
||||
|
||||
@@ -132,14 +132,14 @@ bool KeywordList::doPaste() {
|
||||
// add keyword to set
|
||||
KeywordP keyword = data.getKeyword(set);
|
||||
if (keyword) {
|
||||
set->actions.addAction(new AddKeywordAction(ADD, *set, keyword));
|
||||
set->actions.addAction(make_unique<AddKeywordAction>(ADD, *set, keyword));
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool KeywordList::doDelete() {
|
||||
set->actions.addAction(new AddKeywordAction(REMOVE, *set, getKeyword()));
|
||||
set->actions.addAction(make_unique<AddKeywordAction>(REMOVE, *set, getKeyword()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ void PackageList::showData(const String& pattern) {
|
||||
FOR_EACH(p, matching) {
|
||||
// open image
|
||||
PROFILER(_("load package image"));
|
||||
InputStreamP stream = p->openIconFile();
|
||||
auto stream = p->openIconFile();
|
||||
Image img;
|
||||
Bitmap bmp;
|
||||
if (stream && image_load_file(img, *stream)) {
|
||||
|
||||
Reference in New Issue
Block a user