diff --git a/aegisub/src/ass_dialogue.cpp b/aegisub/src/ass_dialogue.cpp index d52833ca0..b9541e0b8 100644 --- a/aegisub/src/ass_dialogue.cpp +++ b/aegisub/src/ass_dialogue.cpp @@ -41,7 +41,6 @@ #include #include "ass_dialogue.h" -#include "ass_override.h" #include "compat.h" #include "subtitle_format.h" #include "utils.h" @@ -226,9 +225,9 @@ std::auto_ptr> AssDialogue::ParseTags() cons Blocks.push_back(block); // Look for \p in block - for (auto tag : block->Tags) { - if (tag->Name == "\\p") - drawingLevel = tag->Params[0].Get(0); + for (auto const& tag : block->Tags) { + if (tag.Name == "\\p") + drawingLevel = tag.Params[0].Get(0); } } @@ -274,9 +273,9 @@ void AssDialogue::StripTag(wxString const& tag_name) { AssDialogueBlockOverride *over = static_cast(&block); wxString temp; - for (auto tag : over->Tags) { - if (tag->Name != tag_name) - temp += *tag; + for (auto const& tag : over->Tags) { + if (tag.Name != tag_name) + temp += tag; } if (!temp.empty()) diff --git a/aegisub/src/ass_dialogue.h b/aegisub/src/ass_dialogue.h index b9cf98fab..c348f1fe3 100644 --- a/aegisub/src/ass_dialogue.h +++ b/aegisub/src/ass_dialogue.h @@ -33,6 +33,7 @@ /// #include "ass_entry.h" +#include "ass_override.h" #include "ass_time.h" #include @@ -105,7 +106,7 @@ public: AssDialogueBlockOverride(wxString const& text = wxString()) : AssDialogueBlock(text) { } ~AssDialogueBlockOverride(); - std::vector Tags; + std::vector Tags; AssBlockType GetType() const override { return BLOCK_OVERRIDE; } wxString GetText() override; diff --git a/aegisub/src/ass_file.cpp b/aegisub/src/ass_file.cpp index 6e59350ab..133eb55dc 100644 --- a/aegisub/src/ass_file.cpp +++ b/aegisub/src/ass_file.cpp @@ -47,7 +47,6 @@ #include "ass_attachment.h" #include "ass_dialogue.h" #include "ass_info.h" -#include "ass_override.h" #include "ass_style.h" #include "compat.h" #include "main.h" diff --git a/aegisub/src/ass_karaoke.cpp b/aegisub/src/ass_karaoke.cpp index 5f633ad07..6683a5da6 100644 --- a/aegisub/src/ass_karaoke.cpp +++ b/aegisub/src/ass_karaoke.cpp @@ -25,7 +25,6 @@ #include "ass_dialogue.h" #include "ass_file.h" -#include "ass_override.h" #include "include/aegisub/context.h" #include "selection_controller.h" @@ -120,8 +119,8 @@ void AssKaraoke::ParseSyllables(AssDialogue *line, Syllable &syl) { } else if (AssDialogueBlockOverride *ovr = dynamic_cast(&block)) { bool in_tag = false; - for (auto tag : ovr->Tags) { - if (tag->IsValid() && tag->Name.Left(2).Lower() == "\\k") { + for (auto& tag : ovr->Tags) { + if (tag.IsValid() && tag.Name.Left(2).Lower() == "\\k") { if (in_tag) { syl.ovr_tags[syl.text.size()] += "}"; in_tag = false; @@ -129,7 +128,7 @@ void AssKaraoke::ParseSyllables(AssDialogue *line, Syllable &syl) { // Dealing with both \K and \kf is mildly annoying so just // convert them both to \kf - if (tag->Name == "\\K") tag->Name = "\\kf"; + if (tag.Name == "\\K") tag.Name = "\\kf"; // Don't bother including zero duration zero length syls if (syl.duration > 0 || !syl.text.empty()) { @@ -138,9 +137,9 @@ void AssKaraoke::ParseSyllables(AssDialogue *line, Syllable &syl) { syl.ovr_tags.clear(); } - syl.tag_type = tag->Name; + syl.tag_type = tag.Name; syl.start_time += syl.duration; - syl.duration = tag->Params[0].Get(0) * 10; + syl.duration = tag.Params[0].Get(0) * 10; } else { wxString& otext = syl.ovr_tags[syl.text.size()]; @@ -151,7 +150,7 @@ void AssKaraoke::ParseSyllables(AssDialogue *line, Syllable &syl) { otext += "{"; in_tag = true; - otext += *tag; + otext += tag; } } diff --git a/aegisub/src/ass_override.cpp b/aegisub/src/ass_override.cpp index dfcda5916..d9c173b1f 100644 --- a/aegisub/src/ass_override.cpp +++ b/aegisub/src/ass_override.cpp @@ -35,10 +35,10 @@ #include "config.h" +#include "ass_dialogue.h" + #include -#include "ass_dialogue.h" -#include "ass_override.h" #include "compat.h" #include "utils.h" @@ -65,6 +65,14 @@ AssOverrideParameter::AssOverrideParameter(AssOverrideParameter&& o) { } +AssOverrideParameter& AssOverrideParameter::operator=(AssOverrideParameter&& rhs) { + value = std::move(rhs.value); + block = std::move(rhs.block); + type = rhs.type; + classification = rhs.classification; + return *this; +} + AssOverrideParameter::~AssOverrideParameter() { } @@ -179,7 +187,6 @@ struct AssOverrideTagProto { void Set(wxString name, VariableDataType type, AssParameterClass classi = PARCLASS_NORMAL, int opt = NOT_OPTIONAL); }; - AssOverrideParamProto::AssOverrideParamProto(VariableDataType type, int opt, AssParameterClass classi) : optional(opt) , type(type) @@ -404,7 +411,6 @@ void parse_parameters(AssOverrideTag *tag, const wxString &text, AssOverrideTagP for (auto& curproto : proto_it->params) { // Create parameter tag->Params.emplace_back(curproto.type, curproto.classification); - AssOverrideParameter *newparam = &tag->Params.back(); // Check if it's optional and not present if (!(curproto.optional & parsFlag) || curPar >= totalPars) @@ -418,11 +424,10 @@ void parse_parameters(AssOverrideTag *tag, const wxString &text, AssOverrideTagP // From ass_dialogue.h AssDialogueBlockOverride::~AssDialogueBlockOverride() { - delete_clear(Tags); } void AssDialogueBlockOverride::ParseTags() { - delete_clear(Tags); + Tags.clear(); wxStringTokenizer tkn(text, "\\", wxTOKEN_STRTOK); wxString curTag; @@ -435,27 +440,28 @@ void AssDialogueBlockOverride::ParseTags() { while (curTag.Freq('(') > curTag.Freq(')') && tkn.HasMoreTokens()) curTag << "\\" << tkn.GetNextToken(); - Tags.push_back(new AssOverrideTag(curTag)); + Tags.emplace_back(curTag); curTag = "\\"; } } + void AssDialogueBlockOverride::AddTag(wxString const& tag) { - Tags.push_back(new AssOverrideTag(tag)); + Tags.emplace_back(tag); } -static wxString tag_str(AssOverrideTag *t) { return *t; } +static wxString tag_str(AssOverrideTag const& t) { return t; } wxString AssDialogueBlockOverride::GetText() { text = "{" + join(Tags | transformed(tag_str), wxString()) + "}"; return text; } void AssDialogueBlockOverride::ProcessParameters(ProcessParametersCallback callback, void *userData) { - for (auto tag : Tags) { - for (auto& par : tag->Params) { + for (auto& tag : Tags) { + for (auto& par : tag.Params) { if (par.omitted) continue; - callback(tag->Name, &par, userData); + callback(tag.Name, &par, userData); // Go recursive if it's a block parameter if (par.GetType() == VARDATA_BLOCK) @@ -465,9 +471,22 @@ void AssDialogueBlockOverride::ProcessParameters(ProcessParametersCallback callb } AssOverrideTag::AssOverrideTag() : valid(false) { } -AssOverrideTag::AssOverrideTag(wxString text) { +AssOverrideTag::AssOverrideTag(wxString const& text) { SetText(text); } +AssOverrideTag::AssOverrideTag(AssOverrideTag&& rhs) +: valid(rhs.valid) +, Name(std::move(rhs.Name)) +, Params(std::move(rhs.Params)) +{ +} + +AssOverrideTag& AssOverrideTag::operator=(AssOverrideTag&& rhs) { + valid = rhs.valid; + Name = std::move(rhs.Name); + Params = std::move(rhs.Params); + return *this; +} void AssOverrideTag::Clear() { Params.clear(); diff --git a/aegisub/src/ass_override.h b/aegisub/src/ass_override.h index faad0f76b..8a1ae0156 100644 --- a/aegisub/src/ass_override.h +++ b/aegisub/src/ass_override.h @@ -70,6 +70,7 @@ class AssOverrideParameter : boost::noncopyable { public: AssOverrideParameter(VariableDataType type, AssParameterClass classification); AssOverrideParameter(AssOverrideParameter&&); + AssOverrideParameter& operator=(AssOverrideParameter&&); ~AssOverrideParameter(); /// Type of parameter @@ -90,12 +91,14 @@ class AssOverrideTag : boost::noncopyable { bool valid; public: + AssOverrideTag(); + AssOverrideTag(AssOverrideTag&&); + AssOverrideTag(wxString const& text); + AssOverrideTag& operator=(AssOverrideTag&&); + wxString Name; std::vector Params; - AssOverrideTag(); - AssOverrideTag(wxString text); - bool IsValid() const { return valid; } void Clear(); void SetText(const wxString &text); diff --git a/aegisub/src/audio_karaoke.cpp b/aegisub/src/audio_karaoke.cpp index cb5995c28..a6674d5c5 100644 --- a/aegisub/src/audio_karaoke.cpp +++ b/aegisub/src/audio_karaoke.cpp @@ -41,7 +41,6 @@ #include "ass_dialogue.h" #include "ass_file.h" #include "ass_karaoke.h" -#include "ass_override.h" #include "audio_box.h" #include "audio_controller.h" #include "audio_timing.h" diff --git a/aegisub/src/auto4_lua_assfile.cpp b/aegisub/src/auto4_lua_assfile.cpp index e0d90af83..6c95b2321 100644 --- a/aegisub/src/auto4_lua_assfile.cpp +++ b/aegisub/src/auto4_lua_assfile.cpp @@ -52,7 +52,6 @@ #include "ass_info.h" #include "ass_file.h" #include "ass_karaoke.h" -#include "ass_override.h" #include "ass_style.h" #include "auto4_lua.h" #include "utils.h" diff --git a/aegisub/src/command/edit.cpp b/aegisub/src/command/edit.cpp index 3f79dd516..1601037e9 100644 --- a/aegisub/src/command/edit.cpp +++ b/aegisub/src/command/edit.cpp @@ -47,7 +47,6 @@ #include "../ass_dialogue.h" #include "../ass_file.h" #include "../ass_karaoke.h" -#include "../ass_override.h" #include "../ass_style.h" #include "../dialog_colorpicker.h" #include "../dialog_paste_over.h" @@ -169,9 +168,9 @@ void paste_lines(agi::Context *c, bool paste_over) { template T get_value(boost::ptr_vector const& blocks, int blockn, T initial, wxString const& tag_name, wxString alt = wxString()) { for (auto ovr : blocks | sliced(0, blockn + 1) | reversed | agi::of_type()) { - for (auto tag : ovr->Tags | reversed) { - if (tag->Name == tag_name || tag->Name == alt) - return tag->Params[0].Get(initial); + for (auto const& tag : ovr->Tags | reversed) { + if (tag.Name == tag_name || tag.Name == alt) + return tag.Params[0].Get(initial); } } return initial; @@ -238,16 +237,15 @@ void set_tag(AssDialogue *line, boost::ptr_vector &blocks, wxS // Remove old of same bool found = false; for (size_t i = 0; i < ovr->Tags.size(); i++) { - wxString name = ovr->Tags[i]->Name; + wxString name = ovr->Tags[i].Name; if (tag == name || alt == name) { - shift -= ((wxString)*ovr->Tags[i]).size(); + shift -= ((wxString)ovr->Tags[i]).size(); if (found) { - delete ovr->Tags[i]; ovr->Tags.erase(ovr->Tags.begin() + i); i--; } else { - ovr->Tags[i]->Params[0].Set(value); + ovr->Tags[i].Params[0].Set(value); found = true; } } diff --git a/aegisub/src/dialog_resample.cpp b/aegisub/src/dialog_resample.cpp index 681fec3e4..59b9fa5b4 100644 --- a/aegisub/src/dialog_resample.cpp +++ b/aegisub/src/dialog_resample.cpp @@ -33,7 +33,6 @@ #include "ass_dialogue.h" #include "ass_file.h" -#include "ass_override.h" #include "ass_style.h" #include "include/aegisub/context.h" #include "help_button.h" diff --git a/aegisub/src/dialog_style_editor.cpp b/aegisub/src/dialog_style_editor.cpp index bad215a15..5a3b9ca5b 100644 --- a/aegisub/src/dialog_style_editor.cpp +++ b/aegisub/src/dialog_style_editor.cpp @@ -44,7 +44,6 @@ #include "ass_dialogue.h" #include "ass_file.h" -#include "ass_override.h" #include "ass_style.h" #include "ass_style_storage.h" #include "colour_button.h" diff --git a/aegisub/src/export_framerate.cpp b/aegisub/src/export_framerate.cpp index c017d8c82..b889a6258 100644 --- a/aegisub/src/export_framerate.cpp +++ b/aegisub/src/export_framerate.cpp @@ -46,7 +46,6 @@ #include "ass_dialogue.h" #include "ass_file.h" -#include "ass_override.h" #include "export_framerate.h" #include "include/aegisub/context.h" #include "utils.h" diff --git a/aegisub/src/font_file_lister.cpp b/aegisub/src/font_file_lister.cpp index b7511b382..50875efa5 100644 --- a/aegisub/src/font_file_lister.cpp +++ b/aegisub/src/font_file_lister.cpp @@ -25,7 +25,6 @@ #include "ass_dialogue.h" #include "ass_file.h" -#include "ass_override.h" #include "ass_style.h" #include "utils.h" @@ -56,23 +55,23 @@ void FontCollector::ProcessDialogueLine(const AssDialogue *line, int index) { for (auto& block : blocks) { if (AssDialogueBlockOverride *ovr = dynamic_cast(&block)) { - for (auto tag : ovr->Tags) { - wxString name = tag->Name; + for (auto const& tag : ovr->Tags) { + wxString name = tag.Name; if (name == "\\r") { - style = styles[tag->Params[0].Get(line->Style)]; + style = styles[tag.Params[0].Get(line->Style)]; overriden = false; } else if (name == "\\b") { - style.bold = tag->Params[0].Get(initial.bold); + style.bold = tag.Params[0].Get(initial.bold); overriden = true; } else if (name == "\\i") { - style.italic = tag->Params[0].Get(initial.italic); + style.italic = tag.Params[0].Get(initial.italic); overriden = true; } else if (name == "\\fn") { - style.facename = tag->Params[0].Get(initial.facename); + style.facename = tag.Params[0].Get(initial.facename); overriden = true; } } diff --git a/aegisub/src/subtitle_format_ebu3264.cpp b/aegisub/src/subtitle_format_ebu3264.cpp index d63565118..1904b884e 100644 --- a/aegisub/src/subtitle_format_ebu3264.cpp +++ b/aegisub/src/subtitle_format_ebu3264.cpp @@ -37,7 +37,6 @@ #include "aegisub_endian.h" #include "ass_dialogue.h" #include "ass_file.h" -#include "ass_override.h" #include "ass_style.h" #include "compat.h" #include "dialog_export_ebu3264.h" @@ -122,16 +121,16 @@ namespace { void ProcessOverrides(AssDialogueBlockOverride *ob, bool &underline, bool &italic, int &align, bool style_underline, bool style_italic) { - for (auto t : ob->Tags) + for (auto const& t : ob->Tags) { - if (t->Name == "\\u") - underline = t->Params[0].Get(style_underline); - else if (t->Name == "\\i") - italic = t->Params[0].Get(style_italic); - else if (t->Name == "\\an") - align = t->Params[0].Get(align); - else if (t->Name == "\\a" && !t->Params[0].omitted) - align = AssStyle::SsaToAss(t->Params[0].Get()); + if (t.Name == "\\u") + underline = t.Params[0].Get(style_underline); + else if (t.Name == "\\i") + italic = t.Params[0].Get(style_italic); + else if (t.Name == "\\an") + align = t.Params[0].Get(align); + else if (t.Name == "\\a" && !t.Params[0].omitted) + align = AssStyle::SsaToAss(t.Params[0].Get()); } } diff --git a/aegisub/src/subtitle_format_srt.cpp b/aegisub/src/subtitle_format_srt.cpp index ca4c18929..5f48f6e76 100644 --- a/aegisub/src/subtitle_format_srt.cpp +++ b/aegisub/src/subtitle_format_srt.cpp @@ -39,7 +39,6 @@ #include "ass_attachment.h" #include "ass_dialogue.h" #include "ass_file.h" -#include "ass_override.h" #include "ass_style.h" #include "colorspace.h" #include "compat.h" @@ -535,8 +534,8 @@ bool SRTSubtitleFormat::CanSave(const AssFile *file) const { boost::ptr_vector blocks(curdiag->ParseTags()); for (auto ovr : blocks | agi::of_type()) { // Verify that all overrides used are supported - for (auto tag : ovr->Tags) { - if (!std::binary_search(supported_tags, std::end(supported_tags), tag->Name)) + for (auto const& tag : ovr->Tags) { + if (!std::binary_search(supported_tags, std::end(supported_tags), tag.Name)) return false; } } @@ -559,11 +558,11 @@ wxString SRTSubtitleFormat::ConvertTags(const AssDialogue *diag) const { for (auto& block : blocks) { if (AssDialogueBlockOverride* ovr = dynamic_cast(&block)) { // Iterate through overrides - for (auto tag : ovr->Tags) { - if (tag->IsValid() && tag->Name.size() == 2) { - auto it = tag_states.find(tag->Name[1]); + for (auto const& tag : ovr->Tags) { + if (tag.IsValid() && tag.Name.size() == 2) { + auto it = tag_states.find(tag.Name[1]); if (it != tag_states.end()) { - bool temp = tag->Params[0].Get(false); + bool temp = tag.Params[0].Get(false); if (temp && !it->second) final += wxString::Format("<%c>", it->first); if (!temp && it->second) diff --git a/aegisub/src/visual_tool.cpp b/aegisub/src/visual_tool.cpp index 2058f3362..322dae3f6 100644 --- a/aegisub/src/visual_tool.cpp +++ b/aegisub/src/visual_tool.cpp @@ -26,7 +26,6 @@ #include "ass_dialogue.h" #include "ass_file.h" -#include "ass_override.h" #include "ass_style.h" #include "ass_time.h" #include "include/aegisub/context.h" @@ -360,9 +359,9 @@ typedef const std::vector * param_vec; // Find a tag's parameters in a line or return nullptr if it's not found static param_vec find_tag(boost::ptr_vector& blocks, wxString tag_name) { for (auto ovr : blocks | agi::of_type()) { - for (auto tag : ovr->Tags) { - if (tag->Name == tag_name) - return &tag->Params; + for (auto const& tag : ovr->Tags) { + if (tag.Name == tag_name) + return &tag.Params; } } @@ -566,9 +565,8 @@ void VisualToolBase::SetOverride(AssDialogue* line, wxString const& tag, wxStrin else if (AssDialogueBlockOverride *ovr = dynamic_cast(block)) { // Remove old of same for (size_t i = 0; i < ovr->Tags.size(); i++) { - wxString const& name = ovr->Tags[i]->Name; + wxString const& name = ovr->Tags[i].Name; if (tag == name || removeTag == name) { - delete ovr->Tags[i]; ovr->Tags.erase(ovr->Tags.begin() + i); i--; }