Made AssEntry::data private

Originally committed to SVN as r182.
This commit is contained in:
Rodrigo Braz Monteiro 2006-02-27 02:23:50 +00:00
parent 39225db7c8
commit 5f6f39ce3e
14 changed files with 102 additions and 100 deletions

View File

@ -55,7 +55,6 @@ AssDialogue::AssDialogue() {
Movement = 0;
#endif
Type = ENTRY_DIALOGUE;
group = _T("[Events]");
Valid = true;
@ -80,10 +79,8 @@ AssDialogue::AssDialogue(wxString _data,bool IsSSA) {
Movement = 0;
#endif
Type = ENTRY_DIALOGUE;
group = _T("[Events]");
data = _data;
Valid = Parse(IsSSA);
Valid = Parse(_data,IsSSA);
if (!Valid) {
throw _T("Failed parsing line.");
}
@ -130,21 +127,21 @@ void AssDialogue::ClearBlocks() {
//////////////////
// Parse ASS Data
bool AssDialogue::Parse(bool IsSSA) {
bool AssDialogue::Parse(wxString rawData, bool IsSSA) {
size_t pos = 0;
wxString temp;
// Get type
if (data.substr(pos,9) == _T("Dialogue:")) {
if (rawData.substr(pos,9) == _T("Dialogue:")) {
Comment = false;
pos = 10;
}
else if (data.substr(pos,8) == _T("Comment:")) {
else if (rawData.substr(pos,8) == _T("Comment:")) {
Comment = true;
pos = 9;
}
else return false;
wxStringTokenizer tkn(data.Mid(pos),_T(","),wxTOKEN_RET_EMPTY_ALL);
wxStringTokenizer tkn(rawData.Mid(pos),_T(","),wxTOKEN_RET_EMPTY_ALL);
// Get layer number
if (!tkn.HasMoreTokens()) return false;
@ -209,33 +206,34 @@ bool AssDialogue::Parse(bool IsSSA) {
// Update AssDialogue's data line
void AssDialogue::UpdateData () {
// Prepare
data = _T("");
wxString final = _T("");
// Write all data
if (Comment) data += _T("Comment: ");
else data += _T("Dialogue: ");
// Write all final
if (Comment) final += _T("Comment: ");
else final += _T("Dialogue: ");
data += wxString::Format(_T("%01i"),Layer);
data += _T(",");
final += wxString::Format(_T("%01i"),Layer);
final += _T(",");
data += Start.GetASSFormated() + _T(",");
data += End.GetASSFormated() + _T(",");
final += Start.GetASSFormated() + _T(",");
final += End.GetASSFormated() + _T(",");
Style.Replace(_T(","),_T(";"));
Actor.Replace(_T(","),_T(";"));
data += Style + _T(",");
data += Actor + _T(",");
final += Style + _T(",");
final += Actor + _T(",");
data += GetMarginString(1);
data += _T(",");
data += GetMarginString(2);
data += _T(",");
data += GetMarginString(3);
data += _T(",");
final += GetMarginString(1);
final += _T(",");
final += GetMarginString(2);
final += _T(",");
final += GetMarginString(3);
final += _T(",");
Effect.Replace(_T(","),_T(";"));
data += Effect + _T(",");
data += Text;
final += Effect + _T(",");
final += Text;
SetEntryData(final);
}

View File

@ -174,7 +174,9 @@ public:
FexMovement *Movement; // Point tracker generated movement
#endif
bool Parse(bool IsSSA=false); // Parses raw ASS data into everything else
ASS_EntryType GetType() { return ENTRY_DIALOGUE; }
bool Parse(wxString data,bool IsSSA=false); // Parses raw ASS data into everything else
void ParseASSTags(); // Parses text to generate block information (doesn't update data)
void ParseSRTTags(); // Converts tags to ass format and calls ParseASSTags+UpdateData
void UpdateData(); // Updates raw data from current values + text

View File

@ -45,13 +45,11 @@
///////////////////////
// Constructs AssEntry
AssEntry::AssEntry() {
Type = ENTRY_BASE;
Valid = true;
}
AssEntry::AssEntry(wxString _data) {
data = _data;
Type = ENTRY_BASE;
Valid = true;
}
@ -73,7 +71,7 @@ bool operator < (const AssEntry &t1, const AssEntry &t2) {
// Returns an entry as dialogue if possible, else, returns NULL
AssDialogue *AssEntry::GetAsDialogue(AssEntry *base) {
if (!base) return NULL;
if (base->Type == ENTRY_DIALOGUE) {
if (base->GetType() == ENTRY_DIALOGUE) {
return static_cast<AssDialogue*> (base);
}
return NULL;
@ -84,7 +82,7 @@ AssDialogue *AssEntry::GetAsDialogue(AssEntry *base) {
// Returns an entry as style if possible, else, returns NULL
AssStyle *AssEntry::GetAsStyle(AssEntry *base) {
if (!base) return NULL;
if (base->Type == ENTRY_STYLE) {
if (base->GetType() == ENTRY_STYLE) {
return static_cast<AssStyle*> (base);
}
return NULL;

View File

@ -60,17 +60,22 @@ enum ASS_EntryType {
////////////////////////////////////
// Base class for each line in file
class AssEntry {
private:
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:
int StartMS; // This is only stored for sorting issues, in order to keep non-dialogue lines aligned
bool Valid; // Flags as valid or not
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)
wxString group; // Group it belongs to, e.g. "[Events]"
ASS_EntryType Type; // Defines if this is a dialogue, style, or unknown line
AssEntry();
AssEntry(wxString data);
virtual ~AssEntry();
virtual ASS_EntryType GetType() { return ENTRY_BASE; }
virtual const wxString GetEntryData() { return data; }
virtual void SetEntryData(wxString newData) { if (newData.IsEmpty()) data.Clear(); else data = newData; }
virtual wxString GetSSAText();
static AssDialogue *GetAsDialogue(AssEntry *base); // Returns an entry base as a dialogue if it is valid, null otherwise
static AssStyle *GetAsStyle(AssEntry *base); // Returns an entry base as a style if it is valid, null otherwise

View File

@ -193,7 +193,7 @@ void AssFile::SaveASS (wxString _filename,bool setfilename,const wxString encodi
// Write lines
using std::list;
for (list<AssEntry*>::iterator cur=Line.begin();cur!=Line.end();cur++) {
file.WriteLineToFile((*cur)->data);
file.WriteLineToFile((*cur)->GetEntryData());
}
// Done
@ -443,14 +443,14 @@ void AssFile::LoadDefault (bool defline) {
AddLine(_T(""),_T("[Script Info]"),-1,IsSSA);
AddLine(_T("[V4+ Styles]"),_T("[V4+ Styles]"),-1,IsSSA);
AddLine(_T("Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding"),_T("[V4+ Styles]"),-1,IsSSA);
AddLine(defstyle.data,_T("[V4+ Styles]"),-1,IsSSA);
AddLine(defstyle.GetEntryData(),_T("[V4+ Styles]"),-1,IsSSA);
AddLine(_T(""),_T("[V4+ Styles]"),-1,IsSSA);
AddLine(_T("[Events]"),_T("[Events]"),-1,IsSSA);
AddLine(_T("Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text"),_T("[Events]"),-1,IsSSA);
if (defline) {
AssDialogue def;
AddLine(def.data,_T("[Events]"),0,IsSSA);
AddLine(def.GetEntryData(),_T("[Events]"),0,IsSSA);
}
loaded = true;
@ -473,7 +473,7 @@ AssFile::AssFile (AssFile &from) {
// Copy lines
int lasttime = -1;
for (list<AssEntry*>::iterator cur=from.Line.begin();cur!=from.Line.end();cur++) {
lasttime = AddLine((*cur)->data,(*cur)->group,lasttime,IsSSA);
lasttime = AddLine((*cur)->GetEntryData(),(*cur)->group,lasttime,IsSSA);
}
// Add comments
@ -496,7 +496,7 @@ void AssFile::InsertStyle (AssStyle *style) {
// Look for insert position
for (cur=Line.begin();cur!=Line.end();cur++) {
curEntry = *cur;
if (curEntry->Type == ENTRY_STYLE || (lastGroup == _T("[V4+ Styles]") && curEntry->data.substr(0,7) == _T("Format:"))) {
if (curEntry->GetType() == ENTRY_STYLE || (lastGroup == _T("[V4+ Styles]") && curEntry->GetEntryData().substr(0,7) == _T("Format:"))) {
lastStyle = cur;
}
lasttime = curEntry->StartMS;
@ -553,7 +553,7 @@ wxString AssFile::GetScriptInfo(const wxString _key) {
for (cur=Line.begin();cur!=Line.end();cur++) {
if ((*cur)->group == _T("[Script Info]")) {
GotIn = true;
wxString curText = (*cur)->data;
wxString curText = (*cur)->GetEntryData();
curText.Lower();
// Found
@ -601,7 +601,7 @@ void AssFile::SetScriptInfo(const wxString _key,const wxString value) {
for (cur=Line.begin();cur!=Line.end();cur++) {
if ((*cur)->group == _T("[Script Info]")) {
GotIn = true;
wxString curText = (*cur)->data;
wxString curText = (*cur)->GetEntryData();
curText.Lower();
// Found
@ -611,7 +611,7 @@ void AssFile::SetScriptInfo(const wxString _key,const wxString value) {
wxString result = _key;
result += _T(": ");
result += value;
(*cur)->data = result;
(*cur)->SetEntryData(result);
}
// Remove key
@ -622,7 +622,7 @@ void AssFile::SetScriptInfo(const wxString _key,const wxString value) {
return;
}
if (!(*cur)->data.empty()) prev = cur;
if (!(*cur)->GetEntryData().empty()) prev = cur;
}
// Add
@ -656,7 +656,7 @@ void AssFile::AddComment(const wxString _comment) {
if (step == 0 && (*cur)->group == _T("[Script Info]")) step = 1;
// First line after a ;
else if (step == 1 && (*cur)->data.Left(1) != _T(";")) {
else if (step == 1 && (*cur)->GetEntryData().Left(1) != _T(";")) {
AssEntry *prev = *cur;
AssEntry *comm = new AssEntry(comment);
comm->group = prev->group;
@ -678,8 +678,8 @@ wxArrayString AssFile::GetStyles() {
if (curstyle) {
styles.Add(curstyle->name);
}
if (!curstyle && (*cur)->data.Left(5) == _T("Style")) {
wxLogMessage(_T("Style ignored: ") + (*cur)->data);
if (!curstyle && (*cur)->GetEntryData().Left(5) == _T("Style")) {
wxLogMessage(_T("Style ignored: ") + (*cur)->GetEntryData());
curstyle = AssEntry::GetAsStyle(*cur);
}
}
@ -717,7 +717,7 @@ void AssFile::CompressForStack(bool compress) {
diag = AssEntry::GetAsDialogue(*cur);
if (diag) {
if (compress) {
diag->data.Clear();
diag->SetEntryData(_T(""));
diag->ClearBlocks();
}
else diag->UpdateData();

View File

@ -147,7 +147,6 @@ wxString AssColor::GetSSAFormatted () {
///////////////////////
// Default Constructor
AssStyle::AssStyle() {
Type = ENTRY_STYLE;
group = _T("[V4+ Styles]");
name = _T("Default");
@ -196,9 +195,7 @@ AssStyle::AssStyle() {
///////////////
// Constructor
AssStyle::AssStyle(wxString _data,bool IsSSA) {
Type = ENTRY_STYLE;
data = _data;
Valid = Parse(IsSSA);
Valid = Parse(_data,IsSSA);
if (!Valid) {
throw _T("[Error] Failed parsing line.");
}
@ -214,10 +211,10 @@ AssStyle::~AssStyle() {
//////////////////////////////
// Parses value from ASS data
bool AssStyle::Parse(bool IsSSA) {
bool AssStyle::Parse(wxString rawData,bool IsSSA) {
wxString temp;
long templ;
wxStringTokenizer tkn(data.Mid(6),_T(","),wxTOKEN_RET_EMPTY_ALL);
wxStringTokenizer tkn(rawData.Mid(6),_T(","),wxTOKEN_RET_EMPTY_ALL);
// Read name
if (!tkn.HasMoreTokens()) return false;
@ -408,39 +405,40 @@ bool AssStyle::Parse(bool IsSSA) {
// Writes data back to ASS format
void AssStyle::UpdateData() {
// Prepare
data = _T("Style: ");
wxString final = _T("Style: ");
// Write all data
// Write all final
name.Replace(_T(","),_T(";"));
font.Replace(_T(","),_T(";"));
data += name + _T(",");
data += font + _T(",");
data += wxString::Format(_T("%i"),fontsize) + _T(",");
final += name + _T(",");
final += font + _T(",");
final += wxString::Format(_T("%i"),fontsize) + _T(",");
data += primary.GetASSFormatted(true,false,true) + _T(",");
data += secondary.GetASSFormatted(true,false,true) + _T(",");
data += outline.GetASSFormatted(true,false,true) + _T(",");
data += shadow.GetASSFormatted(true,false,true) + _T(",");
final += primary.GetASSFormatted(true,false,true) + _T(",");
final += secondary.GetASSFormatted(true,false,true) + _T(",");
final += outline.GetASSFormatted(true,false,true) + _T(",");
final += shadow.GetASSFormatted(true,false,true) + _T(",");
data += wxString::Format(_T("%i"),bold?-1:0) + _T(",");
data += wxString::Format(_T("%i"),italic?-1:0) + _T(",");
data += wxString::Format(_T("%i"),underline?-1:0) + _T(",");
data += wxString::Format(_T("%i"),strikeout?-1:0) + _T(",");
final += wxString::Format(_T("%i"),bold?-1:0) + _T(",");
final += wxString::Format(_T("%i"),italic?-1:0) + _T(",");
final += wxString::Format(_T("%i"),underline?-1:0) + _T(",");
final += wxString::Format(_T("%i"),strikeout?-1:0) + _T(",");
data += wxString::Format(_T("%i"),scalex) + _T(",");
data += wxString::Format(_T("%i"),scaley) + _T(",");
data += wxString::Format(_T("%.2f"),spacing) + _T(",");
final += wxString::Format(_T("%i"),scalex) + _T(",");
final += wxString::Format(_T("%i"),scaley) + _T(",");
final += wxString::Format(_T("%.2f"),spacing) + _T(",");
data += wxString::Format(_T("%.2f"),angle) + _T(",");
data += wxString::Format(_T("%i"),borderstyle) + _T(",");
data += wxString::Format(_T("%.2f"),outline_w) + _T(",");
data += wxString::Format(_T("%.2f"),shadow_w) + _T(",");
final += wxString::Format(_T("%.2f"),angle) + _T(",");
final += wxString::Format(_T("%i"),borderstyle) + _T(",");
final += wxString::Format(_T("%.2f"),outline_w) + _T(",");
final += wxString::Format(_T("%.2f"),shadow_w) + _T(",");
data += wxString::Format(_T("%i"),alignment) + _T(",");
data += wxString::Format(_T("%i"),MarginL) + _T(",");
data += wxString::Format(_T("%i"),MarginR) + _T(",");
data += wxString::Format(_T("%i"),MarginV) + _T(",");
data += wxString::Format(_T("%i"),encoding);
final += wxString::Format(_T("%i"),alignment) + _T(",");
final += wxString::Format(_T("%i"),MarginL) + _T(",");
final += wxString::Format(_T("%i"),MarginR) + _T(",");
final += wxString::Format(_T("%i"),MarginV) + _T(",");
final += wxString::Format(_T("%i"),encoding);
SetEntryData(final);
}

View File

@ -94,7 +94,9 @@ public:
int MarginV;
int encoding;
bool Parse(bool IsSSA=false); // Parses raw ASS/SSA data into everything else
ASS_EntryType GetType() { return ENTRY_STYLE; }
bool Parse(wxString data,bool IsSSA=false); // Parses raw ASS/SSA data into everything else
void UpdateData(); // Updates raw data
wxString GetSSAText(); // Retrieves SSA-formatted style
wxString GetMarginString(int which); // Returns the margin value as a string (1 = left, 2 = right, 3 = vertical)

View File

@ -58,7 +58,7 @@ void AssStyleStorage::Save(wxString name) {
file.open(filename.mb_str(wxConvLocal));
for (list<AssStyle*>::iterator cur=style.begin();cur!=style.end();cur++) {
file << (*cur)->data.mb_str(wxConvUTF8) << endl;
file << (*cur)->GetEntryData().mb_str(wxConvUTF8) << endl;
}
file.close();

View File

@ -97,7 +97,7 @@ bool AudioKaraoke::LoadFromDialogue(AssDialogue *_diag) {
}
// Split
workDiag = new AssDialogue(diag->data, false);
workDiag = new AssDialogue(diag->GetEntryData(), false);
workDiag->ParseASSTags();
must_rebuild = false;
bool hasKar = ParseDialogue(workDiag);
@ -199,7 +199,7 @@ void AudioKaraoke::AutoSplit() {
// Load
must_rebuild = true;
AssDialogue newDiag(diag->data);
AssDialogue newDiag(diag->GetEntryData());
newDiag.Text = newText;
//newDiag.ParseASSTags();
ParseDialogue(&newDiag);

View File

@ -1201,7 +1201,7 @@ void AutomationScript::process_lines(AssFile *input)
if (!e->Valid) continue;
if (e->Type == ENTRY_STYLE) {
if (e->GetType() == ENTRY_STYLE) {
AssStyle *style = e->GetAsStyle(e);
@ -1247,19 +1247,19 @@ void AutomationScript::process_lines(AssFile *input)
} else if (e->group == _T("[Events]")) {
if (e->Type != ENTRY_DIALOGUE) {
if (e->GetType() != ENTRY_DIALOGUE) {
// not a dialogue/comment event
// start checking for a blank line
if (e->data.IsEmpty()) {
if (e->GetEntryData().IsEmpty()) {
lua_newtable(L);
L_settable(L, -1, "kind", wxString(_T("blank")));
} else if (e->data[0] == _T(';')) {
} else if (e->GetEntryData()[0] == _T(';')) {
// semicolon comment
lua_newtable(L);
L_settable(L, -1, "kind", wxString(_T("scomment")));
L_settable(L, -1, "text", e->data.Mid(1));
L_settable(L, -1, "text", e->GetEntryData().Mid(1));
} else {
// not a blank line and not a semicolon comment
// just skip...
@ -1273,7 +1273,7 @@ void AutomationScript::process_lines(AssFile *input)
lua_newtable(L);
assert(e->Type == ENTRY_DIALOGUE);
assert(e->GetType() == ENTRY_DIALOGUE);
AssDialogue *dia = e->GetAsDialogue(e);
@ -1435,13 +1435,12 @@ void AutomationScript::process_lines(AssFile *input)
while (next != input->Line.end()) {
cur = next++;
if ((*cur)->group == _T("[Events]")) {
if ((*cur)->data == _T("[Events]")) {
if ((*cur)->GetEntryData() == _T("[Events]")) {
// skip the section header
continue;
}
if ((*cur)->Type != ENTRY_DIALOGUE &&
(*cur)->data.Mid(0,1) != _T(";") &&
(*cur)->data.Trim() != _T("")) {
wxString temp = (*cur)->GetEntryData();
if ((*cur)->GetType() != ENTRY_DIALOGUE && temp.Mid(0,1) != _T(";") && temp.Trim() != _T("")) {
// skip non-dialogue non-semicolon comment lines (such as Format)
continue;
}

View File

@ -511,7 +511,7 @@ void DialogStyleManager::OnCurrentCopy (wxCommandEvent &event) {
wxArrayInt selections;
int n = CurrentList->GetSelections(selections);
AssStyle *temp = new AssStyle(styleMap.at(selections[0])->data);
AssStyle *temp = new AssStyle(styleMap.at(selections[0])->GetEntryData());
wxString newName = _("Copy of ");
newName += temp->name;
temp->name = newName;

View File

@ -73,17 +73,17 @@ void AssTransformCleanInfoFilter::ProcessSubs(AssFile *subs) {
if (curEntry->group != _T("[Script Info]")) {
continue;
}
if (curEntry->data.IsEmpty()) {
if (curEntry->GetEntryData().IsEmpty()) {
continue;
}
if (curEntry->data == _T("[Script Info]")) {
if (curEntry->GetEntryData() == _T("[Script Info]")) {
continue;
}
if (curEntry->data.Left(1) == _T(";")) {
if (curEntry->GetEntryData().Left(1) == _T(";")) {
continue;
}
wxString field = curEntry->data.Left(curEntry->data.Find(_T(':')));
wxString field = curEntry->GetEntryData().Left(curEntry->GetEntryData().Find(_T(':')));
if (field != _T("ScriptType") &&
field != _T("Collisions") &&
field != _T("PlayResX") &&

View File

@ -169,7 +169,7 @@ void FrameMain::OnVideoTrackSplitLine(wxCommandEvent &event) {
FexMovementFrame f = curline->Movement->Frames[localframe];
// f.Pos.x /= videoBox->videoDisplay->GetW
AssDialogue *cur = new AssDialogue( curline->data );
AssDialogue *cur = new AssDialogue( curline->GetEntryData() );
cur->Start.SetMS(VFR_Output.GetTimeAtFrame(Frame,true));
cur->End.SetMS(VFR_Output.GetTimeAtFrame(Frame,false));
cur->Text = wxString::Format( _T("{\\pos(%.0f,%.0f)\\fscx%.2f\\fscy%.2f}"), f.Pos.x*sx, f.Pos.y*sy, f.Scale.x*100, f.Scale.y*100 ) + cur->Text;

View File

@ -717,7 +717,7 @@ void SubtitlesGrid::CopyLines(wxArrayInt target) {
if (!first) data += _T("\r\n");
first = false;
cur = GetDialogue(target[i]);
data += cur->data;
data += cur->GetEntryData();
}
// Send to clipboard
@ -950,7 +950,7 @@ void SubtitlesGrid::DuplicateLines(int n1,int n2,bool nextFrame) {
// Create
if (i == n2) update = true;
//cur = new AssDialogue(GetDialogue(i+step)->data);
cur = new AssDialogue(GetDialogue(i)->data);
cur = new AssDialogue(GetDialogue(i)->GetEntryData());
// Shift to next frame
if (nextFrame) {
@ -1023,7 +1023,7 @@ void SubtitlesGrid::SplitLine(int n,int pos,int mode) {
// Split
AssDialogue *n1,*n2;
n1 = GetDialogue(n);
n2 = new AssDialogue(n1->data);
n2 = new AssDialogue(n1->GetEntryData());
InsertLine(n2,n,true,false);
// Modify text