Make AssEntry::group const as it really should never change

Originally committed to SVN as r6408.
This commit is contained in:
Thomas Goyne 2012-02-01 00:47:38 +00:00
parent 8bef1eb874
commit a7d54f3d69
11 changed files with 63 additions and 50 deletions

View File

@ -49,8 +49,9 @@
#include <libaegisub/io.h> #include <libaegisub/io.h>
#include <libaegisub/scoped_ptr.h> #include <libaegisub/scoped_ptr.h>
AssAttachment::AssAttachment(wxString name) AssAttachment::AssAttachment(wxString const& name, wxString const& group)
: data(new std::vector<char>) : AssEntry(wxString(), group)
, data(new std::vector<char>)
, filename(name) , filename(name)
{ {
wxFileName fname(filename); wxFileName fname(filename);
@ -60,9 +61,8 @@ AssAttachment::AssAttachment(wxString name)
} }
AssEntry *AssAttachment::Clone() const { AssEntry *AssAttachment::Clone() const {
AssAttachment *clone = new AssAttachment(filename); AssAttachment *clone = new AssAttachment(filename, group);
clone->data = data; clone->data = data;
clone->group = group;
return clone; return clone;
} }

View File

@ -79,5 +79,5 @@ public:
ASS_EntryType GetType() const { return ENTRY_ATTACHMENT; } ASS_EntryType GetType() const { return ENTRY_ATTACHMENT; }
AssEntry *Clone() const; AssEntry *Clone() const;
AssAttachment(wxString name); AssAttachment(wxString const& name, wxString const& group);
}; };

View File

@ -52,7 +52,5 @@ wxString AssEntry::GetSSAText() const {
} }
AssEntry *AssEntry::Clone() const { AssEntry *AssEntry::Clone() const {
AssEntry *final = new AssEntry(data); return new AssEntry(data, group);
final->group = group;
return final;
} }

View File

@ -80,9 +80,9 @@ class AssEntry {
public: public:
/// Group it belongs to, e.g. "[Events]" /// 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() { } virtual ~AssEntry() { }
/// Create a copy of this entry /// Create a copy of this entry

View File

@ -329,8 +329,7 @@ void AssFile::AddLine(wxString data, int *version, AssAttachment **attach) {
// Attachment // Attachment
if (lowGroup == "[fonts]" || lowGroup == "[graphics]") { if (lowGroup == "[fonts]" || lowGroup == "[graphics]") {
if (isFilename) { if (isFilename) {
*attach = new AssAttachment(data.Mid(10)); *attach = new AssAttachment(data.Mid(10), group);
(*attach)->group = group;
} }
} }
// Dialogue // Dialogue
@ -479,16 +478,16 @@ void AssFile::InsertAttachment(AssAttachment *attach) {
Line.push_back(attach); Line.push_back(attach);
} }
void AssFile::InsertAttachment (wxString filename) { void AssFile::InsertAttachment(wxString filename) {
std::auto_ptr<AssAttachment> newAttach(new AssAttachment(wxFileName(filename).GetFullName())); wxString group("[Graphics]");
newAttach->Import(filename);
// Insert
wxString ext = filename.Right(4).Lower(); wxString ext = filename.Right(4).Lower();
if (ext == ".ttf" || ext == ".ttc" || ext == ".pfb") if (ext == ".ttf" || ext == ".ttc" || ext == ".pfb")
newAttach->group = "[Fonts]"; group = "[Fonts]";
else
newAttach->group = "[Graphics]"; std::auto_ptr<AssAttachment> newAttach(new AssAttachment(wxFileName(filename).GetFullName(), group));
newAttach->Import(filename);
InsertAttachment(newAttach.release()); InsertAttachment(newAttach.release());
} }
@ -540,11 +539,8 @@ void AssFile::SetScriptInfo(wxString const& key, wxString const& value) {
script_info_end = cur; script_info_end = cur;
} }
else if (found_script_info) { else if (found_script_info) {
if (value.size()) { if (value.size())
AssEntry *entry = new AssEntry(key + ": " + value); Line.insert(script_info_end, new AssEntry(key + ": " + value, "[Script Info]"));
entry->group = "[Script Info]";
Line.insert(script_info_end, entry);
}
return; return;
} }
} }

View File

