A little more athenasub refactoring.

Originally committed to SVN as r2461.
This commit is contained in:
Rodrigo Braz Monteiro 2008-11-16 01:02:34 +00:00
parent 9280b56e34
commit 1f1261c997
5 changed files with 11 additions and 14 deletions

View file

@ -116,7 +116,7 @@ namespace Athenasub {
virtual void Clear() = 0; virtual void Clear() = 0;
virtual void Load(wxInputStream &input,Format format=Format(),const String encoding="") = 0; virtual void Load(wxInputStream &input,Format format=Format(),const String encoding="") = 0;
virtual void AddSection(String name) = 0; virtual Section AddSection(String name) = 0;
virtual Section GetMutableSection(String name) = 0; virtual Section GetMutableSection(String name) = 0;
virtual Section GetMutableSectionByIndex(size_t index) = 0; virtual Section GetMutableSectionByIndex(size_t index) = 0;

View file

@ -45,7 +45,7 @@ namespace Athenasub {
protected: protected:
virtual ~CFormatHandler() {} virtual ~CFormatHandler() {}
void AddSection(IModel &model,String name) const { model.AddSection(name); } Section AddSection(IModel &model,String name) const { return model.AddSection(name); }
ConstSection GetSection(const IModel &model,String name) const { return model.GetSection(name); } ConstSection GetSection(const IModel &model,String name) const { return model.GetSection(name); }
ConstSection GetSectionByIndex(const IModel &model,size_t index) const { return model.GetSectionByIndex(index); } ConstSection GetSectionByIndex(const IModel &model,size_t index) const { return model.GetSectionByIndex(index); }
Section GetSection(IModel &model,String name) const { return model.GetMutableSection(name); } Section GetSection(IModel &model,String name) const { return model.GetMutableSection(name); }

View file

@ -378,9 +378,7 @@ void FormatHandlerASS::MakeValid(IModel &model)
// Check for [Script Info] // Check for [Script Info]
Section section = GetSection(model,"Script Info"); Section section = GetSection(model,"Script Info");
if (!section) AddSection(model,"Script Info"); if (!section) section = AddSection(model,"Script Info");
section = GetSection(model,"Script Info");
if (!section) THROW_ATHENA_EXCEPTION(Exception::Internal_Error);
// Check if necessary variables are available // Check if necessary variables are available
if (section->GetProperty("PlayResX").IsEmpty()) section->SetProperty("PlayResX","384"); // These two mystical values come from Substation Alpha if (section->GetProperty("PlayResX").IsEmpty()) section->SetProperty("PlayResX","384"); // These two mystical values come from Substation Alpha
@ -389,15 +387,11 @@ void FormatHandlerASS::MakeValid(IModel &model)
// Get [V4+ Styles] // Get [V4+ Styles]
section = GetSection(model,"V4+ Styles"); section = GetSection(model,"V4+ Styles");
if (!section) AddSection(model,"V4+ Styles"); if (!section) section = AddSection(model,"V4+ Styles");
section = GetSection(model,"V4+ Styles");
if (!section) THROW_ATHENA_EXCEPTION(Exception::Internal_Error);
section->SetProperty("Format","Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding"); section->SetProperty("Format","Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding");
// Get [Events] // Get [Events]
section = GetSection(model,"Events"); section = GetSection(model,"Events");
if (!section) AddSection(model,"Events"); if (!section) section = AddSection(model,"Events");
section = GetSection(model,"Events");
if (!section) THROW_ATHENA_EXCEPTION(Exception::Internal_Error);
section->SetProperty("Format","Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text"); section->SetProperty("Format","Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text");
} }

View file

@ -153,11 +153,14 @@ void CModel::Save(wxOutputStream &output,const Format _format,const String encod
///////////////////////// /////////////////////////
// Inserts a new section // Inserts a new section
void CModel::AddSection(String name) Section CModel::AddSection(String name)
{ {
ConstSection prev = GetSection(name); ConstSection prev = GetSection(name);
if (prev) THROW_ATHENA_EXCEPTION(Exception::Section_Already_Exists); if (prev) THROW_ATHENA_EXCEPTION(Exception::Section_Already_Exists);
sections.push_back(Section(new CSection(name)));
Section result = Section(new CSection(name));
sections.push_back(result);
return result;
} }

View file

@ -82,7 +82,7 @@ namespace Athenasub {
void Clear(); void Clear();
void Load(wxInputStream &input,Format format=Format(),const String encoding=""); void Load(wxInputStream &input,Format format=Format(),const String encoding="");
void AddSection(String name); Section AddSection(String name);
Section GetMutableSection(String name); Section GetMutableSection(String name);
Section GetMutableSectionByIndex(size_t index); Section GetMutableSectionByIndex(size_t index);