forked from mia/Aegisub
Return const references from OptionValue::GetList* rather than taking an output parameter. Eliminates some copies of lists and makes the calling code less awkward.
Originally committed to SVN as r5816.
This commit is contained in:
parent
ba2794b2fe
commit
84c545b978
6 changed files with 32 additions and 54 deletions
|
@ -129,8 +129,7 @@ void Options::Flush() {
|
|||
break;
|
||||
|
||||
case OptionValue::Type_List_String: {
|
||||
std::vector<std::string> array_string;
|
||||
i->second->GetListString(array_string);
|
||||
std::vector<std::string> const& array_string(i->second->GetListString());
|
||||
|
||||
json::Array array;
|
||||
|
||||
|
@ -145,8 +144,7 @@ void Options::Flush() {
|
|||
break;
|
||||
|
||||
case OptionValue::Type_List_Int: {
|
||||
std::vector<int64_t> array_int;
|
||||
i->second->GetListInt(array_int);
|
||||
std::vector<int64_t> const& array_int(i->second->GetListInt());
|
||||
|
||||
json::Array array;
|
||||
|
||||
|
@ -160,8 +158,7 @@ void Options::Flush() {
|
|||
break;
|
||||
|
||||
case OptionValue::Type_List_Double: {
|
||||
std::vector<double> array_double;
|
||||
i->second->GetListDouble(array_double);
|
||||
std::vector<double> const& array_double(i->second->GetListDouble());
|
||||
|
||||
json::Array array;
|
||||
|
||||
|
@ -175,8 +172,7 @@ void Options::Flush() {
|
|||
break;
|
||||
|
||||
case OptionValue::Type_List_Colour: {
|
||||
std::vector<Colour> array_colour;
|
||||
i->second->GetListColour(array_colour);
|
||||
std::vector<Colour> const& array_colour(i->second->GetListColour());
|
||||
|
||||
json::Array array;
|
||||
for (std::vector<Colour>::const_iterator i_colour = array_colour.begin(); i_colour != array_colour.end(); ++i_colour) {
|
||||
|
@ -189,11 +185,9 @@ void Options::Flush() {
|
|||
break;
|
||||
|
||||
case OptionValue::Type_List_Bool: {
|
||||
std::vector<bool> array_bool;
|
||||
std::vector<bool> const& array_bool(i->second->GetListBool());
|
||||
|
||||
json::Array array;
|
||||
|
||||
i->second->GetListBool(array_bool);
|
||||
for (std::vector<bool>::const_iterator i_bool = array_bool.begin(); i_bool != array_bool.end(); ++i_bool) {
|
||||
json::Object obj;
|
||||
obj["bool"] = *i_bool;
|
||||
|
|
|
@ -162,40 +162,25 @@ void ConfigVisitor::AddOptionValue(OptionValue* opt) {
|
|||
opt_cur->SetBool(opt->GetBool());
|
||||
break;
|
||||
|
||||
case OptionValue::Type_List_String: {
|
||||
std::vector<std::string> array;
|
||||
opt->GetListString(array);
|
||||
opt_cur->SetListString(array);
|
||||
case OptionValue::Type_List_String:
|
||||
opt_cur->SetListString(opt->GetListString());
|
||||
break;
|
||||
}
|
||||
|
||||
case OptionValue::Type_List_Int: {
|
||||
std::vector<int64_t> array;
|
||||
opt->GetListInt(array);
|
||||
opt_cur->SetListInt(array);
|
||||
case OptionValue::Type_List_Int:
|
||||
opt_cur->SetListInt(opt->GetListInt());
|
||||
break;
|
||||
}
|
||||
|
||||
case OptionValue::Type_List_Double: {
|
||||
std::vector<double> array;
|
||||
opt->GetListDouble(array);
|
||||
opt_cur->SetListDouble(array);
|
||||
case OptionValue::Type_List_Double:
|
||||
opt_cur->SetListDouble(opt->GetListDouble());
|
||||
break;
|
||||
}
|
||||
|
||||
case OptionValue::Type_List_Colour: {
|
||||
std::vector<Colour> array;
|
||||
opt->GetListColour(array);
|
||||
opt_cur->SetListColour(array);
|
||||
case OptionValue::Type_List_Colour:
|
||||
opt_cur->SetListColour(opt->GetListColour());
|
||||
break;
|
||||
}
|
||||
|
||||
case OptionValue::Type_List_Bool: {
|
||||
std::vector<bool> array;
|
||||
opt->GetListBool(array);
|
||||
opt_cur->SetListBool(array);
|
||||
case OptionValue::Type_List_Bool:
|
||||
opt_cur->SetListBool(opt->GetListBool());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace agi
|
||||
|
|
|
@ -78,7 +78,7 @@ void Path::Set(const char *name, const std::string &path) {
|
|||
|
||||
|
||||
void Path::ListGet(const char *name, std::vector<std::string> &out) {
|
||||
opt->Get(name)->GetListString(out);
|
||||
out = opt->Get(name)->GetListString();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -98,11 +98,11 @@ public:
|
|||
virtual bool GetDefaultBool() const { throw TypeError("bool"); }
|
||||
|
||||
|
||||
virtual void GetListString(std::vector<std::string> &out) const { throw ListTypeError("string"); }
|
||||
virtual void GetListInt(std::vector<int64_t> &out) const { throw ListTypeError("int"); }
|
||||
virtual void GetListDouble(std::vector<double> &out) const { throw ListTypeError("double"); }
|
||||
virtual void GetListColour(std::vector<Colour> &out) const { throw ListTypeError("colour"); }
|
||||
virtual void GetListBool(std::vector<bool> &out) const { throw ListTypeError("string"); }
|
||||
virtual std::vector<std::string> const& GetListString() const { throw ListTypeError("string"); }
|
||||
virtual std::vector<int64_t> const& GetListInt() const { throw ListTypeError("int"); }
|
||||
virtual std::vector<double> const& GetListDouble() const { throw ListTypeError("double"); }
|
||||
virtual std::vector<Colour> const& GetListColour() const { throw ListTypeError("colour"); }
|
||||
virtual std::vector<bool> const& GetListBool() const { throw ListTypeError("string"); }
|
||||
|
||||
virtual void SetListString(const std::vector<std::string>& val) { throw ListTypeError("string", " set "); }
|
||||
virtual void SetListInt(const std::vector<int64_t>& val) { throw ListTypeError("int", " set "); }
|
||||
|
@ -110,11 +110,11 @@ public:
|
|||
virtual void SetListColour(const std::vector<Colour>& val) { throw ListTypeError("colour", " set "); }
|
||||
virtual void SetListBool(const std::vector<bool>& val) { throw ListTypeError("string", " set "); }
|
||||
|
||||
virtual void GetDefaultListString(std::vector<std::string> &out) const { throw ListTypeError("string"); }
|
||||
virtual void GetDefaultListInt(std::vector<int64_t> &out) const { throw ListTypeError("int"); }
|
||||
virtual void GetDefaultListDouble(std::vector<double> &out) const { throw ListTypeError("double"); }
|
||||
virtual void GetDefaultListColour(std::vector<Colour> &out) const { throw ListTypeError("colour"); }
|
||||
virtual void GetDefaultListBool(std::vector<bool> &out) const { throw ListTypeError("string"); }
|
||||
virtual std::vector<std::string> const& GetDefaultListString() const { throw ListTypeError("string"); }
|
||||
virtual std::vector<int64_t> const& GetDefaultListInt() const { throw ListTypeError("int"); }
|
||||
virtual std::vector<double> const& GetDefaultListDouble() const { throw ListTypeError("double"); }
|
||||
virtual std::vector<Colour> const& GetDefaultListColour() const { throw ListTypeError("colour"); }
|
||||
virtual std::vector<bool> const& GetDefaultListBool() const { throw ListTypeError("string"); }
|
||||
|
||||
|
||||
DEFINE_SIGNAL_ADDERS(ValueChanged, Subscribe);
|
||||
|
@ -134,7 +134,7 @@ public:
|
|||
OptionType GetType() const { return OptionValue::Type_##type_name; } \
|
||||
std::string GetName() const { return name; } \
|
||||
void Reset() { value = value_default; NotifyChanged(); } \
|
||||
bool IsDefault() const { return (value == value_default) ? 1 : 0; } \
|
||||
bool IsDefault() const { return value == value_default; } \
|
||||
};
|
||||
|
||||
CONFIG_OPTIONVALUE(String, std::string)
|
||||
|
@ -164,13 +164,13 @@ class OptionValueList: public OptionValue {
|
|||
public: \
|
||||
virtual std::string GetString() const { return "";} \
|
||||
OptionValueList##type_name(std::string member_name): name(member_name) {} \
|
||||
void GetList##type_name(std::vector<type> &out) const { out = array; } \
|
||||
std::vector<type> const& GetList##type_name() const { return array; } \
|
||||
void SetList##type_name(const std::vector<type>& val) { array = val; NotifyChanged(); } \
|
||||
void GetDefaultList##type_name(std::vector<type> &out) const { out = array_default; } \
|
||||
std::vector<type> const& GetDefaultList##type_name() const { return array_default; } \
|
||||
OptionType GetType() const { return OptionValue::Type_List_##type_name; } \
|
||||
std::string GetName() const { return name; } \
|
||||
void Reset() { array = array_default; NotifyChanged(); } \
|
||||
bool IsDefault() const { return (array == array_default) ? 1 : 0; } \
|
||||
bool IsDefault() const { return array == array_default; } \
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -142,8 +142,7 @@ void BaseGrid::UpdateStyle() {
|
|||
}
|
||||
|
||||
// Set column widths
|
||||
std::vector<bool> column_array;
|
||||
OPT_GET("Subtitle/Grid/Column")->GetListBool(column_array);
|
||||
std::vector<bool> column_array(OPT_GET("Subtitle/Grid/Column")->GetListBool());
|
||||
assert(column_array.size() == columns);
|
||||
for (int i = 0; i < columns; ++i) showCol[i] = column_array[i];
|
||||
SetColumnWidths();
|
||||
|
|
|
@ -94,7 +94,7 @@ DialogPasteOver::DialogPasteOver (wxWindow *parent, std::vector<bool>& options)
|
|||
|
||||
// Load checked items
|
||||
/// @todo This assumes a static set of fields.
|
||||
OPT_GET("Tool/Paste Lines Over/Fields")->GetListBool(options);
|
||||
options = OPT_GET("Tool/Paste Lines Over/Fields")->GetListBool();
|
||||
for (unsigned int i=0;i<choices.Count();i++) ListBox->Check(i,options[i]);
|
||||
|
||||
// Top buttons
|
||||
|
|
Loading…
Reference in a new issue