@ -144,7 +144,8 @@ bool AssColor::operator!=(const AssColor &col) const {
} }
AssStyle::AssStyle() AssStyle::AssStyle()
: name("Default") : AssEntry(wxString(), wxS("[V4+ Styles]"))
, name("Default")
, font("Arial") , font("Arial")
, fontsize(20.) , fontsize(20.)
, primary(255, 255, 255) , primary(255, 255, 255)
@ -166,7 +167,6 @@ AssStyle::AssStyle()
, encoding(1) , encoding(1)
, relativeTo(1) , relativeTo(1)
{ {
group = "[V4+ Styles]";
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
Margin[i] = 10; Margin[i] = 10;
@ -192,9 +192,9 @@ static double get_next_double(wxStringTokenizer &tok) {
return temp; return temp;
} }
AssStyle::AssStyle(wxString rawData,int version) { AssStyle::AssStyle(wxString rawData, int version)
group = "[V4+ Styles]"; : AssEntry(wxString(), wxS("[V4+ Styles]"))
{
wxStringTokenizer tkn(rawData.Trim(false).Mid(6), ",", wxTOKEN_RET_EMPTY_ALL); wxStringTokenizer tkn(rawData.Trim(false).Mid(6), ",", wxTOKEN_RET_EMPTY_ALL);
name = get_next_string(tkn).Trim(true).Trim(false); name = get_next_string(tkn).Trim(true).Trim(false);
@ -294,6 +294,37 @@ AssStyle::AssStyle(wxString rawData,int version) {
UpdateData(); 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() { void AssStyle::UpdateData() {
wxString final; wxString final;

View File

@ -107,7 +107,8 @@ public:
static void GetEncodings(wxArrayString &encodingStrings); static void GetEncodings(wxArrayString &encodingStrings);
AssStyle(); AssStyle();
AssStyle(wxString data,int version=1); AssStyle(wxString data, int version=1);
AssStyle& operator=(AssStyle const&);
wxString GetSSAText() const; wxString GetSSAText() const;
ASS_EntryType GetType() const { return ENTRY_STYLE; } ASS_EntryType GetType() const { return ENTRY_STYLE; }

View File

@ -302,19 +302,18 @@ namespace Automation4 {
wxString section = get_string_field(L, "section", "common"); wxString section = get_string_field(L, "section", "common");
if (lclass == "clear") if (lclass == "clear")
result = new AssEntry; result = new AssEntry("", "");
else if (lclass == "comment") 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") else if (lclass == "head")
result = new AssEntry(section); result = new AssEntry(section, section);
else if (lclass == "info") { else if (lclass == "info") {
result = new AssEntry(wxString::Format("%s: %s", get_string_field(L, "key", "info"), get_string_field(L, "value", "info"))); result = new AssEntry(wxString::Format("%s: %s", get_string_field(L, "key", "info"), get_string_field(L, "value", "info")), "[Script Info]");
result->group = "[Script Info]"; // just so it can be read correctly back
} }
else if (lclass == "format") { else if (lclass == "format") {
// ohshi- ... // ohshi- ...
// *FIXME* maybe ignore the actual data and just put some default stuff based on section? // *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") { else if (lclass == "style") {
AssStyle *sty = new AssStyle; AssStyle *sty = new AssStyle;
@ -367,9 +366,6 @@ namespace Automation4 {
return 0; return 0;
} }
if (result->group.empty())
result->group = section;
return result; return result;
} }
catch (agi::Exception const& e) { catch (agi::Exception const& e) {
@ -571,9 +567,7 @@ namespace Automation4 {
// create it at the end of the file // create it at the end of the file
if (e->GetEntryData() != e->group) { if (e->GetEntryData() != e->group) {
// Add the header if the entry being added isn't a header // Add the header if the entry being added isn't a header
AssEntry *header = new AssEntry(e->group); lines.push_back(new AssEntry(e->group, e->group));
header->group = e->group;
lines.push_back(header);
} }
lines.push_back(e); lines.push_back(e);

View File

@ -139,7 +139,7 @@ void DialogAttachments::AttachFile(wxFileDialog &diag, wxString const& group, wx
// Create attachments // Create attachments
for (size_t i = 0; i < filenames.size(); ++i) { for (size_t i = 0; i < filenames.size(); ++i) {
AssAttachment *newAttach = new AssAttachment(filenames[i]); AssAttachment *newAttach = new AssAttachment(filenames[i], group);
try { try {
newAttach->Import(paths[i]); newAttach->Import(paths[i]);
} }
@ -147,7 +147,6 @@ void DialogAttachments::AttachFile(wxFileDialog &diag, wxString const& group, wx
delete newAttach; delete newAttach;
return; return;
} }
newAttach->group = group;
ass->InsertAttachment(newAttach); ass->InsertAttachment(newAttach);
} }

View File

@ -427,9 +427,6 @@ found_timestamps:
} }
// create new subtitle // create new subtitle
line = new AssDialogue; line = new AssDialogue;
line->group = "[Events]";
line->Style = "Default";
line->Comment = false;
line->Start = ReadSRTTime(timestamp_regex.GetMatch(text_line, 1)); line->Start = ReadSRTTime(timestamp_regex.GetMatch(text_line, 1));
line->End = ReadSRTTime(timestamp_regex.GetMatch(text_line, 2)); line->End = ReadSRTTime(timestamp_regex.GetMatch(text_line, 2));
// store pointer to subtitle, we'll continue working on it // store pointer to subtitle, we'll continue working on it

View File

@ -282,8 +282,5 @@ void TTXTSubtitleFormat::ConvertToTTXT(AssFile &file) const {
AssDialogue *diag = new AssDialogue; AssDialogue *diag = new AssDialogue;
diag->Start = lastTime; diag->Start = lastTime;
diag->End = lastTime+OPT_GET("Timing/Default Duration")->GetInt(); diag->End = lastTime+OPT_GET("Timing/Default Duration")->GetInt();
diag->group = "[Events]";
diag->Style = "Default";
diag->Comment = false;
file.Line.push_back(diag); file.Line.push_back(diag);
} }