Modify the StringToX macro to emit a template specialization of the (new) T StringTo<T>(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<X> 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.
This commit is contained in:
@@ -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<X>( const RString& s ) { return StringTo##X( s ); }
|
||||
template<class T> T StringTo( const RString& s );
|
||||
|
||||
#define LuaXToString(X) \
|
||||
LuaFunction( X##ToString, X##ToString( (X) IArg(1) ) );
|
||||
|
||||
@@ -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 T>
|
||||
class ThemeMetricEnum : public ThemeMetric<int>
|
||||
template<class T> T StringTo( const RString& s );
|
||||
template<class T>
|
||||
class ThemeMetricEnum : public ThemeMetric<RString>
|
||||
{
|
||||
T m_Value;
|
||||
public:
|
||||
ThemeMetricEnum() : ThemeMetric<int>() {}
|
||||
ThemeMetricEnum( const RString& sGroup, const RString& sName ) : ThemeMetric<int>(sGroup,sName) {}
|
||||
T GetValue() const { return (T)ThemeMetric<int>::GetValue(); }
|
||||
bool operator ==( T other ) const { return GetValue() == other; }
|
||||
ThemeMetricEnum() : ThemeMetric<RString>() {}
|
||||
ThemeMetricEnum( const RString& sGroup, const RString& sName ) :
|
||||
ThemeMetric<RString>( sGroup, sName ) {}
|
||||
void Read() { ThemeMetric<RString>::Read(); m_Value = StringTo<T>(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,
|
||||
|
||||
Reference in New Issue
Block a user