Kill AssEntry::Valid, as there wasn't actually any way to get a fully-constructed entry with it set to false

Originally committed to SVN as r6034.
This commit is contained in:
Thomas Goyne 2011-12-22 21:14:51 +00:00
parent 61767e4453
commit d28c4c4d8b
6 changed files with 43 additions and 143 deletions

View file

@ -59,7 +59,6 @@ AssDialogue::AssDialogue()
, Text("") , Text("")
{ {
group = "[Events]"; group = "[Events]";
Valid = true;
for (int i=0;i<4;i++) Margin[i] = 0; for (int i=0;i<4;i++) Margin[i] = 0;
} }
@ -75,7 +74,6 @@ AssDialogue::AssDialogue(AssDialogue const& that)
, Text(that.Text) , Text(that.Text)
{ {
group = that.group; group = that.group;
Valid = that.Valid;
for (int i=0;i<4;i++) Margin[i] = that.Margin[i]; for (int i=0;i<4;i++) Margin[i] = that.Margin[i];
} }
@ -93,20 +91,19 @@ AssDialogue::AssDialogue(wxString _data,int version)
, Text("") , Text("")
{ {
group = "[Events]"; group = "[Events]";
Valid = false; bool valid = false;
// Try parsing in different ways // Try parsing in different ways
int count = 0; int count = 0;
while (!Valid && count < 3) { while (!valid && count < 3) {
Valid = Parse(_data,version); valid = Parse(_data,version);
count++; count++;
version++; version++;
if (version > 2) version = 0; if (version > 2) version = 0;
} }
// Not valid // Not valid
if (!Valid) { if (!valid)
throw "Failed parsing line."; throw "Failed parsing line.";
}
} }
AssDialogue::~AssDialogue () { AssDialogue::~AssDialogue () {

View file

@ -34,60 +34,25 @@
/// @ingroup subs_storage /// @ingroup subs_storage
/// ///
///////////
// Headers
#include "config.h" #include "config.h"
#include "ass_attachment.h"
#include "ass_dialogue.h"
#include "ass_entry.h" #include "ass_entry.h"
#include "ass_style.h"
/// @brief Constructs AssEntry
AssEntry::AssEntry() {
Valid = true;
}
/// @brief DOCME
/// @param _data
///
AssEntry::AssEntry(wxString _data) {
data = _data;
Valid = true;
}
/// @brief Destructor for AssEntry
///
AssEntry::~AssEntry() {
}
/// @brief Get SSA conversion
/// @return
///
wxString AssEntry::GetSSAText() const { wxString AssEntry::GetSSAText() const {
wxString lower = data.Lower();
// Special cases // Special cases
if (data.Lower() == "[v4+ styles]") return wxString("[V4 Styles]"); if (lower == "[v4+ styles]") return "[V4 Styles]";
if (data.Lower() == "scripttype: v4.00+") return wxString("ScriptType: v4.00"); if (lower == "scripttype: v4.00+") return "ScriptType: v4.00";
if (data.Lower().Left(7) == "format:") { if (lower.Left(7) == "format:") {
if (group.Lower() == "[events]") return wxString("Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text"); if (group.Lower() == "[events]") return "Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text";
if (group.Lower() == "[v4+ styles]") return wxString("Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, TertiaryColour, BackColour, Bold, Italic, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, AlphaLevel, Encoding"); if (group.Lower() == "[v4+ styles]") return "Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, TertiaryColour, BackColour, Bold, Italic, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, AlphaLevel, Encoding";
} }
return GetEntryData(); return GetEntryData();
} }
/// @brief Clone
///
AssEntry *AssEntry::Clone() const { AssEntry *AssEntry::Clone() const {
// Create clone AssEntry *final = new AssEntry(data);
AssEntry *final = new AssEntry();
// Copy data
final->data = data;
final->group = group; final->group = group;
final->Valid = Valid;
// Return
return final; return final;
} }

View file

@ -37,41 +37,23 @@
#pragma once #pragma once
///////////
// Headers
#ifndef AGI_PRE #ifndef AGI_PRE
#include <wx/string.h> #include <wx/string.h>
#endif #endif
#include <libaegisub/exception.h> #include <libaegisub/exception.h>
//////////////
// Prototypes
class AssDialogue; class AssDialogue;
class AssStyle; class AssStyle;
class AssAttachment; class AssAttachment;
/// DOCME
enum ASS_EntryType { enum ASS_EntryType {
/// DOCME
ENTRY_BASE, ENTRY_BASE,
/// DOCME
ENTRY_DIALOGUE, ENTRY_DIALOGUE,
/// DOCME
ENTRY_STYLE, ENTRY_STYLE,
/// DOCME
ENTRY_ATTACHMENT ENTRY_ATTACHMENT
}; };
/// @see aegisub.h /// @see aegisub.h
namespace Aegisub { namespace Aegisub {
@ -82,60 +64,40 @@ namespace Aegisub {
/// DOCME /// DOCME
class InvalidMarginIdError : public agi::InternalError { class InvalidMarginIdError : public agi::InternalError {
public: public:
/// @brief DOCME
/// @return
///
InvalidMarginIdError() : InternalError("Invalid margin id", 0) { } InvalidMarginIdError() : InternalError("Invalid margin id", 0) { }
/// @brief DOCME
/// @return
///
const char *GetName() const { return "internal_error/invalid_margin_id"; } const char *GetName() const { return "internal_error/invalid_margin_id"; }
}; };
} }
/// DOCME /// DOCME
/// @class AssEntry /// @class AssEntry
/// @brief DOCME /// @brief DOCME
/// ///
/// DOCME /// DOCME
class AssEntry { class AssEntry {
private: /// Raw data, exactly the same line that appears on the .ass (note that this will be in ass even if source wasn't)
wxString data;
/// DOCME
wxString data; // Raw data, exactly the same line that appears on the .ass (note that this will be in ass even if source wasn't)
public: public:
/// Group it belongs to, e.g. "[Events]"
wxString group;
/// DOCME AssEntry(wxString const& data = "") : data(data) { }
bool Valid; // Flags as valid or not virtual ~AssEntry() { }
/// DOCME
wxString group; // Group it belongs to, e.g. "[Events]"
AssEntry();
AssEntry(wxString data);
virtual ~AssEntry();
/// Create a copy of this entry
virtual AssEntry *Clone() const; virtual AssEntry *Clone() const;
/// @brief DOCME /// Get this entry's fully-derived type
/// @return
///
virtual ASS_EntryType GetType() const { return ENTRY_BASE; } virtual ASS_EntryType GetType() const { return ENTRY_BASE; }
/// @brief DOCME /// @brief Get this line's raw entry data in ASS format
/// @return
///
virtual const wxString GetEntryData() const { return data; } virtual const wxString GetEntryData() const { return data; }
/// @brief DOCME /// @brief Set this line's raw entry data
/// @param newData /// @param newData New raw entry data
/// virtual void SetEntryData(wxString const& newData) { data = newData; }
virtual void SetEntryData(wxString newData) { data = newData; }
/// Get this line in SSA format
virtual wxString GetSSAText() const; virtual wxString GetSSAText() const;
}; };

View file

@ -203,10 +203,8 @@ AssStyle::AssStyle(const AssStyle& s)
} }
AssStyle::AssStyle(wxString _data,int version) { AssStyle::AssStyle(wxString _data,int version) {
Valid = Parse(_data,version); if (!Parse(_data,version))
if (!Valid) {
throw "[Error] Failed parsing line."; throw "[Error] Failed parsing line.";
}
UpdateData(); UpdateData();
} }

View file

@ -301,15 +301,11 @@ void DialogStyleManager::LoadCatalog () {
/// @brief Load the list of styles from a subtitle file /// @brief Load the list of styles from a subtitle file
void DialogStyleManager::LoadCurrentStyles (AssFile *subs) { void DialogStyleManager::LoadCurrentStyles (AssFile *subs) {
using std::list;
AssStyle *style;
CurrentList->Clear(); CurrentList->Clear();
styleMap.clear(); styleMap.clear();
for (list<AssEntry*>::iterator cur=subs->Line.begin();cur!=subs->Line.end();cur++) { for (std::list<AssEntry*>::iterator cur=subs->Line.begin();cur!=subs->Line.end();cur++) {
style = dynamic_cast<AssStyle*>(*cur); if (AssStyle *style = dynamic_cast<AssStyle*>(*cur)) {
if (style && style->Valid) {
CurrentList->Append(style->name); CurrentList->Append(style->name);
styleMap.push_back(style); styleMap.push_back(style);
} }
@ -319,14 +315,11 @@ void DialogStyleManager::LoadCurrentStyles (AssFile *subs) {
/// @brief Load the list of styles from the currently active storage /// @brief Load the list of styles from the currently active storage
void DialogStyleManager::LoadStorageStyles () { void DialogStyleManager::LoadStorageStyles () {
using std::list;
StorageList->Clear(); StorageList->Clear();
styleStorageMap.clear(); styleStorageMap.clear();
for (list<AssStyle*>::iterator cur=Store.style.begin();cur!=Store.style.end();cur++) { for (std::list<AssStyle*>::iterator cur=Store.style.begin();cur!=Store.style.end();cur++) {
AssStyle *style = *cur; if (AssStyle *style = *cur) {
if (style && style->Valid) {
StorageList->Append(style->name); StorageList->Append(style->name);
styleStorageMap.push_back(style); styleStorageMap.push_back(style);
} }
@ -657,24 +650,17 @@ void DialogStyleManager::PasteToCurrent() {
wxStringTokenizer st(data,'\n'); wxStringTokenizer st(data,'\n');
while (st.HasMoreTokens()) { while (st.HasMoreTokens()) {
AssStyle *s = NULL;
try { try {
s = new AssStyle(st.GetNextToken().Trim(true)); AssStyle *s = new AssStyle(st.GetNextToken().Trim(true));
if (s->Valid) { while (c->ass->GetStyle(s->name) != NULL)
while (c->ass->GetStyle(s->name) != NULL) s->name = "Copy of " + s->name;
s->name = "Copy of " + s->name;
s->UpdateData(); c->ass->InsertStyle(s);
c->ass->InsertStyle(s); LoadCurrentStyles(c->ass);
LoadCurrentStyles(c->ass);
c->ass->Commit(_("style paste"), AssFile::COMMIT_STYLES); c->ass->Commit(_("style paste"), AssFile::COMMIT_STYLES);
}
else
wxMessageBox(_("Could not parse style"), _("Could not parse style"), wxOK | wxICON_EXCLAMATION , this);
} }
catch (...) { catch (...) {
delete s;
wxMessageBox(_("Could not parse style"), _("Could not parse style"), wxOK | wxICON_EXCLAMATION , this); wxMessageBox(_("Could not parse style"), _("Could not parse style"), wxOK | wxICON_EXCLAMATION , this);
} }
@ -696,25 +682,18 @@ void DialogStyleManager::PasteToStorage() {
wxStringTokenizer st(data,'\n'); wxStringTokenizer st(data,'\n');
while (st.HasMoreTokens()) { while (st.HasMoreTokens()) {
AssStyle *s = NULL;
try { try {
s = new AssStyle(st.GetNextToken().Trim(true)); AssStyle *s = new AssStyle(st.GetNextToken().Trim(true));
if (s->Valid) { while (Store.GetStyle(s->name) != NULL)
while (Store.GetStyle(s->name) != NULL) s->name = "Copy of " + s->name;
s->name = "Copy of " + s->name;
s->UpdateData(); Store.style.push_back(s);
Store.style.push_back(s); Store.Save(CatalogList->GetString(CatalogList->GetSelection()));
Store.Save(CatalogList->GetString(CatalogList->GetSelection()));
LoadStorageStyles(); LoadStorageStyles();
StorageList->SetStringSelection(s->name); StorageList->SetStringSelection(s->name);
}
else
wxMessageBox(_("Could not parse style"), _("Could not parse style"), wxOK | wxICON_EXCLAMATION , this);
} }
catch(...) { catch(...) {
delete s;
wxMessageBox(_("Could not parse style"), _("Could not parse style"), wxOK | wxICON_EXCLAMATION , this); wxMessageBox(_("Could not parse style"), _("Could not parse style"), wxOK | wxICON_EXCLAMATION , this);
} }
} }

View file

@ -691,7 +691,6 @@ int SubsEditBox::BlockAtPos(wxString const& text, int pos) const {
void SubsEditBox::SetTag(wxString tag, wxString value, bool atEnd) { void SubsEditBox::SetTag(wxString tag, wxString value, bool atEnd) {
assert(line); assert(line);
assert(line->Valid);
if (line->Blocks.empty()) if (line->Blocks.empty())
line->ParseASSTags(); line->ParseASSTags();