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

View File

@ -34,60 +34,25 @@
/// @ingroup subs_storage
///
///////////
// Headers
#include "config.h"
#include "ass_attachment.h"
#include "ass_dialogue.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 lower = data.Lower();
// Special cases
if (data.Lower() == "[v4+ styles]") return wxString("[V4 Styles]");
if (data.Lower() == "scripttype: v4.00+") return wxString("ScriptType: v4.00");
if (data.Lower().Left(7) == "format:") {
if (group.Lower() == "[events]") return wxString("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 (lower == "[v4+ styles]") return "[V4 Styles]";
if (lower == "scripttype: v4.00+") return "ScriptType: v4.00";
if (lower.Left(7) == "format:") {
if (group.Lower() == "[events]") return "Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text";
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();
}
/// @brief Clone
///
AssEntry *AssEntry::Clone() const {
// Create clone
AssEntry *final = new AssEntry();
// Copy data
final->data = data;
AssEntry *final = new AssEntry(data);
final->group = group;
final->Valid = Valid;
// Return
return final;
}

View File

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

View File

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

View File

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