Change AssFile::Info to a vector

This commit is contained in:
Thomas Goyne 2014-03-07 16:16:38 -08:00
parent b1639c6162
commit e64fd78c51
3 changed files with 17 additions and 19 deletions

View file

@ -32,22 +32,21 @@
AssFile::AssFile() { }
AssFile::~AssFile() {
Info.clear_and_dispose([](AssInfo *e) { delete e; });
Styles.clear_and_dispose([](AssStyle *e) { delete e; });
Events.clear_and_dispose([](AssDialogue *e) { delete e; });
Attachments.clear_and_dispose([](AssAttachment *e) { delete e; });
}
void AssFile::LoadDefault(bool include_dialogue_line) {
Info.push_back(*new AssInfo("Title", "Default Aegisub file"));
Info.push_back(*new AssInfo("ScriptType", "v4.00+"));
Info.push_back(*new AssInfo("WrapStyle", "0"));
Info.push_back(*new AssInfo("ScaledBorderAndShadow", "yes"));
Info.emplace_back("Title", "Default Aegisub file");
Info.emplace_back("ScriptType", "v4.00+");
Info.emplace_back("WrapStyle", "0");
Info.emplace_back("ScaledBorderAndShadow", "yes");
if (!OPT_GET("Subtitle/Default Resolution/Auto")->GetBool()) {
Info.push_back(*new AssInfo("PlayResX", std::to_string(OPT_GET("Subtitle/Default Resolution/Width")->GetInt())));
Info.push_back(*new AssInfo("PlayResY", std::to_string(OPT_GET("Subtitle/Default Resolution/Height")->GetInt())));
Info.emplace_back("PlayResX", std::to_string(OPT_GET("Subtitle/Default Resolution/Width")->GetInt()));
Info.emplace_back("PlayResY", std::to_string(OPT_GET("Subtitle/Default Resolution/Height")->GetInt()));
}
Info.push_back(*new AssInfo("YCbCr Matrix", "None"));
Info.emplace_back("YCbCr Matrix", "None");
Styles.push_back(*new AssStyle);
@ -55,8 +54,9 @@ void AssFile::LoadDefault(bool include_dialogue_line) {
Events.push_back(*new AssDialogue);
}
AssFile::AssFile(const AssFile &from) {
Info.clone_from(from.Info, std::mem_fun_ref(&AssInfo::Clone), [](AssInfo *e) { delete e; });
AssFile::AssFile(const AssFile &from)
: Info(from.Info)
{
Styles.clone_from(from.Styles, std::mem_fun_ref(&AssStyle::Clone), [](AssStyle *e) { delete e; });
Events.clone_from(from.Events, std::mem_fun_ref(&AssDialogue::Clone), [](AssDialogue *e) { delete e; });
Attachments.clone_from(from.Attachments, std::mem_fun_ref(&AssAttachment::Clone), [](AssAttachment *e) { delete e; });
@ -114,18 +114,18 @@ void AssFile::SaveUIState(std::string const& key, std::string const& value) {
}
void AssFile::SetScriptInfo(std::string const& key, std::string const& value) {
for (auto& info : Info) {
if (boost::iequals(key, info.Key())) {
for (auto it = Info.begin(); it != Info.end(); ++it) {
if (boost::iequals(key, it->Key())) {
if (value.empty())
delete &info;
Info.erase(it);
else
info.SetValue(value);
it->SetValue(value);
return;
}
}
if (!value.empty())
Info.push_back(*new AssInfo(key, value));
Info.emplace_back(key, value);
}
void AssFile::GetResolution(int &sw, int &sh) const {

View file

@ -50,9 +50,6 @@ class wxString;
template<typename T>
using EntryList = typename boost::intrusive::make_list<T, boost::intrusive::constant_time_size<false>, boost::intrusive::base_hook<AssEntry>>::type;
template<typename T>
using EntryIter = typename EntryList<T>::iterator;
struct AssFileCommit {
wxString const& message;
int *commit_id;
@ -65,7 +62,7 @@ class AssFile {
agi::signal::Signal<AssFileCommit> PushState;
public:
/// The lines in the file
EntryList<AssInfo> Info;
std::vector<AssInfo> Info;
EntryList<AssStyle> Styles;
EntryList<AssDialogue> Events;
EntryList<AssAttachment> Attachments;

View file

@ -39,6 +39,7 @@
#include "auto4_lua_utils.h"
#include "ass_attachment.h"
#include "ass_dialogue.h"
#include "ass_info.h"
#include "ass_file.h"
#include "ass_style.h"
#include "auto4_lua_factory.h"