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:
Twan van Laarhoven
2020-04-25 21:30:05 +02:00
parent 708b4389a0
commit 64ea1d7322
57 changed files with 363 additions and 385 deletions
+2 -2
View File
@@ -12,9 +12,9 @@
// ----------------------------------------------------------------------------- : ValueEditor
void ValueEditor::addAction(ValueAction* a) {
void ValueEditor::addAction(unique_ptr<ValueAction> a) {
if (a) {
a->isOnCard(editor().getCard().get());
editor().addAction(a);
editor().addAction(move(a));
}
}
+1 -1
View File
@@ -130,7 +130,7 @@ class ValueEditor {
virtual DataEditor& editor() const = 0;
/// Perform an action
void addAction(ValueAction* a);
void addAction(unique_ptr<ValueAction> a);
};
// ----------------------------------------------------------------------------- : Utility
+1 -1
View File
@@ -65,7 +65,7 @@ bool ImageValueEditor::canPaste() const {
bool ImageValueEditor::doCopy() {
// load image
InputStreamP image_file = getLocalPackage().openIn(value().filename);
auto image_file = getLocalPackage().openIn(value().filename);
Image image;
if (!image_load_file(image, *image_file)) return false;
// set data
+3 -3
View File
@@ -856,7 +856,7 @@ void TextValueEditor::doFormat(int type) {
break;
}
case ID_FORMAT_REMINDER: {
addAction(new TextToggleReminderAction(valueP(), selection_start_i));
addAction(make_unique<TextToggleReminderAction>(valueP(), selection_start_i));
break;
}
}
@@ -983,7 +983,7 @@ void TextValueEditor::replaceSelection(const String& replacement, const String&
fixSelection();
// execute the action before adding it to the stack,
// because we want to run scripts before action listeners see the action
TextValueAction* action = typing_action(valueP(), selection_start_i, selection_end_i, select_on_undo ? selection_start : selection_end, selection_end, replacement, name);
auto action = typing_action(valueP(), selection_start_i, selection_end_i, select_on_undo ? selection_start : selection_end, selection_end, replacement, name);
if (!action) {
// nothing changes, but move the selection anyway
moveSelection(TYPE_CURSOR, selection_end);
@@ -994,7 +994,7 @@ void TextValueEditor::replaceSelection(const String& replacement, const String&
size_t expected_cursor = min(selection_start, selection_end) + untag_for_cursor(replacement).size();
// perform the action
// NOTE: this calls our onAction, invalidating the text viewer and moving the selection around the new text
addAction(action);
addAction(std::move(action));
// move cursor
{
String real_value = untag_for_cursor(value().value());