Templatize VariableData's getters and setters

Originally committed to SVN as r4523.
This commit is contained in:
Thomas Goyne 2010-06-16 06:20:06 +00:00
parent c7ea710267
commit 166c95975b
13 changed files with 127 additions and 228 deletions

View file

@ -486,7 +486,7 @@ void AssDialogue::ParseASSTags () {
for (curTag = block->Tags.begin();curTag != block->Tags.end();curTag++) { for (curTag = block->Tags.begin();curTag != block->Tags.end();curTag++) {
AssOverrideTag *tag = *curTag; AssOverrideTag *tag = *curTag;
if (tag->Name == _T("\\p")) { if (tag->Name == _T("\\p")) {
drawingLevel = tag->Params.at(0)->AsInt(); drawingLevel = tag->Params.at(0)->Get<int>();
} }
} }
} }
@ -591,7 +591,7 @@ void AssDialogue::ConvertTagsToSRT () {
if (curTag->IsValid()) { if (curTag->IsValid()) {
// Italics // Italics
if (curTag->Name == _T("\\i")) { if (curTag->Name == _T("\\i")) {
temp = curTag->Params.at(0)->AsBool(); temp = curTag->Params.at(0)->Get<bool>();
if (temp && !isItalic) { if (temp && !isItalic) {
isItalic = true; isItalic = true;
final += _T("<i>"); final += _T("<i>");
@ -604,7 +604,7 @@ void AssDialogue::ConvertTagsToSRT () {
// Underline // Underline
if (curTag->Name == _T("\\u")) { if (curTag->Name == _T("\\u")) {
temp = curTag->Params.at(0)->AsBool(); temp = curTag->Params.at(0)->Get<bool>();
if (temp && !isUnder) { if (temp && !isUnder) {
isUnder = true; isUnder = true;
final += _T("<u>"); final += _T("<u>");
@ -617,7 +617,7 @@ void AssDialogue::ConvertTagsToSRT () {
// Strikeout // Strikeout
if (curTag->Name == _T("\\s")) { if (curTag->Name == _T("\\s")) {
temp = curTag->Params.at(0)->AsBool(); temp = curTag->Params.at(0)->Get<bool>();
if (temp && !isStrike) { if (temp && !isStrike) {
isStrike = true; isStrike = true;
final += _T("<s>"); final += _T("<s>");
@ -630,7 +630,7 @@ void AssDialogue::ConvertTagsToSRT () {
// Bold // Bold
if (curTag->Name == _T("\\b")) { if (curTag->Name == _T("\\b")) {
temp = curTag->Params.at(0)->AsBool(); temp = curTag->Params.at(0)->Get<bool>();
if (temp && !isBold) { if (temp && !isBold) {
isBold = true; isBold = true;
final += _T("<b>"); final += _T("<b>");

View file

@ -102,7 +102,7 @@ void ParseAssKaraokeTags(const AssDialogue *line, AssKaraokeVector &syls)
syl.unstripped_text = _T(""); syl.unstripped_text = _T("");
syl.tag = tag; syl.tag = tag;
syl.type = tag->Name; syl.type = tag->Name;
syl.duration = tag->Params[0]->AsInt(); syl.duration = tag->Params[0]->Get<int>();
} else { } else {
// not karaoke tag // not karaoke tag

View file

@ -61,15 +61,7 @@ AssOverrideParameter::~AssOverrideParameter () {
/// @param param /// @param param
/// ///
void AssOverrideParameter::CopyFrom (const AssOverrideParameter &param) { void AssOverrideParameter::CopyFrom (const AssOverrideParameter &param) {
switch(param.GetType()) { *static_cast<VariableData*>(this) = static_cast<const VariableData&>(param);
case VARDATA_INT: SetInt(param.AsInt()); break;
case VARDATA_FLOAT: SetFloat(param.AsFloat()); break;
case VARDATA_TEXT: SetText(param.AsText()); break;
case VARDATA_BOOL: SetBool(param.AsBool()); break;
case VARDATA_COLOUR: SetColour(param.AsColour()); break;
case VARDATA_BLOCK: SetBlock(param.AsBlock()); break;
default: DeleteValue();
}
classification = param.classification; classification = param.classification;
ommited = param.ommited; ommited = param.ommited;
} }
@ -165,7 +157,7 @@ void AssDialogueBlockOverride::ProcessParameters(AssDialogueBlockOverride::Proce
// Go recursive if it's a block parameter // Go recursive if it's a block parameter
if (curPar->GetType() == VARDATA_BLOCK) { if (curPar->GetType() == VARDATA_BLOCK) {
curPar->AsBlock()->ProcessParameters(callback,userData); curPar->Get<AssDialogueBlockOverride*>()->ProcessParameters(callback,userData);
} }
} }
@ -466,25 +458,25 @@ void AssOverrideTagProto::LoadProtos () {
i++; i++;
proto[i].name = _T("\\b"); proto[i].name = _T("\\b");
proto[i].params.push_back(AssOverrideParamProto(VARDATA_INT,OPTIONAL_1,PARCLASS_NORMAL)); proto[i].params.push_back(AssOverrideParamProto(VARDATA_INT,OPTIONAL_1,PARCLASS_NORMAL));
proto[i].params.back().defaultValue.SetBool(false); proto[i].params.back().defaultValue.Set<bool>(false);
// \i<0/1> // \i<0/1>
i++; i++;
proto[i].name = _T("\\i"); proto[i].name = _T("\\i");
proto[i].params.push_back(AssOverrideParamProto(VARDATA_BOOL,OPTIONAL_1,PARCLASS_NORMAL)); proto[i].params.push_back(AssOverrideParamProto(VARDATA_BOOL,OPTIONAL_1,PARCLASS_NORMAL));
proto[i].params.back().defaultValue.SetBool(false); proto[i].params.back().defaultValue.Set<bool>(false);
// \u<0/1> // \u<0/1>
i++; i++;
proto[i].name = _T("\\u"); proto[i].name = _T("\\u");
proto[i].params.push_back(AssOverrideParamProto(VARDATA_BOOL,OPTIONAL_1,PARCLASS_NORMAL)); proto[i].params.push_back(AssOverrideParamProto(VARDATA_BOOL,OPTIONAL_1,PARCLASS_NORMAL));
proto[i].params.back().defaultValue.SetBool(false); proto[i].params.back().defaultValue.Set<bool>(false);
// \s<0/1> // \s<0/1>
i++; i++;
proto[i].name = _T("\\s"); proto[i].name = _T("\\s");
proto[i].params.push_back(AssOverrideParamProto(VARDATA_BOOL,OPTIONAL_1,PARCLASS_NORMAL)); proto[i].params.push_back(AssOverrideParamProto(VARDATA_BOOL,OPTIONAL_1,PARCLASS_NORMAL));
proto[i].params.back().defaultValue.SetBool(false); proto[i].params.back().defaultValue.Set<bool>(false);
// \a<alignment> // \a<alignment>
i++; i++;
@ -689,7 +681,7 @@ end_tokenizing:
wxChar firstChar = curtok[0]; wxChar firstChar = curtok[0];
bool auto4 = (firstChar == _T('!') || firstChar == _T('$') || firstChar == _T('%')) && curproto->type != VARDATA_BLOCK; bool auto4 = (firstChar == _T('!') || firstChar == _T('$') || firstChar == _T('%')) && curproto->type != VARDATA_BLOCK;
if (auto4) { if (auto4) {
newparam->SetText(curtok); newparam->Set(curtok);
} }
else { else {
// Determine parameter type and set value // Determine parameter type and set value
@ -697,29 +689,29 @@ end_tokenizing:
case VARDATA_INT: { case VARDATA_INT: {
long temp = 0; long temp = 0;
curtok.ToLong(&temp); curtok.ToLong(&temp);
newparam->SetInt(temp); newparam->Set<int>(temp);
break; break;
} }
case VARDATA_FLOAT: { case VARDATA_FLOAT: {
double temp = 0.0; double temp = 0.0;
curtok.ToDouble(&temp); curtok.ToDouble(&temp);
newparam->SetFloat(temp); newparam->Set<double>(temp);
break; break;
} }
case VARDATA_TEXT: case VARDATA_TEXT:
newparam->SetText(curtok); newparam->Set(curtok);
break; break;
case VARDATA_BOOL: { case VARDATA_BOOL: {
long temp = false; long temp = false;
curtok.ToLong(&temp); curtok.ToLong(&temp);
newparam->SetBool(temp != 0); newparam->Set<bool>(temp != 0);
break; break;
} }
case VARDATA_BLOCK: { case VARDATA_BLOCK: {
AssDialogueBlockOverride *temp = new AssDialogueBlockOverride; AssDialogueBlockOverride *temp = new AssDialogueBlockOverride;
temp->text = curtok; temp->text = curtok;
temp->ParseTags(); temp->ParseTags();
newparam->SetBlock(temp); newparam->Set(temp);
break; break;
} }
default: default:
@ -761,7 +753,7 @@ wxString AssOverrideTag::ToString() {
int n = 0; int n = 0;
for (std::vector<AssOverrideParameter*>::iterator cur=Params.begin();cur!=Params.end();cur++) { for (std::vector<AssOverrideParameter*>::iterator cur=Params.begin();cur!=Params.end();cur++) {
if ((*cur)->GetType() != VARDATA_NONE && (*cur)->ommited == false) { if ((*cur)->GetType() != VARDATA_NONE && (*cur)->ommited == false) {
result += (*cur)->AsText(); result += (*cur)->Get<wxString>();
result += _T(","); result += _T(",");
n++; n++;
} }

View file

@ -183,7 +183,7 @@ void AudioKaraoke::Commit() {
// Some weird people have text before the first karaoke tag on a line. // Some weird people have text before the first karaoke tag on a line.
// Check that a karaoke tag actually exists for the (non-)syllable to avoid a crash. // Check that a karaoke tag actually exists for the (non-)syllable to avoid a crash.
if (syl->tag && syl->tag->Params.size()>0) if (syl->tag && syl->tag->Params.size()>0)
syl->tag->Params[0]->SetInt(syl->duration); syl->tag->Params[0]->Set<int>(syl->duration);
// Of course, if the user changed the duration of such a non-syllable, its timing can't be updated and will stay zero. // Of course, if the user changed the duration of such a non-syllable, its timing can't be updated and will stay zero.
// There is no way to check for that right now, and I can't bother to fix it. // There is no way to check for that right now, and I can't bother to fix it.
} }

View file

@ -932,11 +932,11 @@ namespace Automation4 {
ktag = tag->Name.Mid(1); ktag = tag->Name.Mid(1);
// check if it's a "set time" tag, special handling for that (depends on previous syllable duration) // check if it's a "set time" tag, special handling for that (depends on previous syllable duration)
if (ktag == _T("kt")) { if (ktag == _T("kt")) {
ktime = tag->Params[0]->AsInt() * 10; ktime = tag->Params[0]->Get<int>() * 10;
kdur = 0; kdur = 0;
} else { } else {
ktime += kdur; // duration of previous syllable ktime += kdur; // duration of previous syllable
kdur = tag->Params[0]->AsInt() * 10; kdur = tag->Params[0]->Get<int>() * 10;
} }
ktext.clear(); ktext.clear();
ktext_stripped.clear(); ktext_stripped.clear();

View file

@ -639,7 +639,7 @@ bool FontsCollectorThread::AttachFont(wxString filename) {
/// ///
void FontsCollectorThread::GetFonts (wxString tagName,int par_n,AssOverrideParameter *param,void *usr) { void FontsCollectorThread::GetFonts (wxString tagName,int par_n,AssOverrideParameter *param,void *usr) {
if (tagName == _T("\\fn")) { if (tagName == _T("\\fn")) {
if (instance) instance->AddFont(param->AsText(),1); if (instance) instance->AddFont(param->Get<wxString>(),1);
} }
} }

View file

@ -191,9 +191,9 @@ void DialogResample::DoResampleTags (wxString name,int n,AssOverrideParameter *c
case PARCLASS_DRAWING: case PARCLASS_DRAWING:
{ {
AssDialogueBlockDrawing block; AssDialogueBlockDrawing block;
block.text = curParam->AsText(); block.text = curParam->Get<wxString>();
block.TransformCoords(m[0],m[2],rx,ry); block.TransformCoords(m[0],m[2],rx,ry);
curParam->SetText(block.GetText()); curParam->Set(block.GetText());
} }
return; return;
@ -203,16 +203,16 @@ void DialogResample::DoResampleTags (wxString name,int n,AssOverrideParameter *c
VariableDataType curType = curParam->GetType(); VariableDataType curType = curParam->GetType();
if (curType == VARDATA_FLOAT) { if (curType == VARDATA_FLOAT) {
float par = curParam->AsFloat(); float par = curParam->Get<double>();
if (isX) par += m[0]; if (isX) par += m[0];
if (isY) par += m[2]; if (isY) par += m[2];
curParam->SetFloat(par * resizer); curParam->Set<double>(par * resizer);
} }
if (curType == VARDATA_INT) { if (curType == VARDATA_INT) {
int par = curParam->AsInt(); int par = curParam->Get<int>();
if (isX) par += m[0]; if (isX) par += m[0];
if (isY) par += m[2]; if (isY) par += m[2];
curParam->SetInt(int(double(par) * resizer + 0.5)); curParam->Set<int>(int(double(par) * resizer + 0.5));
} }
} }

View file

@ -510,8 +510,8 @@ void ReplaceStyle(wxString tag,int n,AssOverrideParameter* param,void *userData)
wxArrayString strings = *((wxArrayString*)userData); wxArrayString strings = *((wxArrayString*)userData);
if (tag == _T("\\r")) { if (tag == _T("\\r")) {
if (param->GetType() == VARDATA_TEXT) { if (param->GetType() == VARDATA_TEXT) {
if (param->AsText() == strings[0]) { if (param->Get<wxString>() == strings[0]) {
param->SetText(strings[1]); param->Set(strings[1]);
} }
} }
} }

View file

@ -213,7 +213,7 @@ void AssTransformFramerateFilter::TransformTimeTags (wxString name,int n,AssOver
} }
// Parameter value // Parameter value
int parVal = curParam->AsInt() * mult; int parVal = curParam->Get<int>() * mult;
// Karaoke preprocess // Karaoke preprocess
int curKarPos = 0; int curKarPos = 0;
@ -263,7 +263,7 @@ void AssTransformFramerateFilter::TransformTimeTags (wxString name,int n,AssOver
value -= curKarPos; value -= curKarPos;
} }
curParam->SetInt(value/mult); curParam->Set<int>(value/mult);
} }

View file

@ -1182,14 +1182,14 @@ void SubsEditBox::SetOverride (wxString tagname,wxString preValue,int forcePos,b
for (size_t j=0;j<override->Tags.size();j++) { for (size_t j=0;j<override->Tags.size();j++) {
tag = override->Tags.at(j); tag = override->Tags.at(j);
if (tag->Name == tagname || tag->Name == alttagname || tagname == _T("\\fn")) { if (tag->Name == tagname || tag->Name == alttagname || tagname == _T("\\fn")) {
if (isColor) startcolor = tag->Params.at(0)->AsColour(); if (isColor) startcolor = tag->Params.at(0)->Get<wxColour>();
if (isFlag) state = tag->Params.at(0)->AsBool(); if (isFlag) state = tag->Params.at(0)->Get<bool>();
if (isFont) { if (isFont) {
if (tag->Name == _T("\\fn")) startfont.SetFaceName(tag->Params.at(0)->AsText()); if (tag->Name == _T("\\fn")) startfont.SetFaceName(tag->Params.at(0)->Get<wxString>());
if (tag->Name == _T("\\fs")) startfont.SetPointSize(tag->Params.at(0)->AsInt()); if (tag->Name == _T("\\fs")) startfont.SetPointSize(tag->Params.at(0)->Get<int>());
if (tag->Name == _T("\\b")) startfont.SetWeight((tag->Params.at(0)->AsInt() > 0) ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL); if (tag->Name == _T("\\b")) startfont.SetWeight((tag->Params.at(0)->Get<int>() > 0) ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL);
if (tag->Name == _T("\\i")) startfont.SetStyle(tag->Params.at(0)->AsBool() ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL); if (tag->Name == _T("\\i")) startfont.SetStyle(tag->Params.at(0)->Get<bool>() ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL);
if (tag->Name == _T("\\u")) startfont.SetUnderlined(tag->Params.at(0)->AsBool()); if (tag->Name == _T("\\u")) startfont.SetUnderlined(tag->Params.at(0)->Get<bool>());
} }
} }
} }

View file

@ -32,8 +32,6 @@
/// @file variable_data.cpp /// @file variable_data.cpp
/// @brief A variant-type implementation /// @brief A variant-type implementation
/// @ingroup utility subs_storage /// @ingroup utility subs_storage
///
//////////// ////////////
// Includes // Includes
@ -44,27 +42,19 @@
#include "utils.h" #include "utils.h"
#include "variable_data.h" #include "variable_data.h"
/// @brief Constructor /// @brief Constructor
///
VariableData::VariableData () { VariableData::VariableData () {
type = VARDATA_NONE; type = VARDATA_NONE;
value = NULL; value = NULL;
} }
/// @brief Destructor /// @brief Destructor
///
VariableData::~VariableData () { VariableData::~VariableData () {
DeleteValue (); DeleteValue ();
} }
/// @brief Deletes the stored value /// @brief Deletes the stored value
/// @return /// @return
///
void VariableData::DeleteValue () { void VariableData::DeleteValue () {
if (!value) return; if (!value) return;
if (type == VARDATA_NONE) return; if (type == VARDATA_NONE) return;
@ -81,129 +71,88 @@ void VariableData::DeleteValue () {
value = NULL; value = NULL;
} }
template<class T> static inline VariableDataType get_type();
template<> inline VariableDataType get_type<int>() {
/// @brief Sets to an integer return VARDATA_INT;
/// @param param }
/// template<> inline VariableDataType get_type<double>() {
void VariableData::SetInt(int param) { return VARDATA_FLOAT;
DeleteValue(); }
type = VARDATA_INT; template<> inline VariableDataType get_type<bool>() {
value_int = new int(param); return VARDATA_BOOL;
}
template<> inline VariableDataType get_type<wxString>() {
return VARDATA_TEXT;
}
template<> inline VariableDataType get_type<wxColour>() {
return VARDATA_COLOUR;
}
template<> inline VariableDataType get_type<AssDialogueBlockOverride *>() {
return VARDATA_BLOCK;
} }
template<class T>
void VariableData::Set(T param) {
/// @brief Sets to a float
/// @param param
///
void VariableData::SetFloat(double param) {
DeleteValue(); DeleteValue();
type = VARDATA_FLOAT; type = get_type<T>();
value_float = new double(param); value = new T(param);
} }
template void VariableData::Set<int>(int param);
template void VariableData::Set<double>(double param);
template void VariableData::Set<bool>(bool param);
/// @brief Sets to a boolean template void VariableData::Set(wxString param);
/// @param param template void VariableData::Set<wxColour>(wxColour param);
/// template void VariableData::Set<AssDialogueBlockOverride *>(AssDialogueBlockOverride * param);
void VariableData::SetBool(bool param) {
DeleteValue();
type = VARDATA_BOOL;
value_bool = new bool(param);
}
/// @brief Sets to a string
/// @param param
///
void VariableData::SetText(wxString param) {
DeleteValue();
type = VARDATA_TEXT;
value_text = new wxString (param);
}
/// @brief Sets to a colour
/// @param param
///
void VariableData::SetColour(wxColour param) {
DeleteValue();
type = VARDATA_COLOUR;
value_colour = new wxColour (param);
}
/// @brief Sets to a block
/// @param param
///
void VariableData::SetBlock(AssDialogueBlockOverride *param) {
DeleteValue();
type = VARDATA_BLOCK;
value_block = param;
}
/// @brief Resets a value with a string, preserving current type /// @brief Resets a value with a string, preserving current type
/// @param value /// @param value
///
void VariableData::ResetWith(wxString value) { void VariableData::ResetWith(wxString value) {
switch (type) { switch (type) {
case VARDATA_INT: { case VARDATA_INT: {
long temp = 0; long temp = 0;
value.ToLong(&temp); value.ToLong(&temp);
SetInt(temp); Set<int>(temp);
break; break;
} }
case VARDATA_FLOAT: { case VARDATA_FLOAT: {
double temp = 0; double temp = 0;
value.ToDouble(&temp); value.ToDouble(&temp);
SetFloat(temp); Set(temp);
break; break;
} }
case VARDATA_BOOL: case VARDATA_BOOL:
if (value == _T("1")) SetBool(true); if (value == _T("1")) Set(true);
else SetBool(false); else Set(false);
break; break;
case VARDATA_COLOUR: { case VARDATA_COLOUR: {
long r=0,g=0,b=0; long r=0,g=0,b=0;
value.Mid(1,2).ToLong(&r,16); value.Mid(1,2).ToLong(&r,16);
value.Mid(3,2).ToLong(&g,16); value.Mid(3,2).ToLong(&g,16);
value.Mid(5,2).ToLong(&b,16); value.Mid(5,2).ToLong(&b,16);
SetColour(wxColour(r,g,b)); Set(wxColour(r,g,b));
break; break;
} }
default: default:
SetText(value); Set(value);
break; break;
} }
} }
/// @brief Reads as an int /// @brief Reads as an int
/// @return /// @return
/// template<> int VariableData::Get<int>() const {
int VariableData::AsInt() const {
if (!value) throw _T("Null parameter"); if (!value) throw _T("Null parameter");
if (type == VARDATA_BOOL) return (*value_bool)?1:0; if (type == VARDATA_BOOL) return !!(*value_bool);
if (type == VARDATA_INT) return *value_int; if (type == VARDATA_INT) return *value_int;
if (type == VARDATA_FLOAT) return (int)(*value_float); if (type == VARDATA_FLOAT) return (int)(*value_float);
if (type == VARDATA_TEXT) return 0; if (type == VARDATA_TEXT) return 0;
throw _T("Wrong parameter type, should be int"); throw _T("Wrong parameter type, should be int");
} }
/// @brief Reads as a float /// @brief Reads as a float
/// @return /// @return
/// template<> double VariableData::Get<double>() const {
double VariableData::AsFloat() const {
if (!value) throw _T("Null parameter"); if (!value) throw _T("Null parameter");
if (type == VARDATA_FLOAT) return *value_float; if (type == VARDATA_FLOAT) return *value_float;
if (type == VARDATA_INT) return (float)(*value_int); if (type == VARDATA_INT) return (float)(*value_int);
@ -211,12 +160,9 @@ double VariableData::AsFloat() const {
throw _T("Wrong parameter type, should be float"); throw _T("Wrong parameter type, should be float");
} }
/// @brief Reads as a bool /// @brief Reads as a bool
/// @return /// @return
/// template<> bool VariableData::Get<bool>() const {
bool VariableData::AsBool() const {
if (!value) throw _T("Null parameter"); if (!value) throw _T("Null parameter");
if (type == VARDATA_BOOL) return *value_bool; if (type == VARDATA_BOOL) return *value_bool;
if (type == VARDATA_INT) return ((*value_int)!=0); if (type == VARDATA_INT) return ((*value_int)!=0);
@ -225,12 +171,9 @@ bool VariableData::AsBool() const {
throw _T("Wrong parameter type, should be bool"); throw _T("Wrong parameter type, should be bool");
} }
/// @brief Reads as a colour /// @brief Reads as a colour
/// @return /// @return
/// template<> wxColour VariableData::Get<wxColour>() const {
wxColour VariableData::AsColour() const {
if (!value) throw _T("Null parameter"); if (!value) throw _T("Null parameter");
if (type == VARDATA_COLOUR) return *value_colour; if (type == VARDATA_COLOUR) return *value_colour;
else if (type == VARDATA_TEXT) { else if (type == VARDATA_TEXT) {
@ -241,62 +184,45 @@ wxColour VariableData::AsColour() const {
else throw _T("Wrong parameter type, should be colour"); else throw _T("Wrong parameter type, should be colour");
} }
/// @brief Reads as a block /// @brief Reads as a block
/// @return /// @return
/// template<> AssDialogueBlockOverride *VariableData::Get<AssDialogueBlockOverride *>() const {
AssDialogueBlockOverride *VariableData::AsBlock() const {
if (!value) throw _T("Null parameter"); if (!value) throw _T("Null parameter");
if (type != VARDATA_BLOCK) throw _T("Wrong parameter type, should be block"); if (type != VARDATA_BLOCK) throw _T("Wrong parameter type, should be block");
return value_block; return *value_block;
} }
/// @brief Reads as a string /// @brief Reads as a string
/// @return /// @return
/// template<> wxString VariableData::Get<wxString>() const {
wxString VariableData::AsText() const {
if (!value) throw _T("Null parameter"); if (!value) throw _T("Null parameter");
if (type != VARDATA_TEXT) { if (type != VARDATA_TEXT) {
if (type == VARDATA_INT) return wxString::Format(_T("%i"),*value_int); if (type == VARDATA_INT) return wxString::Format("%i",*value_int);
else if (type == VARDATA_FLOAT) return wxString::Format(_T("%g"),*value_float); else if (type == VARDATA_FLOAT) return wxString::Format("%g",*value_float);
else if (type == VARDATA_COLOUR) return wxString::Format(_T("#%02X%02X%02X"),value_colour->Red(),value_colour->Green(),value_colour->Blue()); else if (type == VARDATA_COLOUR) return wxString::Format("#%02X%02X%02X",value_colour->Red(),value_colour->Green(),value_colour->Blue());
else if (type == VARDATA_BOOL) { else if (type == VARDATA_BOOL) return *value_bool ? "1" : "0";
if (*value_bool) return _T("1"); else if (type == VARDATA_BLOCK) return (*value_block)->GetText();
else return _T("0");
}
else if (type == VARDATA_BLOCK) return value_block->GetText();
else throw _T("Wrong parameter type, should be text"); else throw _T("Wrong parameter type, should be text");
} }
return *value_text; return *value_text;
} }
/// @brief Gets type /// @brief Gets type
/// @return /// @return
///
VariableDataType VariableData::GetType() const { VariableDataType VariableData::GetType() const {
return type; return type;
} }
/// @brief Copy /// @brief Copy
/// @param param /// @param param
///
void VariableData::operator= (const VariableData &param) { void VariableData::operator= (const VariableData &param) {
switch(param.GetType()) { switch(param.GetType()) {
case VARDATA_INT: SetInt(param.AsInt()); break; case VARDATA_INT: Set(param.Get<int>()); break;
case VARDATA_FLOAT: SetFloat(param.AsFloat()); break; case VARDATA_FLOAT: Set(param.Get<double>()); break;
case VARDATA_TEXT: SetText(param.AsText()); break; case VARDATA_TEXT: Set(param.Get<wxString>()); break;
case VARDATA_BOOL: SetBool(param.AsBool()); break; case VARDATA_BOOL: Set(param.Get<bool>()); break;
case VARDATA_COLOUR: SetColour(param.AsColour()); break; case VARDATA_COLOUR: Set(param.Get<wxColor>()); break;
case VARDATA_BLOCK: SetBlock(param.AsBlock()); break; case VARDATA_BLOCK: Set(param.Get<AssDialogueBlockOverride*>()); break;
default: DeleteValue(); default: DeleteValue();
} }
} }

View file

@ -70,13 +70,9 @@ enum VariableDataType {
VARDATA_BLOCK VARDATA_BLOCK
}; };
//////////////
// Prototypes
class AssDialogueBlockOverride; class AssDialogueBlockOverride;
/// DOCME /// DOCME
/// @class VariableData /// @class VariableData
/// @brief DOCME /// @brief DOCME
@ -85,7 +81,6 @@ class AssDialogueBlockOverride;
class VariableData { class VariableData {
private: private:
union { union {
/// DOCME /// DOCME
void *value; void *value;
@ -105,7 +100,7 @@ private:
wxColour *value_colour; wxColour *value_colour;
/// DOCME /// DOCME
AssDialogueBlockOverride *value_block; AssDialogueBlockOverride **value_block;
}; };
/// DOCME /// DOCME
@ -119,23 +114,9 @@ public:
virtual ~VariableData(); virtual ~VariableData();
VariableDataType GetType() const; VariableDataType GetType() const;
template<class T> void Set(T param);
void SetInt(int param);
void SetFloat(double param);
void SetBool(bool param);
void SetText(wxString param);
void SetColour(wxColour param);
void SetBlock(AssDialogueBlockOverride *param);
void ResetWith(wxString value); void ResetWith(wxString value);
template<class T> T Get() const;
int AsInt() const;
double AsFloat() const;
bool AsBool() const;
wxString AsText() const;
wxColour AsColour() const;
AssDialogueBlockOverride *AsBlock() const;
void operator= (const VariableData &param); void operator= (const VariableData &param);
}; };

View file

@ -473,15 +473,15 @@ void VisualTool<FeatureType>::GetLinePosition(AssDialogue *diag,int &x, int &y,
// Position // Position
if ((tag->Name == L"\\pos" || tag->Name == L"\\move") && tag->Params.size() >= 2) { if ((tag->Name == L"\\pos" || tag->Name == L"\\move") && tag->Params.size() >= 2) {
if (!posSet) { if (!posSet) {
x = tag->Params[0]->AsInt(); x = tag->Params[0]->Get<int>();
y = tag->Params[1]->AsInt(); y = tag->Params[1]->Get<int>();
posSet = true; posSet = true;
} }
} }
// Alignment // Alignment
else if ((tag->Name == L"\\an" || tag->Name == L"\\a") && tag->Params.size() >= 1) { else if ((tag->Name == L"\\an" || tag->Name == L"\\a") && tag->Params.size() >= 1) {
align = tag->Params[0]->AsInt(); align = tag->Params[0]->Get<int>();
if (tag->Name == L"\\a") { if (tag->Name == L"\\a") {
switch(align) { switch(align) {
case 1: case 2: case 3: case 1: case 2: case 3:
@ -501,8 +501,8 @@ void VisualTool<FeatureType>::GetLinePosition(AssDialogue *diag,int &x, int &y,
// Origin // Origin
else if (!orgSet && tag->Name == L"\\org" && tag->Params.size() >= 2) { else if (!orgSet && tag->Name == L"\\org" && tag->Params.size() >= 2) {
orgx = tag->Params[0]->AsInt(); orgx = tag->Params[0]->Get<int>();
orgy = tag->Params[1]->AsInt(); orgy = tag->Params[1]->Get<int>();
parent->FromScriptCoords(&orgx, &orgy); parent->FromScriptCoords(&orgx, &orgy);
orgSet = true; orgSet = true;
} }
@ -562,18 +562,18 @@ void VisualTool<FeatureType>::GetLineMove(AssDialogue *diag,bool &hasMove,int &x
// Position // Position
if (tag->Name == L"\\move" && tag->Params.size() >= 4) { if (tag->Name == L"\\move" && tag->Params.size() >= 4) {
hasMove = true; hasMove = true;
x1 = tag->Params[0]->AsInt(); x1 = tag->Params[0]->Get<int>();
y1 = tag->Params[1]->AsInt(); y1 = tag->Params[1]->Get<int>();
x2 = tag->Params[2]->AsInt(); x2 = tag->Params[2]->Get<int>();
y2 = tag->Params[3]->AsInt(); y2 = tag->Params[3]->Get<int>();
parent->FromScriptCoords(&x1, &y1); parent->FromScriptCoords(&x1, &y1);
parent->FromScriptCoords(&x2, &y2); parent->FromScriptCoords(&x2, &y2);
if (tag->Params.size() >= 6 && if (tag->Params.size() >= 6 &&
!tag->Params[4]->ommited && !tag->Params[4]->ommited &&
!tag->Params[5]->ommited) { !tag->Params[5]->ommited) {
t1 = tag->Params[4]->AsInt(); t1 = tag->Params[4]->Get<int>();
t2 = tag->Params[5]->AsInt(); t2 = tag->Params[5]->Get<int>();
} }
return; return;
} }
@ -617,13 +617,13 @@ void VisualTool<FeatureType>::GetLineRotation(AssDialogue *diag,float &rx,float
for (size_t j=0;j<override->Tags.size();j++) { for (size_t j=0;j<override->Tags.size();j++) {
tag = override->Tags.at(j); tag = override->Tags.at(j);
if (tag->Name == L"\\frx" && tag->Params.size() == 1) { if (tag->Name == L"\\frx" && tag->Params.size() == 1) {
rx = tag->Params[0]->AsFloat(); rx = tag->Params[0]->Get<double>();
} }
if (tag->Name == L"\\fry" && tag->Params.size() == 1) { if (tag->Name == L"\\fry" && tag->Params.size() == 1) {
ry = tag->Params[0]->AsFloat(); ry = tag->Params[0]->Get<double>();
} }
if ((tag->Name == L"\\frz" || tag->Name == L"\fr") && tag->Params.size() == 1) { if ((tag->Name == L"\\frz" || tag->Name == L"\fr") && tag->Params.size() == 1) {
rz = tag->Params[0]->AsFloat(); rz = tag->Params[0]->Get<double>();
} }
} }
} }
@ -655,10 +655,10 @@ void VisualTool<FeatureType>::GetLineScale(AssDialogue *diag,float &scalX,float
for (size_t j=0;j<override->Tags.size();j++) { for (size_t j=0;j<override->Tags.size();j++) {
tag = override->Tags.at(j); tag = override->Tags.at(j);
if (tag->Name == L"\\fscx" && tag->Params.size() == 1) { if (tag->Name == L"\\fscx" && tag->Params.size() == 1) {
scalX = tag->Params[0]->AsFloat(); scalX = tag->Params[0]->Get<double>();
} }
if (tag->Name == L"\\fscy" && tag->Params.size() == 1) { if (tag->Name == L"\\fscy" && tag->Params.size() == 1) {
scalY = tag->Params[0]->AsFloat(); scalY = tag->Params[0]->Get<double>();
} }
} }
} }
@ -698,17 +698,17 @@ void VisualTool<FeatureType>::GetLineClip(AssDialogue *diag,int &x1,int &y1,int
for (size_t j=0;j<override->Tags.size();j++) { for (size_t j=0;j<override->Tags.size();j++) {
tag = override->Tags.at(j); tag = override->Tags.at(j);
if (tag->Name == L"\\clip" && tag->Params.size() == 4) { if (tag->Name == L"\\clip" && tag->Params.size() == 4) {
x1 = tag->Params[0]->AsInt(); x1 = tag->Params[0]->Get<int>();
y1 = tag->Params[1]->AsInt(); y1 = tag->Params[1]->Get<int>();
x2 = tag->Params[2]->AsInt(); x2 = tag->Params[2]->Get<int>();
y2 = tag->Params[3]->AsInt(); y2 = tag->Params[3]->Get<int>();
inverse = false; inverse = false;
} }
else if (tag->Name == L"\\iclip" && tag->Params.size() == 4) { else if (tag->Name == L"\\iclip" && tag->Params.size() == 4) {
x1 = tag->Params[0]->AsInt(); x1 = tag->Params[0]->Get<int>();
y1 = tag->Params[1]->AsInt(); y1 = tag->Params[1]->Get<int>();
x2 = tag->Params[2]->AsInt(); x2 = tag->Params[2]->Get<int>();
y2 = tag->Params[3]->AsInt(); y2 = tag->Params[3]->Get<int>();
inverse = true; inverse = true;
} }
} }
@ -745,17 +745,17 @@ wxString VisualTool<FeatureType>::GetLineVectorClip(AssDialogue *diag,int &scale
tag = override->Tags.at(j); tag = override->Tags.at(j);
if (tag->Name == L"\\clip" || tag->Name == L"\\iclip") { if (tag->Name == L"\\clip" || tag->Name == L"\\iclip") {
if (tag->Params.size() == 1) { if (tag->Params.size() == 1) {
result = tag->Params[0]->AsText(); result = tag->Params[0]->Get<wxString>();
} }
else if (tag->Params.size() == 2) { else if (tag->Params.size() == 2) {
scale = tag->Params[0]->AsInt(); scale = tag->Params[0]->Get<int>();
result = tag->Params[1]->AsText(); result = tag->Params[1]->Get<wxString>();
} }
else if (tag->Params.size() == 4) { else if (tag->Params.size() == 4) {
int x1 = tag->Params[0]->AsInt(), int x1 = tag->Params[0]->Get<int>(),
y1 = tag->Params[1]->AsInt(), y1 = tag->Params[1]->Get<int>(),
x2 = tag->Params[2]->AsInt(), x2 = tag->Params[2]->Get<int>(),
y2 = tag->Params[3]->AsInt(); y2 = tag->Params[3]->Get<int>();
result = wxString::Format(L"m %d %d l %d %d %d %d %d %d", x1, y1, x2, y1, x2, y2, x1, y2); result = wxString::Format(L"m %d %d l %d %d %d %d %d %d", x1, y1, x2, y1, x2, y2, x1, y2);
} }
inverse = tag->Name == L"\\iclip"; inverse = tag->Name == L"\\iclip";