From d4f3329c5a53c1e2c973ac8b7f53ff8c8b6edb50 Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Tue, 14 Mar 2006 03:47:43 +0000 Subject: [PATCH] Modify the StringToX macro to emit a template specialization of the (new) T StringTo(const RString& s) function. Doing this allows a general ThemeMetricEnum class which instead of reading an int will now read a string and then call the appropriate StringToX function via the StringTo function. Currently the only thing which uses ThemeMetricEnum is the EditMode enums. As a result, this breaks the EditMode=n (for n in 0..2) metrics (which I just broke with the previous commit anyway). That commit coming shortly. --- stepmania/src/EnumHelper.h | 4 +++- stepmania/src/ThemeMetric.h | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) 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,