diff --git a/stepmania/src/EnumHelper.h b/stepmania/src/EnumHelper.h index c4790b37b1..1aeb03e72c 100644 --- a/stepmania/src/EnumHelper.h +++ b/stepmania/src/EnumHelper.h @@ -92,7 +92,9 @@ static const RString EMPTY_STRING; if( !s2.CompareNoCase(X##Names[i]) ) \ return (X)i; \ return (X)(i+1); /*invalid*/ \ - } + } \ + template<> X StringTo( const RString& s ) { return StringTo##X( s ); } +template T StringTo( const RString& s ); #define LuaXToString(X) \ LuaFunction( X##ToString, X##ToString( (X) IArg(1) ) ); diff --git a/stepmania/src/ThemeMetric.h b/stepmania/src/ThemeMetric.h index f047635aeb..9bfe9d795f 100644 --- a/stepmania/src/ThemeMetric.h +++ b/stepmania/src/ThemeMetric.h @@ -22,7 +22,7 @@ class ThemeMetric : public IThemeMetric protected: RString m_sGroup; RString m_sName; - T m_currentValue; + T m_currentValue; bool m_bIsLoaded; /* HACK: If true, reload the metric each time it's read. This is like DynamicThemeMetric, @@ -219,16 +219,21 @@ public: } }; -template -class ThemeMetricEnum : public ThemeMetric +template T StringTo( const RString& s ); +template +class ThemeMetricEnum : public ThemeMetric { + T m_Value; public: - ThemeMetricEnum() : ThemeMetric() {} - ThemeMetricEnum( const RString& sGroup, const RString& sName ) : ThemeMetric(sGroup,sName) {} - T GetValue() const { return (T)ThemeMetric::GetValue(); } - bool operator ==( T other ) const { return GetValue() == other; } + ThemeMetricEnum() : ThemeMetric() {} + ThemeMetricEnum( const RString& sGroup, const RString& sName ) : + ThemeMetric( sGroup, sName ) {} + void Read() { ThemeMetric::Read(); m_Value = StringTo(m_currentValue); } + T GetValue() const { ASSERT( !m_sName.empty() && m_bIsLoaded ); return m_Value; } + operator T () const { return GetValue(); } }; + /* * Like ThemeMetric, but allows evaluating Lua expressions each time. This is * fast, since we only compile the expression once. To evaluate every time,