From a7d54f3d69797ac40e2bd1273610243311293e9c Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Wed, 1 Feb 2012 00:47:38 +0000 Subject: [PATCH] Make AssEntry::group const as it really should never change Originally committed to SVN as r6408. --- aegisub/src/ass_attachment.cpp | 8 +++--- aegisub/src/ass_attachment.h | 2 +- aegisub/src/ass_entry.cpp | 4 +-- aegisub/src/ass_entry.h | 4 +-- aegisub/src/ass_file.cpp | 24 +++++++--------- aegisub/src/ass_style.cpp | 41 ++++++++++++++++++++++++---- aegisub/src/ass_style.h | 3 +- aegisub/src/auto4_lua_assfile.cpp | 18 ++++-------- aegisub/src/dialog_attachments.cpp | 3 +- aegisub/src/subtitle_format_srt.cpp | 3 -- aegisub/src/subtitle_format_ttxt.cpp | 3 -- 11 files changed, 63 insertions(+), 50 deletions(-) diff --git a/aegisub/src/ass_attachment.cpp b/aegisub/src/ass_attachment.cpp index 9f7d77e1b..acacc4430 100644 --- a/aegisub/src/ass_attachment.cpp +++ b/aegisub/src/ass_attachment.cpp @@ -49,8 +49,9 @@ #include #include -AssAttachment::AssAttachment(wxString name) -: data(new std::vector) +AssAttachment::AssAttachment(wxString const& name, wxString const& group) +: AssEntry(wxString(), group) +, data(new std::vector) , filename(name) { wxFileName fname(filename); @@ -60,9 +61,8 @@ AssAttachment::AssAttachment(wxString name) } AssEntry *AssAttachment::Clone() const { - AssAttachment *clone = new AssAttachment(filename); + AssAttachment *clone = new AssAttachment(filename, group); clone->data = data; - clone->group = group; return clone; } diff --git a/aegisub/src/ass_attachment.h b/aegisub/src/ass_attachment.h index 4fcb670a3..afe09b1dd 100644 --- a/aegisub/src/ass_attachment.h +++ b/aegisub/src/ass_attachment.h @@ -79,5 +79,5 @@ public: ASS_EntryType GetType() const { return ENTRY_ATTACHMENT; } AssEntry *Clone() const; - AssAttachment(wxString name); + AssAttachment(wxString const& name, wxString const& group); }; diff --git a/aegisub/src/ass_entry.cpp b/aegisub/src/ass_entry.cpp index adb4688f3..f13accdf0 100644 --- a/aegisub/src/ass_entry.cpp +++ b/aegisub/src/ass_entry.cpp @@ -52,7 +52,5 @@ wxString AssEntry::GetSSAText() const { } AssEntry *AssEntry::Clone() const { - AssEntry *final = new AssEntry(data); - final->group = group; - return final; + return new AssEntry(data, group); } diff --git a/aegisub/src/ass_entry.h b/aegisub/src/ass_entry.h index 07b589d82..e66779e3d 100644 --- a/aegisub/src/ass_entry.h +++ b/aegisub/src/ass_entry.h @@ -80,9 +80,9 @@ class AssEntry { public: /// Group it belongs to, e.g. "[Events]" - wxString group; + const wxString group; - AssEntry(wxString const& data = wxString(), wxString const& group = wxString()) : data(data), group(group) { } + AssEntry(wxString const& data, wxString const& group) : data(data), group(group) { } virtual ~AssEntry() { } /// Create a copy of this entry diff --git a/aegisub/src/ass_file.cpp b/aegisub/src/ass_file.cpp index 27e8643aa..f5f18170a 100644 --- a/aegisub/src/ass_file.cpp +++ b/aegisub/src/ass_file.cpp @@ -329,8 +329,7 @@ void AssFile::AddLine(wxString data, int *version, AssAttachment **attach) { // Attachment if (lowGroup == "[fonts]" || lowGroup == "[graphics]") { if (isFilename) { - *attach = new AssAttachment(data.Mid(10)); - (*attach)->group = group; + *attach = new AssAttachment(data.Mid(10), group); } } // Dialogue @@ -479,16 +478,16 @@ void AssFile::InsertAttachment(AssAttachment *attach) { Line.push_back(attach); } -void AssFile::InsertAttachment (wxString filename) { - std::auto_ptr newAttach(new AssAttachment(wxFileName(filename).GetFullName())); - newAttach->Import(filename); +void AssFile::InsertAttachment(wxString filename) { + wxString group("[Graphics]"); - // Insert wxString ext = filename.Right(4).Lower(); if (ext == ".ttf" || ext == ".ttc" || ext == ".pfb") - newAttach->group = "[Fonts]"; - else - newAttach->group = "[Graphics]"; + group = "[Fonts]"; + + std::auto_ptr newAttach(new AssAttachment(wxFileName(filename).GetFullName(), group)); + newAttach->Import(filename); + InsertAttachment(newAttach.release()); } @@ -540,11 +539,8 @@ void AssFile::SetScriptInfo(wxString const& key, wxString const& value) { script_info_end = cur; } else if (found_script_info) { - if (value.size()) { - AssEntry *entry = new AssEntry(key + ": " + value); - entry->group = "[Script Info]"; - Line.insert(script_info_end, entry); - } + if (value.size()) + Line.insert(script_info_end, new AssEntry(key + ": " + value, "[Script Info]")); return; } } diff --git a/aegisub/src/ass_style.cpp b/aegisub/src/ass_style.cpp index 68d22e11a..db58957ac 100644 --- a/aegisub/src/ass_style.cpp +++ b/aegisub/src/ass_style.cpp @@ -144,7 +144,8 @@ bool AssColor::operator!=(const AssColor &col) const { } AssStyle::AssStyle() -: name("Default") +: AssEntry(wxString(), wxS("[V4+ Styles]")) +, name("Default") , font("Arial") , fontsize(20.) , primary(255, 255, 255) @@ -166,7 +167,6 @@ AssStyle::AssStyle() , encoding(1) , relativeTo(1) { - group = "[V4+ Styles]"; for (int i = 0; i < 4; i++) Margin[i] = 10; @@ -192,9 +192,9 @@ static double get_next_double(wxStringTokenizer &tok) { return temp; } -AssStyle::AssStyle(wxString rawData,int version) { - group = "[V4+ Styles]"; - +AssStyle::AssStyle(wxString rawData, int version) +: AssEntry(wxString(), wxS("[V4+ Styles]")) +{ wxStringTokenizer tkn(rawData.Trim(false).Mid(6), ",", wxTOKEN_RET_EMPTY_ALL); name = get_next_string(tkn).Trim(true).Trim(false); @@ -294,6 +294,37 @@ AssStyle::AssStyle(wxString rawData,int version) { UpdateData(); } +AssStyle& AssStyle::operator=(AssStyle const& rgt) { + name = rgt.name; + font = rgt.font; + fontsize = rgt.fontsize; + + primary = rgt.primary; + secondary = rgt.secondary; + outline = rgt.outline; + shadow = rgt.shadow; + + bold = rgt.bold; + italic = rgt.italic; + underline = rgt.underline; + strikeout = rgt.strikeout; + + scalex = rgt.scalex; + scaley = rgt.scaley; + spacing = rgt.spacing; + angle = rgt.angle; + borderstyle = rgt.borderstyle; + outline_w = rgt.outline_w; + shadow_w = rgt.shadow_w; + alignment = rgt.alignment; + encoding = rgt.encoding; + relativeTo = rgt.relativeTo; + + memcpy(Margin, rgt.Margin, sizeof(Margin)); + + return *this; +} + void AssStyle::UpdateData() { wxString final; diff --git a/aegisub/src/ass_style.h b/aegisub/src/ass_style.h index f0e2c1071..d066dc17d 100644 --- a/aegisub/src/ass_style.h +++ b/aegisub/src/ass_style.h @@ -107,7 +107,8 @@ public: static void GetEncodings(wxArrayString &encodingStrings); AssStyle(); - AssStyle(wxString data,int version=1); + AssStyle(wxString data, int version=1); + AssStyle& operator=(AssStyle const&); wxString GetSSAText() const; ASS_EntryType GetType() const { return ENTRY_STYLE; } diff --git a/aegisub/src/auto4_lua_assfile.cpp b/aegisub/src/auto4_lua_assfile.cpp index aeeb16468..b5f5fa85a 100644 --- a/aegisub/src/auto4_lua_assfile.cpp +++ b/aegisub/src/auto4_lua_assfile.cpp @@ -302,19 +302,18 @@ namespace Automation4 { wxString section = get_string_field(L, "section", "common"); if (lclass == "clear") - result = new AssEntry; + result = new AssEntry("", ""); else if (lclass == "comment") - result = new AssEntry(";" + get_string_field(L, "text", "comment")); + result = new AssEntry(";" + get_string_field(L, "text", "comment"), section); else if (lclass == "head") - result = new AssEntry(section); + result = new AssEntry(section, section); else if (lclass == "info") { - result = new AssEntry(wxString::Format("%s: %s", get_string_field(L, "key", "info"), get_string_field(L, "value", "info"))); - result->group = "[Script Info]"; // just so it can be read correctly back + result = new AssEntry(wxString::Format("%s: %s", get_string_field(L, "key", "info"), get_string_field(L, "value", "info")), "[Script Info]"); } else if (lclass == "format") { // ohshi- ... // *FIXME* maybe ignore the actual data and just put some default stuff based on section? - result = new AssEntry("Format: Auto4,Is,Broken"); + result = new AssEntry("Format: Auto4,Is,Broken", section); } else if (lclass == "style") { AssStyle *sty = new AssStyle; @@ -367,9 +366,6 @@ namespace Automation4 { return 0; } - if (result->group.empty()) - result->group = section; - return result; } catch (agi::Exception const& e) { @@ -571,9 +567,7 @@ namespace Automation4 { // create it at the end of the file if (e->GetEntryData() != e->group) { // Add the header if the entry being added isn't a header - AssEntry *header = new AssEntry(e->group); - header->group = e->group; - lines.push_back(header); + lines.push_back(new AssEntry(e->group, e->group)); } lines.push_back(e); diff --git a/aegisub/src/dialog_attachments.cpp b/aegisub/src/dialog_attachments.cpp index d7b131b1f..f8603259b 100644 --- a/aegisub/src/dialog_attachments.cpp +++ b/aegisub/src/dialog_attachments.cpp @@ -139,7 +139,7 @@ void DialogAttachments::AttachFile(wxFileDialog &diag, wxString const& group, wx // Create attachments for (size_t i = 0; i < filenames.size(); ++i) { - AssAttachment *newAttach = new AssAttachment(filenames[i]); + AssAttachment *newAttach = new AssAttachment(filenames[i], group); try { newAttach->Import(paths[i]); } @@ -147,7 +147,6 @@ void DialogAttachments::AttachFile(wxFileDialog &diag, wxString const& group, wx delete newAttach; return; } - newAttach->group = group; ass->InsertAttachment(newAttach); } diff --git a/aegisub/src/subtitle_format_srt.cpp b/aegisub/src/subtitle_format_srt.cpp index 2d99f1376..f5a472535 100644 --- a/aegisub/src/subtitle_format_srt.cpp +++ b/aegisub/src/subtitle_format_srt.cpp @@ -427,9 +427,6 @@ found_timestamps: } // create new subtitle line = new AssDialogue; - line->group = "[Events]"; - line->Style = "Default"; - line->Comment = false; line->Start = ReadSRTTime(timestamp_regex.GetMatch(text_line, 1)); line->End = ReadSRTTime(timestamp_regex.GetMatch(text_line, 2)); // store pointer to subtitle, we'll continue working on it diff --git a/aegisub/src/subtitle_format_ttxt.cpp b/aegisub/src/subtitle_format_ttxt.cpp index e897140c3..1b2757089 100644 --- a/aegisub/src/subtitle_format_ttxt.cpp +++ b/aegisub/src/subtitle_format_ttxt.cpp @@ -282,8 +282,5 @@ void TTXTSubtitleFormat::ConvertToTTXT(AssFile &file) const { AssDialogue *diag = new AssDialogue; diag->Start = lastTime; diag->End = lastTime+OPT_GET("Timing/Default Duration")->GetInt(); - diag->group = "[Events]"; - diag->Style = "Default"; - diag->Comment = false; file.Line.push_back(diag); }