Store AssOverrideTags directly rather than a vector of pointers

This commit is contained in:
Thomas Goyne 2012-12-10 15:32:36 -08:00
parent a0d3b8595f
commit 8c2062f0c7
16 changed files with 83 additions and 75 deletions

View file

@ -41,7 +41,6 @@
#include <wx/tokenzr.h> #include <wx/tokenzr.h>
#include "ass_dialogue.h" #include "ass_dialogue.h"
#include "ass_override.h"
#include "compat.h" #include "compat.h"
#include "subtitle_format.h" #include "subtitle_format.h"
#include "utils.h" #include "utils.h"
@ -226,9 +225,9 @@ std::auto_ptr<boost::ptr_vector<AssDialogueBlock>> AssDialogue::ParseTags() cons
Blocks.push_back(block); Blocks.push_back(block);
// Look for \p in block // Look for \p in block
for (auto tag : block->Tags) { for (auto const& tag : block->Tags) {
if (tag->Name == "\\p") if (tag.Name == "\\p")
drawingLevel = tag->Params[0].Get<int>(0); drawingLevel = tag.Params[0].Get<int>(0);
} }
} }
@ -274,9 +273,9 @@ void AssDialogue::StripTag(wxString const& tag_name) {
AssDialogueBlockOverride *over = static_cast<AssDialogueBlockOverride*>(&block); AssDialogueBlockOverride *over = static_cast<AssDialogueBlockOverride*>(&block);
wxString temp; wxString temp;
for (auto tag : over->Tags) { for (auto const& tag : over->Tags) {
if (tag->Name != tag_name) if (tag.Name != tag_name)
temp += *tag; temp += tag;
} }
if (!temp.empty()) if (!temp.empty())

View file

@ -33,6 +33,7 @@
/// ///
#include "ass_entry.h" #include "ass_entry.h"
#include "ass_override.h"
#include "ass_time.h" #include "ass_time.h"
#include <libaegisub/exception.h> #include <libaegisub/exception.h>
@ -105,7 +106,7 @@ public:
AssDialogueBlockOverride(wxString const& text = wxString()) : AssDialogueBlock(text) { } AssDialogueBlockOverride(wxString const& text = wxString()) : AssDialogueBlock(text) { }
~AssDialogueBlockOverride(); ~AssDialogueBlockOverride();
std::vector<AssOverrideTag *> Tags; std::vector<AssOverrideTag> Tags;
AssBlockType GetType() const override { return BLOCK_OVERRIDE; } AssBlockType GetType() const override { return BLOCK_OVERRIDE; }
wxString GetText() override; wxString GetText() override;

View file

@ -47,7 +47,6 @@
#include "ass_attachment.h" #include "ass_attachment.h"
#include "ass_dialogue.h" #include "ass_dialogue.h"
#include "ass_info.h" #include "ass_info.h"
#include "ass_override.h"
#include "ass_style.h" #include "ass_style.h"
#include "compat.h" #include "compat.h"
#include "main.h" #include "main.h"

View file

@ -25,7 +25,6 @@
#include "ass_dialogue.h" #include "ass_dialogue.h"
#include "ass_file.h" #include "ass_file.h"
#include "ass_override.h"
#include "include/aegisub/context.h" #include "include/aegisub/context.h"
#include "selection_controller.h" #include "selection_controller.h"
@ -120,8 +119,8 @@ void AssKaraoke::ParseSyllables(AssDialogue *line, Syllable &syl) {
} }
else if (AssDialogueBlockOverride *ovr = dynamic_cast<AssDialogueBlockOverride*>(&block)) { else if (AssDialogueBlockOverride *ovr = dynamic_cast<AssDialogueBlockOverride*>(&block)) {
bool in_tag = false; bool in_tag = false;
for (auto tag : ovr->Tags) { for (auto& tag : ovr->Tags) {
if (tag->IsValid() && tag->Name.Left(2).Lower() == "\\k") { if (tag.IsValid() && tag.Name.Left(2).Lower() == "\\k") {
if (in_tag) { if (in_tag) {
syl.ovr_tags[syl.text.size()] += "}"; syl.ovr_tags[syl.text.size()] += "}";
in_tag = false; in_tag = false;
@ -129,7 +128,7 @@ void AssKaraoke::ParseSyllables(AssDialogue *line, Syllable &syl) {
// Dealing with both \K and \kf is mildly annoying so just // Dealing with both \K and \kf is mildly annoying so just
// convert them both to \kf // convert them both to \kf
if (tag->Name == "\\K") tag->Name = "\\kf"; if (tag.Name == "\\K") tag.Name = "\\kf";
// Don't bother including zero duration zero length syls // Don't bother including zero duration zero length syls
if (syl.duration > 0 || !syl.text.empty()) { if (syl.duration > 0 || !syl.text.empty()) {
@ -138,9 +137,9 @@ void AssKaraoke::ParseSyllables(AssDialogue *line, Syllable &syl) {
syl.ovr_tags.clear(); syl.ovr_tags.clear();
} }
syl.tag_type = tag->Name; syl.tag_type = tag.Name;
syl.start_time += syl.duration; syl.start_time += syl.duration;
syl.duration = tag->Params[0].Get(0) * 10; syl.duration = tag.Params[0].Get(0) * 10;
} }
else { else {
wxString& otext = syl.ovr_tags[syl.text.size()]; wxString& otext = syl.ovr_tags[syl.text.size()];
@ -151,7 +150,7 @@ void AssKaraoke::ParseSyllables(AssDialogue *line, Syllable &syl) {
otext += "{"; otext += "{";
in_tag = true; in_tag = true;
otext += *tag; otext += tag;
} }
} }

View file

@ -35,10 +35,10 @@
#include "config.h" #include "config.h"
#include "ass_dialogue.h"
#include <libaegisub/log.h> #include <libaegisub/log.h>
#include "ass_dialogue.h"
#include "ass_override.h"
#include "compat.h" #include "compat.h"
#include "utils.h" #include "utils.h"
@ -65,6 +65,14 @@ AssOverrideParameter::AssOverrideParameter(AssOverrideParameter&& o)
{ {
} }
AssOverrideParameter& AssOverrideParameter::operator=(AssOverrideParameter&& rhs) {
value = std::move(rhs.value);
block = std::move(rhs.block);
type = rhs.type;
classification = rhs.classification;
return *this;
}
AssOverrideParameter::~AssOverrideParameter() { AssOverrideParameter::~AssOverrideParameter() {
} }
@ -179,7 +187,6 @@ struct AssOverrideTagProto {
void Set(wxString name, VariableDataType type, AssParameterClass classi = PARCLASS_NORMAL, int opt = NOT_OPTIONAL); void Set(wxString name, VariableDataType type, AssParameterClass classi = PARCLASS_NORMAL, int opt = NOT_OPTIONAL);
}; };
AssOverrideParamProto::AssOverrideParamProto(VariableDataType type, int opt, AssParameterClass classi) AssOverrideParamProto::AssOverrideParamProto(VariableDataType type, int opt, AssParameterClass classi)
: optional(opt) : optional(opt)
, type(type) , type(type)
@ -404,7 +411,6 @@ void parse_parameters(AssOverrideTag *tag, const wxString &text, AssOverrideTagP
for (auto& curproto : proto_it->params) { for (auto& curproto : proto_it->params) {
// Create parameter // Create parameter
tag->Params.emplace_back(curproto.type, curproto.classification); tag->Params.emplace_back(curproto.type, curproto.classification);
AssOverrideParameter *newparam = &tag->Params.back();
// Check if it's optional and not present // Check if it's optional and not present
if (!(curproto.optional & parsFlag) || curPar >= totalPars) if (!(curproto.optional & parsFlag) || curPar >= totalPars)
@ -418,11 +424,10 @@ void parse_parameters(AssOverrideTag *tag, const wxString &text, AssOverrideTagP
// From ass_dialogue.h // From ass_dialogue.h
AssDialogueBlockOverride::~AssDialogueBlockOverride() { AssDialogueBlockOverride::~AssDialogueBlockOverride() {
delete_clear(Tags);
} }
void AssDialogueBlockOverride::ParseTags() { void AssDialogueBlockOverride::ParseTags() {
delete_clear(Tags); Tags.clear();
wxStringTokenizer tkn(text, "\\", wxTOKEN_STRTOK); wxStringTokenizer tkn(text, "\\", wxTOKEN_STRTOK);
wxString curTag; wxString curTag;
@ -435,27 +440,28 @@ void AssDialogueBlockOverride::ParseTags() {
while (curTag.Freq('(') > curTag.Freq(')') && tkn.HasMoreTokens()) while (curTag.Freq('(') > curTag.Freq(')') && tkn.HasMoreTokens())
curTag << "\\" << tkn.GetNextToken(); curTag << "\\" << tkn.GetNextToken();
Tags.push_back(new AssOverrideTag(curTag)); Tags.emplace_back(curTag);
curTag = "\\"; curTag = "\\";
} }
} }
void AssDialogueBlockOverride::AddTag(wxString const& tag) { void AssDialogueBlockOverride::AddTag(wxString const& tag) {
Tags.push_back(new AssOverrideTag(tag)); Tags.emplace_back(tag);
} }
static wxString tag_str(AssOverrideTag *t) { return *t; } static wxString tag_str(AssOverrideTag const& t) { return t; }
wxString AssDialogueBlockOverride::GetText() { wxString AssDialogueBlockOverride::GetText() {
text = "{" + join(Tags | transformed(tag_str), wxString()) + "}"; text = "{" + join(Tags | transformed(tag_str), wxString()) + "}";
return text; return text;
} }
void AssDialogueBlockOverride::ProcessParameters(ProcessParametersCallback callback, void *userData) { void AssDialogueBlockOverride::ProcessParameters(ProcessParametersCallback callback, void *userData) {
for (auto tag : Tags) { for (auto& tag : Tags) {
for (auto& par : tag->Params) { for (auto& par : tag.Params) {
if (par.omitted) continue; if (par.omitted) continue;
callback(tag->Name, &par, userData); callback(tag.Name, &par, userData);
// Go recursive if it's a block parameter // Go recursive if it's a block parameter
if (par.GetType() == VARDATA_BLOCK) if (par.GetType() == VARDATA_BLOCK)
@ -465,9 +471,22 @@ void AssDialogueBlockOverride::ProcessParameters(ProcessParametersCallback callb
} }
AssOverrideTag::AssOverrideTag() : valid(false) { } AssOverrideTag::AssOverrideTag() : valid(false) { }
AssOverrideTag::AssOverrideTag(wxString text) { AssOverrideTag::AssOverrideTag(wxString const& text) {
SetText(text); SetText(text);
} }
AssOverrideTag::AssOverrideTag(AssOverrideTag&& rhs)
: valid(rhs.valid)
, Name(std::move(rhs.Name))
, Params(std::move(rhs.Params))
{
}
AssOverrideTag& AssOverrideTag::operator=(AssOverrideTag&& rhs) {
valid = rhs.valid;
Name = std::move(rhs.Name);
Params = std::move(rhs.Params);
return *this;
}
void AssOverrideTag::Clear() { void AssOverrideTag::Clear() {
Params.clear(); Params.clear();

View file

@ -70,6 +70,7 @@ class AssOverrideParameter : boost::noncopyable {
public: public:
AssOverrideParameter(VariableDataType type, AssParameterClass classification); AssOverrideParameter(VariableDataType type, AssParameterClass classification);
AssOverrideParameter(AssOverrideParameter&&); AssOverrideParameter(AssOverrideParameter&&);
AssOverrideParameter& operator=(AssOverrideParameter&&);
~AssOverrideParameter(); ~AssOverrideParameter();
/// Type of parameter /// Type of parameter
@ -90,12 +91,14 @@ class AssOverrideTag : boost::noncopyable {
bool valid; bool valid;
public: public:
AssOverrideTag();
AssOverrideTag(AssOverrideTag&&);
AssOverrideTag(wxString const& text);
AssOverrideTag& operator=(AssOverrideTag&&);
wxString Name; wxString Name;
std::vector<AssOverrideParameter> Params; std::vector<AssOverrideParameter> Params;
AssOverrideTag();
AssOverrideTag(wxString text);
bool IsValid() const { return valid; } bool IsValid() const { return valid; }
void Clear(); void Clear();
void SetText(const wxString &text); void SetText(const wxString &text);

View file

@ -41,7 +41,6 @@
#include "ass_dialogue.h" #include "ass_dialogue.h"
#include "ass_file.h" #include "ass_file.h"
#include "ass_karaoke.h" #include "ass_karaoke.h"
#include "ass_override.h"
#include "audio_box.h" #include "audio_box.h"
#include "audio_controller.h" #include "audio_controller.h"
#include "audio_timing.h" #include "audio_timing.h"

View file

@ -52,7 +52,6 @@
#include "ass_info.h" #include "ass_info.h"
#include "ass_file.h" #include "ass_file.h"
#include "ass_karaoke.h" #include "ass_karaoke.h"
#include "ass_override.h"
#include "ass_style.h" #include "ass_style.h"
#include "auto4_lua.h" #include "auto4_lua.h"
#include "utils.h" #include "utils.h"

View file

@ -47,7 +47,6 @@
#include "../ass_dialogue.h" #include "../ass_dialogue.h"
#include "../ass_file.h" #include "../ass_file.h"
#include "../ass_karaoke.h" #include "../ass_karaoke.h"
#include "../ass_override.h"
#include "../ass_style.h" #include "../ass_style.h"
#include "../dialog_colorpicker.h" #include "../dialog_colorpicker.h"
#include "../dialog_paste_over.h" #include "../dialog_paste_over.h"
@ -169,9 +168,9 @@ void paste_lines(agi::Context *c, bool paste_over) {
template<class T> template<class T>
T get_value(boost::ptr_vector<AssDialogueBlock> const& blocks, int blockn, T initial, wxString const& tag_name, wxString alt = wxString()) { T get_value(boost::ptr_vector<AssDialogueBlock> const& blocks, int blockn, T initial, wxString const& tag_name, wxString alt = wxString()) {
for (auto ovr : blocks | sliced(0, blockn + 1) | reversed | agi::of_type<AssDialogueBlockOverride>()) { for (auto ovr : blocks | sliced(0, blockn + 1) | reversed | agi::of_type<AssDialogueBlockOverride>()) {
for (auto tag : ovr->Tags | reversed) { for (auto const& tag : ovr->Tags | reversed) {
if (tag->Name == tag_name || tag->Name == alt) if (tag.Name == tag_name || tag.Name == alt)
return tag->Params[0].Get<T>(initial); return tag.Params[0].Get<T>(initial);
} }
} }
return initial; return initial;
@ -238,16 +237,15 @@ void set_tag(AssDialogue *line, boost::ptr_vector<AssDialogueBlock> &blocks, wxS
// Remove old of same // Remove old of same
bool found = false; bool found = false;
for (size_t i = 0; i < ovr->Tags.size(); i++) { for (size_t i = 0; i < ovr->Tags.size(); i++) {
wxString name = ovr->Tags[i]->Name; wxString name = ovr->Tags[i].Name;
if (tag == name || alt == name) { if (tag == name || alt == name) {
shift -= ((wxString)*ovr->Tags[i]).size(); shift -= ((wxString)ovr->Tags[i]).size();
if (found) { if (found) {
delete ovr->Tags[i];
ovr->Tags.erase(ovr->Tags.begin() + i); ovr->Tags.erase(ovr->Tags.begin() + i);
i--; i--;
} }
else { else {
ovr->Tags[i]->Params[0].Set(value); ovr->Tags[i].Params[0].Set(value);
found = true; found = true;
} }
} }

View file

@ -33,7 +33,6 @@
#include "ass_dialogue.h" #include "ass_dialogue.h"
#include "ass_file.h" #include "ass_file.h"
#include "ass_override.h"
#include "ass_style.h" #include "ass_style.h"
#include "include/aegisub/context.h" #include "include/aegisub/context.h"
#include "help_button.h" #include "help_button.h"

View file

@ -44,7 +44,6 @@
#include "ass_dialogue.h" #include "ass_dialogue.h"
#include "ass_file.h" #include "ass_file.h"
#include "ass_override.h"
#include "ass_style.h" #include "ass_style.h"
#include "ass_style_storage.h" #include "ass_style_storage.h"
#include "colour_button.h" #include "colour_button.h"

View file

@ -46,7 +46,6 @@
#include "ass_dialogue.h" #include "ass_dialogue.h"
#include "ass_file.h" #include "ass_file.h"
#include "ass_override.h"
#include "export_framerate.h" #include "export_framerate.h"
#include "include/aegisub/context.h" #include "include/aegisub/context.h"
#include "utils.h" #include "utils.h"

View file

@ -25,7 +25,6 @@
#include "ass_dialogue.h" #include "ass_dialogue.h"
#include "ass_file.h" #include "ass_file.h"
#include "ass_override.h"
#include "ass_style.h" #include "ass_style.h"
#include "utils.h" #include "utils.h"
@ -56,23 +55,23 @@ void FontCollector::ProcessDialogueLine(const AssDialogue *line, int index) {
for (auto& block : blocks) { for (auto& block : blocks) {
if (AssDialogueBlockOverride *ovr = dynamic_cast<AssDialogueBlockOverride *>(&block)) { if (AssDialogueBlockOverride *ovr = dynamic_cast<AssDialogueBlockOverride *>(&block)) {
for (auto tag : ovr->Tags) { for (auto const& tag : ovr->Tags) {
wxString name = tag->Name; wxString name = tag.Name;
if (name == "\\r") { if (name == "\\r") {
style = styles[tag->Params[0].Get<wxString>(line->Style)]; style = styles[tag.Params[0].Get<wxString>(line->Style)];
overriden = false; overriden = false;
} }
else if (name == "\\b") { else if (name == "\\b") {
style.bold = tag->Params[0].Get(initial.bold); style.bold = tag.Params[0].Get(initial.bold);
overriden = true; overriden = true;
} }
else if (name == "\\i") { else if (name == "\\i") {
style.italic = tag->Params[0].Get(initial.italic); style.italic = tag.Params[0].Get(initial.italic);
overriden = true; overriden = true;
} }
else if (name == "\\fn") { else if (name == "\\fn") {
style.facename = tag->Params[0].Get(initial.facename); style.facename = tag.Params[0].Get(initial.facename);
overriden = true; overriden = true;
} }
} }

View file

@ -37,7 +37,6 @@
#include "aegisub_endian.h" #include "aegisub_endian.h"
#include "ass_dialogue.h" #include "ass_dialogue.h"
#include "ass_file.h" #include "ass_file.h"
#include "ass_override.h"
#include "ass_style.h" #include "ass_style.h"
#include "compat.h" #include "compat.h"
#include "dialog_export_ebu3264.h" #include "dialog_export_ebu3264.h"
@ -122,16 +121,16 @@ namespace
{ {
void ProcessOverrides(AssDialogueBlockOverride *ob, bool &underline, bool &italic, int &align, bool style_underline, bool style_italic) void ProcessOverrides(AssDialogueBlockOverride *ob, bool &underline, bool &italic, int &align, bool style_underline, bool style_italic)
{ {
for (auto t : ob->Tags) for (auto const& t : ob->Tags)
{ {
if (t->Name == "\\u") if (t.Name == "\\u")
underline = t->Params[0].Get<bool>(style_underline); underline = t.Params[0].Get<bool>(style_underline);
else if (t->Name == "\\i") else if (t.Name == "\\i")
italic = t->Params[0].Get<bool>(style_italic); italic = t.Params[0].Get<bool>(style_italic);
else if (t->Name == "\\an") else if (t.Name == "\\an")
align = t->Params[0].Get<int>(align); align = t.Params[0].Get<int>(align);
else if (t->Name == "\\a" && !t->Params[0].omitted) else if (t.Name == "\\a" && !t.Params[0].omitted)
align = AssStyle::SsaToAss(t->Params[0].Get<int>()); align = AssStyle::SsaToAss(t.Params[0].Get<int>());
} }
} }

View file

@ -39,7 +39,6 @@
#include "ass_attachment.h" #include "ass_attachment.h"
#include "ass_dialogue.h" #include "ass_dialogue.h"
#include "ass_file.h" #include "ass_file.h"
#include "ass_override.h"
#include "ass_style.h" #include "ass_style.h"
#include "colorspace.h" #include "colorspace.h"
#include "compat.h" #include "compat.h"
@ -535,8 +534,8 @@ bool SRTSubtitleFormat::CanSave(const AssFile *file) const {
boost::ptr_vector<AssDialogueBlock> blocks(curdiag->ParseTags()); boost::ptr_vector<AssDialogueBlock> blocks(curdiag->ParseTags());
for (auto ovr : blocks | agi::of_type<AssDialogueBlockOverride>()) { for (auto ovr : blocks | agi::of_type<AssDialogueBlockOverride>()) {
// Verify that all overrides used are supported // Verify that all overrides used are supported
for (auto tag : ovr->Tags) { for (auto const& tag : ovr->Tags) {
if (!std::binary_search(supported_tags, std::end(supported_tags), tag->Name)) if (!std::binary_search(supported_tags, std::end(supported_tags), tag.Name))
return false; return false;
} }
} }
@ -559,11 +558,11 @@ wxString SRTSubtitleFormat::ConvertTags(const AssDialogue *diag) const {
for (auto& block : blocks) { for (auto& block : blocks) {
if (AssDialogueBlockOverride* ovr = dynamic_cast<AssDialogueBlockOverride*>(&block)) { if (AssDialogueBlockOverride* ovr = dynamic_cast<AssDialogueBlockOverride*>(&block)) {
// Iterate through overrides // Iterate through overrides
for (auto tag : ovr->Tags) { for (auto const& tag : ovr->Tags) {
if (tag->IsValid() && tag->Name.size() == 2) { if (tag.IsValid() && tag.Name.size() == 2) {
auto it = tag_states.find(tag->Name[1]); auto it = tag_states.find(tag.Name[1]);
if (it != tag_states.end()) { if (it != tag_states.end()) {
bool temp = tag->Params[0].Get(false); bool temp = tag.Params[0].Get(false);
if (temp && !it->second) if (temp && !it->second)
final += wxString::Format("<%c>", it->first); final += wxString::Format("<%c>", it->first);
if (!temp && it->second) if (!temp && it->second)

View file

@ -26,7 +26,6 @@
#include "ass_dialogue.h" #include "ass_dialogue.h"
#include "ass_file.h" #include "ass_file.h"
#include "ass_override.h"
#include "ass_style.h" #include "ass_style.h"
#include "ass_time.h" #include "ass_time.h"
#include "include/aegisub/context.h" #include "include/aegisub/context.h"
@ -360,9 +359,9 @@ typedef const std::vector<AssOverrideParameter> * param_vec;
// Find a tag's parameters in a line or return nullptr if it's not found // Find a tag's parameters in a line or return nullptr if it's not found
static param_vec find_tag(boost::ptr_vector<AssDialogueBlock>& blocks, wxString tag_name) { static param_vec find_tag(boost::ptr_vector<AssDialogueBlock>& blocks, wxString tag_name) {
for (auto ovr : blocks | agi::of_type<AssDialogueBlockOverride>()) { for (auto ovr : blocks | agi::of_type<AssDialogueBlockOverride>()) {
for (auto tag : ovr->Tags) { for (auto const& tag : ovr->Tags) {
if (tag->Name == tag_name) if (tag.Name == tag_name)
return &tag->Params; return &tag.Params;
} }
} }
@ -566,9 +565,8 @@ void VisualToolBase::SetOverride(AssDialogue* line, wxString const& tag, wxStrin
else if (AssDialogueBlockOverride *ovr = dynamic_cast<AssDialogueBlockOverride*>(block)) { else if (AssDialogueBlockOverride *ovr = dynamic_cast<AssDialogueBlockOverride*>(block)) {
// Remove old of same // Remove old of same
for (size_t i = 0; i < ovr->Tags.size(); i++) { for (size_t i = 0; i < ovr->Tags.size(); i++) {
wxString const& name = ovr->Tags[i]->Name; wxString const& name = ovr->Tags[i].Name;
if (tag == name || removeTag == name) { if (tag == name || removeTag == name) {
delete ovr->Tags[i];
ovr->Tags.erase(ovr->Tags.begin() + i); ovr->Tags.erase(ovr->Tags.begin() + i);
i--; i--;
} }