From ac09590389a4d353ec343e10494b8a72478532b2 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Thu, 19 Sep 2013 16:38:06 -0700 Subject: [PATCH] Devirtualize OptionValue::GetName --- .../include/libaegisub/option_value.h | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/aegisub/libaegisub/include/libaegisub/option_value.h b/aegisub/libaegisub/include/libaegisub/option_value.h index 7d08f4fcc..1bcf8ff65 100644 --- a/aegisub/libaegisub/include/libaegisub/option_value.h +++ b/aegisub/libaegisub/include/libaegisub/option_value.h @@ -17,8 +17,6 @@ /// @ingroup libaegisub #include - -#include #include #include @@ -26,8 +24,6 @@ #include namespace agi { - - DEFINE_BASE_EXCEPTION_NOINNER(OptionValueError, Exception) DEFINE_SIMPLE_EXCEPTION_NOINNER(OptionValueErrorNotFound, OptionValueError, "options/not_found") DEFINE_SIMPLE_EXCEPTION_NOINNER(OptionValueErrorInvalidType, OptionValueError, "options/invalid_type") @@ -37,6 +33,7 @@ DEFINE_SIMPLE_EXCEPTION_NOINNER(OptionValueErrorInvalidListType, OptionValueErro /// Holds an actual option. class OptionValue { agi::signal::Signal ValueChanged; + std::string name; protected: void NotifyChanged() { ValueChanged(*this); } @@ -47,10 +44,11 @@ protected: return OptionValueErrorInvalidListType("Attempt to" + op + type + " with non-" + type + " list " + GetName()); } + OptionValue(std::string name) : name(std::move(name)) { } + public: virtual ~OptionValue() {}; - /// Option type /// No bitsets here. enum OptionType { @@ -66,8 +64,8 @@ public: Type_List_Bool = 104 ///< List of Bools }; + std::string GetName() const { return name; } virtual OptionType GetType() const = 0; - virtual std::string GetName() const = 0; virtual bool IsDefault() const = 0; virtual void Reset() = 0; @@ -104,14 +102,13 @@ public: class OptionValue##type_name : public OptionValue { \ type value; \ type value_default; \ - std::string name; \ public: \ OptionValue##type_name(std::string member_name, type member_value) \ - : value(member_value), value_default(member_value), name(member_name) {} \ + : OptionValue(std::move(member_name)) \ + , value(member_value), value_default(member_value) { } \ type Get##type_name() const { return value; } \ void Set##type_name(const type new_val) { value = new_val; NotifyChanged(); } \ 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; } \ void Set(const OptionValue *new_val) { Set##type_name(new_val->Get##type_name()); } \ @@ -129,18 +126,17 @@ CONFIG_OPTIONVALUE(Bool, bool) std::vector array_default; \ std::string name; \ public: \ - OptionValueList##type_name(std::string const& name, std::vector const& value = std::vector()) \ - : array(value), array_default(value), name(name) { } \ + OptionValueList##type_name(std::string name, std::vector const& value = std::vector()) \ + : OptionValue(std::move(name)) \ + , array(value), array_default(value) { } \ std::vector const& GetList##type_name() const { return array; } \ void SetList##type_name(const std::vector& val) { array = val; NotifyChanged(); } \ 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; } \ void Set(const OptionValue *nv) { SetList##type_name(nv->GetList##type_name()); } \ }; - CONFIG_OPTIONVALUE_LIST(String, std::string) CONFIG_OPTIONVALUE_LIST(Int, int64_t) CONFIG_OPTIONVALUE_LIST(Double, double)