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/scoped_ptr.h>
AssAttachment::AssAttachment(wxString name)
: data(new std::vector<char>)
AssAttachment::AssAttachment(wxString const& name, wxString const& group)
: AssEntry(wxString(), group)
, data(new std::vector<char>)
, 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;
}

View file

@ -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);
};

View file

@ -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);
}

View file

@ -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

View file

@ -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
@ -480,15 +479,15 @@ void AssFile::InsertAttachment(AssAttachment *attach) {
}
void AssFile::InsertAttachment(wxString filename) {
std::auto_ptr<AssAttachment> newAttach(new AssAttachment(wxFileName(filename).GetFullName()));
newAttach->Import(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<AssAttachment> 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;
}
}

View file

@ -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;

View file

@ -108,6 +108,7 @@ public:
AssStyle();
AssStyle(wxString data, int version=1);
AssStyle& operator=(AssStyle const&);
wxString GetSSAText() const;
ASS_EntryType GetType() const { return ENTRY_STYLE; }

View file

@ -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);

View file

@ -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);
}

View file

@ -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

View file

@ -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);
}