Added clone function for better copying of AssEntry and derived classes

Originally committed to SVN as r184.
This commit is contained in:
Rodrigo Braz Monteiro 2006-02-27 09:07:08 +00:00
parent 3c27496b29
commit 2d9574952e
7 changed files with 92 additions and 1 deletions

View File

@ -727,6 +727,35 @@ bool AssDialogue::CollidesWith(AssDialogue *target) {
}
/////////
// Clone
AssEntry *AssDialogue::Clone() {
// Create clone
AssDialogue *final = new AssDialogue();
// Copy data
final->group = group;
final->StartMS = StartMS;
final->Valid = Valid;
final->Actor = Actor;
final->Comment = Comment;
final->Effect = Effect;
final->End = End;
final->Layer = Layer;
final->MarginL = MarginL;
final->MarginR = MarginR;
final->MarginV = MarginV;
final->Start = Start;
final->StartMS = final->StartMS;
final->Style = Style;
final->Text = Text;
final->SetEntryData(GetEntryData());
// Return
return final;
}
////////////////////// AssDialogueBlock //////////////////////
///////////////
// Constructor

View File

@ -200,6 +200,8 @@ public:
bool CollidesWith(AssDialogue *target); // Checks if two lines collide
void ClearBlocks();
AssEntry *Clone();
AssDialogue();
AssDialogue(wxString data,bool IsSSA=false);
~AssDialogue();

View File

@ -100,3 +100,20 @@ wxString AssEntry::GetSSAText() {
}
return data;
}
/////////
// Clone
AssEntry *AssEntry::Clone() {
// Create clone
AssEntry *final = new AssEntry();
// Copy data
final->data = data;
final->group = group;
final->StartMS = StartMS;
final->Valid = Valid;
// Return
return final;
}

View File

@ -72,6 +72,8 @@ public:
AssEntry(wxString data);
virtual ~AssEntry();
virtual AssEntry *Clone();
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; }

View File

@ -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)->GetEntryData(),(*cur)->group,lasttime,IsSSA);
Line.push_back((*cur)->Clone());
}
// Add comments

View File

@ -524,3 +524,42 @@ wxString AssStyle::GetSSAText() {
return output;
}
/////////
// Clone
AssEntry *AssStyle::Clone() {
// Create clone
AssStyle *final = new AssStyle();
// Copy data
final->group = group;
final->StartMS = StartMS;
final->Valid = Valid;
final->alignment = alignment;
final->angle = angle;
final->bold = bold;
final->borderstyle = borderstyle;
final->encoding = encoding;
final->font = font;
final->fontsize = fontsize;
final->italic = italic;
final->MarginL = MarginL;
final->MarginR = MarginR;
final->MarginV = MarginV;
final->name = name;
final->outline = outline;
final->outline_w = outline_w;
final->primary = primary;
final->scalex = scalex;
final->scaley = scaley;
final->secondary = secondary;
final->shadow = shadow;
final->spacing = spacing;
final->strikeout = strikeout;
final->underline = underline;
final->SetEntryData(GetEntryData());
// Return
return final;
}

View File

@ -102,6 +102,8 @@ public:
wxString GetMarginString(int which); // Returns the margin value as a string (1 = left, 2 = right, 3 = vertical)
void SetMarginString(const wxString value,int which); // Sets margin value from a string (1 = left, 2 = right, 3 = vertical)
AssEntry *Clone();
AssStyle();
AssStyle(wxString data,bool IsSSA=false);
~AssStyle();