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:
Thomas Goyne 2011-11-04 19:42:31 +00:00
parent ba2794b2fe
commit 84c545b978
6 changed files with 32 additions and 54 deletions

View File

@ -129,8 +129,7 @@ void Options::Flush() {
break; break;
case OptionValue::Type_List_String: { case OptionValue::Type_List_String: {
std::vector<std::string> array_string; std::vector<std::string> const& array_string(i->second->GetListString());
i->second->GetListString(array_string);
json::Array array; json::Array array;
@ -145,8 +144,7 @@ void Options::Flush() {
break; break;
case OptionValue::Type_List_Int: { case OptionValue::Type_List_Int: {
std::vector<int64_t> array_int; std::vector<int64_t> const& array_int(i->second->GetListInt());
i->second->GetListInt(array_int);
json::Array array; json::Array array;
@ -160,8 +158,7 @@ void Options::Flush() {
break; break;
case OptionValue::Type_List_Double: { case OptionValue::Type_List_Double: {
std::vector<double> array_double; std::vector<double> const& array_double(i->second->GetListDouble());
i->second->GetListDouble(array_double);
json::Array array; json::Array array;
@ -175,8 +172,7 @@ void Options::Flush() {
break; break;
case OptionValue::Type_List_Colour: { case OptionValue::Type_List_Colour: {
std::vector<Colour> array_colour; std::vector<Colour> const& array_colour(i->second->GetListColour());
i->second->GetListColour(array_colour);
json::Array array; json::Array array;
for (std::vector<Colour>::const_iterator i_colour = array_colour.begin(); i_colour != array_colour.end(); ++i_colour) { 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; break;
case OptionValue::Type_List_Bool: { case OptionValue::Type_List_Bool: {
std::vector<bool> array_bool; std::vector<bool> const& array_bool(i->second->GetListBool());
json::Array array; 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) { for (std::vector<bool>::const_iterator i_bool = array_bool.begin(); i_bool != array_bool.end(); ++i_bool) {
json::Object obj; json::Object obj;
obj["bool"] = *i_bool; obj["bool"] = *i_bool;

View File

@ -162,40 +162,25 @@ void ConfigVisitor::AddOptionValue(OptionValue* opt) {
opt_cur->SetBool(opt->GetBool()); opt_cur->SetBool(opt->GetBool());
break; break;
case OptionValue::Type_List_String: { case OptionValue::Type_List_String:
std::vector<std::string> array; opt_cur->SetListString(opt->GetListString());
opt->GetListString(array);
opt_cur->SetListString(array);
break; break;
}
case OptionValue::Type_List_Int: { case OptionValue::Type_List_Int:
std::vector<int64_t> array; opt_cur->SetListInt(opt->GetListInt());
opt->GetListInt(array);
opt_cur->SetListInt(array);
break; break;
}
case OptionValue::Type_List_Double: { case OptionValue::Type_List_Double:
std::vector<double> array; opt_cur->SetListDouble(opt->GetListDouble());
opt->GetListDouble(array);
opt_cur->SetListDouble(array);
break; break;
}
case OptionValue::Type_List_Colour: { case OptionValue::Type_List_Colour:
std::vector<Colour> array; opt_cur->SetListColour(opt->GetListColour());
opt->GetListColour(array);
opt_cur->SetListColour(array);
break; break;
}
case OptionValue::Type_List_Bool: { case OptionValue::Type_List_Bool:
std::vector<bool> array; opt_cur->SetListBool(opt->GetListBool());
opt->GetListBool(array);
opt_cur->SetListBool(array);
break; break;
}
} }
} }
} // namespace agi } // namespace agi

View File

@ -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) { void Path::ListGet(const char *name, std::vector<std::string> &out) {
opt->Get(name)->GetListString(out); out = opt->Get(name)->GetListString();
} }

View File

@ -98,11 +98,11 @@ public:
virtual bool GetDefaultBool() const { throw TypeError("bool"); } virtual bool GetDefaultBool() const { throw TypeError("bool"); }
virtual void GetListString(std::vector<std::string> &out) const { throw ListTypeError("string"); } virtual std::vector<std::string> const& GetListString() const { throw ListTypeError("string"); }
virtual void GetListInt(std::vector<int64_t> &out) const { throw ListTypeError("int"); } virtual std::vector<int64_t> const& GetListInt() const { throw ListTypeError("int"); }
virtual void GetListDouble(std::vector<double> &out) const { throw ListTypeError("double"); } virtual std::vector<double> const& GetListDouble() const { throw ListTypeError("double"); }
virtual void GetListColour(std::vector<Colour> &out) const { throw ListTypeError("colour"); } virtual std::vector<Colour> const& GetListColour() const { throw ListTypeError("colour"); }
virtual void GetListBool(std::vector<bool> &out) const { throw ListTypeError("string"); } 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 SetListString(const std::vector<std::string>& val) { throw ListTypeError("string", " set "); }
virtual void SetListInt(const std::vector<int64_t>& val) { throw ListTypeError("int", " 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 SetListColour(const std::vector<Colour>& val) { throw ListTypeError("colour", " set "); }
virtual void SetListBool(const std::vector<bool>& val) { throw ListTypeError("string", " 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 std::vector<std::string> const& GetDefaultListString() const { throw ListTypeError("string"); }
virtual void GetDefaultListInt(std::vector<int64_t> &out) const { throw ListTypeError("int"); } virtual std::vector<int64_t> const& GetDefaultListInt() const { throw ListTypeError("int"); }
virtual void GetDefaultListDouble(std::vector<double> &out) const { throw ListTypeError("double"); } virtual std::vector<double> const& GetDefaultListDouble() const { throw ListTypeError("double"); }
virtual void GetDefaultListColour(std::vector<Colour> &out) const { throw ListTypeError("colour"); } virtual std::vector<Colour> const& GetDefaultListColour() const { throw ListTypeError("colour"); }
virtual void GetDefaultListBool(std::vector<bool> &out) const { throw ListTypeError("string"); } virtual std::vector<bool> const& GetDefaultListBool() const { throw ListTypeError("string"); }
DEFINE_SIGNAL_ADDERS(ValueChanged, Subscribe); DEFINE_SIGNAL_ADDERS(ValueChanged, Subscribe);
@ -134,7 +134,7 @@ public:
OptionType GetType() const { return OptionValue::Type_##type_name; } \ OptionType GetType() const { return OptionValue::Type_##type_name; } \
std::string GetName() const { return name; } \ std::string GetName() const { return name; } \
void Reset() { value = value_default; NotifyChanged(); } \ 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) CONFIG_OPTIONVALUE(String, std::string)
@ -164,13 +164,13 @@ class OptionValueList: public OptionValue {
public: \ public: \
virtual std::string GetString() const { return "";} \ virtual std::string GetString() const { return "";} \
OptionValueList##type_name(std::string member_name): name(member_name) {} \ 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 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; } \ OptionType GetType() const { return OptionValue::Type_List_##type_name; } \
std::string GetName() const { return name; } \ std::string GetName() const { return name; } \
void Reset() { array = array_default; NotifyChanged(); } \ void Reset() { array = array_default; NotifyChanged(); } \
bool IsDefault() const { return (array == array_default) ? 1 : 0; } \ bool IsDefault() const { return array == array_default; } \
}; };

View File

@ -142,8 +142,7 @@ void BaseGrid::UpdateStyle() {
} }
// Set column widths // Set column widths
std::vector<bool> column_array; std::vector<bool> column_array(OPT_GET("Subtitle/Grid/Column")->GetListBool());
OPT_GET("Subtitle/Grid/Column")->GetListBool(column_array);
assert(column_array.size() == columns); assert(column_array.size() == columns);
for (int i = 0; i < columns; ++i) showCol[i] = column_array[i]; for (int i = 0; i < columns; ++i) showCol[i] = column_array[i];
SetColumnWidths(); SetColumnWidths();

View File

@ -94,7 +94,7 @@ DialogPasteOver::DialogPasteOver (wxWindow *parent, std::vector<bool>& options)
// Load checked items // Load checked items
/// @todo This assumes a static set of fields. /// @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]); for (unsigned int i=0;i<choices.Count();i++) ListBox->Check(i,options[i]);
// Top buttons // Top buttons