Store AssOverrideParameters directly rather than a vector of pointers to them

This commit is contained in:
Thomas Goyne 2012-12-09 08:29:02 -08:00
parent 851f7f40e6
commit d2a0a76ca9
9 changed files with 48 additions and 53 deletions

View File

@ -228,7 +228,7 @@ std::auto_ptr<boost::ptr_vector<AssDialogueBlock>> AssDialogue::ParseTags() cons
// Look for \p in block
for (auto tag : block->Tags) {
if (tag->Name == "\\p")
drawingLevel = tag->Params[0]->Get<int>(0);
drawingLevel = tag->Params[0].Get<int>(0);
}
}

View File

@ -140,7 +140,7 @@ void AssKaraoke::ParseSyllables(AssDialogue *line, Syllable &syl) {
syl.tag_type = tag->Name;
syl.start_time += syl.duration;
syl.duration = tag->Params[0]->Get(0) * 10;
syl.duration = tag->Params[0].Get(0) * 10;
}
else {
wxString& otext = syl.ovr_tags[syl.text.size()];

View File

@ -100,14 +100,14 @@ wxString AssDialogueBlockOverride::GetText() {
void AssDialogueBlockOverride::ProcessParameters(ProcessParametersCallback callback, void *userData) {
for (auto tag : Tags) {
for (auto par : tag->Params) {
if (par->GetType() == VARDATA_NONE || par->omitted) continue;
for (auto& par : tag->Params) {
if (par.GetType() == VARDATA_NONE || par.omitted) continue;
callback(tag->Name, par, userData);
callback(tag->Name, &par, userData);
// Go recursive if it's a block parameter
if (par->GetType() == VARDATA_BLOCK)
par->Get<AssDialogueBlockOverride*>()->ProcessParameters(callback, userData);
if (par.GetType() == VARDATA_BLOCK)
par.Get<AssDialogueBlockOverride*>()->ProcessParameters(callback, userData);
}
}
}
@ -269,12 +269,8 @@ AssOverrideTag::AssOverrideTag(wxString text) {
SetText(text);
}
AssOverrideTag::~AssOverrideTag () {
delete_clear(Params);
}
void AssOverrideTag::Clear() {
delete_clear(Params);
Params.clear();
Params.reserve(6);
valid = false;
}
@ -365,9 +361,9 @@ void AssOverrideTag::ParseParameters(const wxString &text, AssOverrideTagProto::
unsigned curPar = 0;
for (auto& curproto : proto_it->params) {
// Create parameter
AssOverrideParameter *newparam = new AssOverrideParameter;
Params.emplace_back();
AssOverrideParameter *newparam = &Params.back();
newparam->classification = curproto.classification;
Params.push_back(newparam);
// Check if it's optional and not present
if (!(curproto.optional & parsFlag) || curPar >= totalPars) {
@ -423,7 +419,7 @@ void AssOverrideTag::ParseParameters(const wxString &text, AssOverrideTagProto::
}
}
static wxString param_str(AssOverrideParameter *p) { return p->Get<wxString>(); }
static wxString param_str(AssOverrideParameter const& p) { return p.Get<wxString>(); }
AssOverrideTag::operator wxString() const {
wxString result = Name;
@ -433,7 +429,7 @@ AssOverrideTag::operator wxString() const {
// Add parameters
result += join(Params
| filtered([](AssOverrideParameter *p) { return p->GetType() != VARDATA_NONE && !p->omitted; })
| filtered([](AssOverrideParameter const& p) { return p.GetType() != VARDATA_NONE && !p.omitted; })
| transformed(param_str),
wxS(","));

View File

@ -113,16 +113,15 @@ struct AssOverrideTagProto {
void Set(wxString name, VariableDataType type, AssParameterClass classi = PARCLASS_NORMAL, int opt = NOT_OPTIONAL);
};
class AssOverrideTag {
class AssOverrideTag : boost::noncopyable {
bool valid;
public:
wxString Name;
std::vector<AssOverrideParameter*> Params;
std::vector<AssOverrideParameter> Params;
AssOverrideTag();
AssOverrideTag(wxString text);
~AssOverrideTag();
bool IsValid() const { return valid; }
/// @brief Parses the parameters for the ass override tag

View File

@ -171,7 +171,7 @@ T get_value(boost::ptr_vector<AssDialogueBlock> const& blocks, int blockn, T ini
for (auto ovr : blocks | sliced(0, blockn + 1) | reversed | agi::of_type<AssDialogueBlockOverride>()) {
for (auto tag : ovr->Tags | reversed) {
if (tag->Name == tag_name || tag->Name == alt)
return tag->Params[0]->Get<T>(initial);
return tag->Params[0].Get<T>(initial);
}
}
return initial;
@ -247,8 +247,8 @@ void set_tag(AssDialogue *line, boost::ptr_vector<AssDialogueBlock> &blocks, wxS
i--;
}
else {
ovr->Tags[i]->Params[0]->Set(value);
ovr->Tags[i]->Params[0]->omitted = false;
ovr->Tags[i]->Params[0].Set(value);
ovr->Tags[i]->Params[0].omitted = false;
found = true;
}
}

View File

@ -60,19 +60,19 @@ void FontCollector::ProcessDialogueLine(const AssDialogue *line, int index) {
wxString name = tag->Name;
if (name == "\\r") {
style = styles[tag->Params[0]->Get<wxString>(line->Style)];
style = styles[tag->Params[0].Get<wxString>(line->Style)];
overriden = false;
}
else if (name == "\\b") {
style.bold = tag->Params[0]->Get(initial.bold);
style.bold = tag->Params[0].Get(initial.bold);
overriden = true;
}
else if (name == "\\i") {
style.italic = tag->Params[0]->Get(initial.italic);
style.italic = tag->Params[0].Get(initial.italic);
overriden = true;
}
else if (name == "\\fn") {
style.facename = tag->Params[0]->Get(initial.facename);
style.facename = tag->Params[0].Get(initial.facename);
overriden = true;
}
}

View File

@ -125,13 +125,13 @@ namespace
for (auto t : ob->Tags)
{
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")
italic = t->Params[0]->Get<bool>(style_italic);
italic = t->Params[0].Get<bool>(style_italic);
else if (t->Name == "\\an")
align = t->Params[0]->Get<int>(align);
else if (t->Name == "\\a" && !t->Params[0]->omitted)
align = AssStyle::SsaToAss(t->Params[0]->Get<int>());
align = t->Params[0].Get<int>(align);
else if (t->Name == "\\a" && !t->Params[0].omitted)
align = AssStyle::SsaToAss(t->Params[0].Get<int>());
}
}

View File

@ -563,7 +563,7 @@ wxString SRTSubtitleFormat::ConvertTags(const AssDialogue *diag) const {
if (tag->IsValid() && tag->Name.size() == 2) {
auto it = tag_states.find(tag->Name[1]);
if (it != tag_states.end()) {
bool temp = tag->Params[0]->Get(false);
bool temp = tag->Params[0].Get(false);
if (temp && !it->second)
final += wxString::Format("<%c>", it->first);
if (!temp && it->second)

View File

@ -355,7 +355,7 @@ void VisualTool<FeatureType>::RemoveSelection(feature_iterator feat) {
//////// PARSERS
typedef const std::vector<AssOverrideParameter*> * param_vec;
typedef const std::vector<AssOverrideParameter> * param_vec;
// 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) {
@ -373,12 +373,12 @@ static param_vec find_tag(boost::ptr_vector<AssDialogueBlock>& blocks, wxString
static Vector2D vec_or_bad(param_vec tag, size_t x_idx, size_t y_idx) {
if (!tag ||
tag->size() <= x_idx || tag->size() <= y_idx ||
(*tag)[x_idx]->omitted || (*tag)[y_idx]->omitted ||
(*tag)[x_idx]->GetType() == VARDATA_NONE || (*tag)[y_idx]->GetType() == VARDATA_NONE)
(*tag)[x_idx].omitted || (*tag)[y_idx].omitted ||
(*tag)[x_idx].GetType() == VARDATA_NONE || (*tag)[y_idx].GetType() == VARDATA_NONE)
{
return Vector2D();
}
return Vector2D((*tag)[x_idx]->Get<float>(), (*tag)[y_idx]->Get<float>());
return Vector2D((*tag)[x_idx].Get<float>(), (*tag)[y_idx].Get<float>());
}
Vector2D VisualToolBase::GetLinePosition(AssDialogue *diag) {
@ -402,10 +402,10 @@ Vector2D VisualToolBase::GetLinePosition(AssDialogue *diag) {
param_vec align_tag;
int ovr_align = 0;
if ((align_tag = find_tag(blocks, "\\an")) && !(*align_tag)[0]->omitted)
ovr_align = (*align_tag)[0]->Get<int>();
if ((align_tag = find_tag(blocks, "\\an")) && !(*align_tag)[0].omitted)
ovr_align = (*align_tag)[0].Get<int>();
else if ((align_tag = find_tag(blocks, "\\a")))
ovr_align = AssStyle::SsaToAss((*align_tag)[0]->Get<int>(2));
ovr_align = AssStyle::SsaToAss((*align_tag)[0].Get<int>(2));
if (ovr_align > 0 && ovr_align <= 9)
align = ovr_align;
@ -448,8 +448,8 @@ bool VisualToolBase::GetLineMove(AssDialogue *diag, Vector2D &p1, Vector2D &p2,
p1 = vec_or_bad(tag, 0, 1);
p2 = vec_or_bad(tag, 2, 3);
// VSFilter actually defaults to -1, but it uses <= 0 to check for default and 0 seems less bug-prone
t1 = (*tag)[4]->Get<int>(0);
t2 = (*tag)[5]->Get<int>(0);
t1 = (*tag)[4].Get<int>(0);
t2 = (*tag)[5].Get<int>(0);
return p1 && p2;
}
@ -463,13 +463,13 @@ void VisualToolBase::GetLineRotation(AssDialogue *diag, float &rx, float &ry, fl
boost::ptr_vector<AssDialogueBlock> blocks(diag->ParseTags());
if (param_vec tag = find_tag(blocks, "\\frx"))
rx = tag->front()->Get<float>(rx);
rx = tag->front().Get<float>(rx);
if (param_vec tag = find_tag(blocks, "\\fry"))
ry = tag->front()->Get<float>(ry);
ry = tag->front().Get<float>(ry);
if (param_vec tag = find_tag(blocks, "\\frz"))
rz = tag->front()->Get<float>(rz);
rz = tag->front().Get<float>(rz);
else if ((tag = find_tag(blocks, "\\fr")))
rz = tag->front()->Get<float>(rz);
rz = tag->front().Get<float>(rz);
}
void VisualToolBase::GetLineScale(AssDialogue *diag, Vector2D &scale) {
@ -483,9 +483,9 @@ void VisualToolBase::GetLineScale(AssDialogue *diag, Vector2D &scale) {
boost::ptr_vector<AssDialogueBlock> blocks(diag->ParseTags());
if (param_vec tag = find_tag(blocks, "\\fscx"))
x = tag->front()->Get<float>(x);
x = tag->front().Get<float>(x);
if (param_vec tag = find_tag(blocks, "\\fscy"))
y = tag->front()->Get<float>(y);
y = tag->front().Get<float>(y);
scale = Vector2D(x, y);
}
@ -524,14 +524,14 @@ wxString VisualToolBase::GetLineVectorClip(AssDialogue *diag, int &scale, bool &
if (tag && tag->size() == 4) {
return wxString::Format("m %d %d l %d %d %d %d %d %d",
(*tag)[0]->Get<int>(), (*tag)[1]->Get<int>(),
(*tag)[2]->Get<int>(), (*tag)[1]->Get<int>(),
(*tag)[2]->Get<int>(), (*tag)[3]->Get<int>(),
(*tag)[0]->Get<int>(), (*tag)[3]->Get<int>());
(*tag)[0].Get<int>(), (*tag)[1].Get<int>(),
(*tag)[2].Get<int>(), (*tag)[1].Get<int>(),
(*tag)[2].Get<int>(), (*tag)[3].Get<int>(),
(*tag)[0].Get<int>(), (*tag)[3].Get<int>());
}
if (tag) {
scale = std::max((*tag)[0]->Get(scale), 1);
return (*tag)[1]->Get<wxString>("");
scale = std::max((*tag)[0].Get(scale), 1);
return (*tag)[1].Get<wxString>("");
}
return "";