maybe workaround g++ 3.3 weirdness

This commit is contained in:
Glenn Maynard
2006-10-07 08:56:12 +00:00
parent dff1ed1c05
commit 30fd6d77b4
7 changed files with 73 additions and 80 deletions
+2 -2
View File
@@ -61,7 +61,7 @@ const RString &EnumToString( int iVal, int iMax, const char **szNameArray, auto_
static auto_ptr<RString> as_##X##Name[NUM_##X+2]; \ static auto_ptr<RString> as_##X##Name[NUM_##X+2]; \
return EnumToString( x, NUM_##X, X##Names, as_##X##Name ); \ return EnumToString( x, NUM_##X, X##Names, as_##X##Name ); \
} \ } \
template<> RString ToString<X>( const X &value ) { return X##ToString(value); } namespace StringConversion { template<> RString ToString<X>( const X &value ) { return X##ToString(value); } }
#define XToString(X, CNT) XToString2(X) #define XToString(X, CNT) XToString2(X)
#define XToLocalizedString(X) \ #define XToLocalizedString(X) \
@@ -89,7 +89,7 @@ const RString &EnumToString( int iVal, int iMax, const char **szNameArray, auto_
return (X)i; \ return (X)i; \
return (X)(i+1); /*invalid*/ \ return (X)(i+1); /*invalid*/ \
} \ } \
template<> bool FromString<X>( const RString &sValue, X &out ) { out = StringTo##X(sValue); return out != X##_Invalid; } namespace StringConversion { template<> bool FromString<X>( const RString &sValue, X &out ) { out = StringTo##X(sValue); return out != X##_Invalid; } }
// currently unused // currently unused
#define LuaDeclareType(X) #define LuaDeclareType(X)
+2 -2
View File
@@ -225,7 +225,7 @@ void Model::LoadMaterialsFromMilkshapeAscii( const RString &_sPath )
if( f.GetLine( sLine ) <= 0 ) if( f.GetLine( sLine ) <= 0 )
THROW; THROW;
float fShininess; float fShininess;
if( !FromString(sLine, fShininess) ) if( !StringConversion::FromString(sLine, fShininess) )
THROW; THROW;
Material.fShininess = fShininess; Material.fShininess = fShininess;
@@ -233,7 +233,7 @@ void Model::LoadMaterialsFromMilkshapeAscii( const RString &_sPath )
if( f.GetLine( sLine ) <= 0 ) if( f.GetLine( sLine ) <= 0 )
THROW; THROW;
float fTransparency; float fTransparency;
if( !FromString(sLine, fTransparency) ) if( !StringConversion::FromString(sLine, fTransparency) )
THROW; THROW;
Material.fTransparency = fTransparency; Material.fTransparency = fTransparency;
+1 -1
View File
@@ -274,7 +274,7 @@ void PlayerOptions::FromString( const RString &sOptions, bool bWarnOnInvalid )
vector<RString> matches; vector<RString> matches;
if( mult.Compare(sBit, matches) ) if( mult.Compare(sBit, matches) )
{ {
::FromString( matches[0], level ); StringConversion::FromString( matches[0], level );
SET_FLOAT( fScrollSpeed ) SET_FLOAT( fScrollSpeed )
SET_FLOAT( fTimeSpacing ) SET_FLOAT( fTimeSpacing )
m_fTimeSpacing = 0; m_fTimeSpacing = 0;
+3 -3
View File
@@ -57,10 +57,10 @@ public:
LoadDefault(); LoadDefault();
} }
RString ToString() const { return ::ToString<T>( m_currentValue ); } RString ToString() const { return StringConversion::ToString<T>( m_currentValue ); }
void FromString( const RString &s ) void FromString( const RString &s )
{ {
if( !::FromString<T>(s, m_currentValue) ) if( !StringConversion::FromString<T>(s, m_currentValue) )
m_currentValue = m_defaultValue; m_currentValue = m_defaultValue;
if( m_pfnValidate ) if( m_pfnValidate )
m_pfnValidate( m_currentValue ); m_pfnValidate( m_currentValue );
@@ -83,7 +83,7 @@ public:
void SetDefaultFromString( const RString &s ) void SetDefaultFromString( const RString &s )
{ {
T def = m_defaultValue; T def = m_defaultValue;
if( !::FromString<T>(s, m_defaultValue) ) if( !StringConversion::FromString<T>(s, m_defaultValue) )
m_defaultValue = def; m_defaultValue = def;
} }
+3 -2
View File
@@ -1883,7 +1883,8 @@ void CollapsePath( RString &sPath, bool bRemoveLeadingDot )
sOut.swap( sPath ); sOut.swap( sPath );
} }
namespace StringConversion
{
template<> bool FromString<int>( const RString &sValue, int &out ) template<> bool FromString<int>( const RString &sValue, int &out )
{ {
if( sscanf( sValue.c_str(), "%d", &out ) == 1 ) if( sscanf( sValue.c_str(), "%d", &out ) == 1 )
@@ -1940,7 +1941,7 @@ template<> RString ToString<bool>( const bool &value )
{ {
return ssprintf( "%i", value ); return ssprintf( "%i", value );
} }
}
// //
// Helper function for reading/writing scores // Helper function for reading/writing scores
+5 -15
View File
@@ -532,27 +532,17 @@ void FlushDirCache();
void FixSlashesInPlace( RString &sPath ); void FixSlashesInPlace( RString &sPath );
void CollapsePath( RString &sPath, bool bRemoveLeadingDot=false ); void CollapsePath( RString &sPath, bool bRemoveLeadingDot=false );
/* If the specified value is not a valid value for this type, and the type namespace StringConversion
* has a corresponding "invalid" value, out will be assigned the invalid {
* value if bAllowInvalid is true, or a sensible default if false. (An example
* "invalid" sentinels is NULL for pointers.) In either case, false will
* be returned. */
template<typename T> template<typename T>
bool FromString( const RString &sValue, T &out ); bool FromString( const RString &sValue, T &out );
template<> bool FromString<int>( const RString &sValue, int &out );
template<> bool FromString<unsigned>( const RString &sValue, unsigned &out );
template<> bool FromString<float>( const RString &sValue, float &out );
template<> bool FromString<bool>( const RString &sValue, bool &out );
template<> inline bool FromString<RString>( const RString &sValue, RString &out ) { out = sValue; return true; }
template<typename T> template<typename T>
RString ToString( const T &value ); RString ToString( const T &value );
template<> RString ToString<int>( const int &value );
template<> RString ToString<unsigned>( const unsigned &value ); template<> inline bool FromString<RString>( const RString &sValue, RString &out ) { out = sValue; return true; }
template<> RString ToString<float>( const float &value );
template<> RString ToString<bool>( const bool &value );
template<> inline RString ToString<RString>( const RString &value ) { return value; } template<> inline RString ToString<RString>( const RString &value ) { return value; }
}
// helper file functions used by Bookkeeper and ProfileManager // helper file functions used by Bookkeeper and ProfileManager
class RageFileBasic; class RageFileBasic;
@@ -19,6 +19,8 @@
#include "SpecialFiles.h" #include "SpecialFiles.h"
#include "RageLog.h" #include "RageLog.h"
using namespace StringConversion;
static void GetPrefsDefaultModifiers( PlayerOptions &po, SongOptions &so ) static void GetPrefsDefaultModifiers( PlayerOptions &po, SongOptions &so )
{ {
po.FromString( PREFSMAN->m_sDefaultModifiers ); po.FromString( PREFSMAN->m_sDefaultModifiers );