diff --git a/stepmania/src/EnumHelper.h b/stepmania/src/EnumHelper.h index c091975476..ef4655bea4 100644 --- a/stepmania/src/EnumHelper.h +++ b/stepmania/src/EnumHelper.h @@ -61,7 +61,7 @@ const RString &EnumToString( int iVal, int iMax, const char **szNameArray, auto_ static auto_ptr as_##X##Name[NUM_##X+2]; \ return EnumToString( x, NUM_##X, X##Names, as_##X##Name ); \ } \ - template<> RString ToString( const X &value ) { return X##ToString(value); } + namespace StringConversion { template<> RString ToString( const X &value ) { return X##ToString(value); } } #define XToString(X, CNT) XToString2(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+1); /*invalid*/ \ } \ - template<> bool FromString( const RString &sValue, X &out ) { out = StringTo##X(sValue); return out != X##_Invalid; } + namespace StringConversion { template<> bool FromString( const RString &sValue, X &out ) { out = StringTo##X(sValue); return out != X##_Invalid; } } // currently unused #define LuaDeclareType(X) diff --git a/stepmania/src/Model.cpp b/stepmania/src/Model.cpp index 01c33c1b54..e0bc8961f9 100644 --- a/stepmania/src/Model.cpp +++ b/stepmania/src/Model.cpp @@ -225,7 +225,7 @@ void Model::LoadMaterialsFromMilkshapeAscii( const RString &_sPath ) if( f.GetLine( sLine ) <= 0 ) THROW; float fShininess; - if( !FromString(sLine, fShininess) ) + if( !StringConversion::FromString(sLine, fShininess) ) THROW; Material.fShininess = fShininess; @@ -233,7 +233,7 @@ void Model::LoadMaterialsFromMilkshapeAscii( const RString &_sPath ) if( f.GetLine( sLine ) <= 0 ) THROW; float fTransparency; - if( !FromString(sLine, fTransparency) ) + if( !StringConversion::FromString(sLine, fTransparency) ) THROW; Material.fTransparency = fTransparency; diff --git a/stepmania/src/PlayerOptions.cpp b/stepmania/src/PlayerOptions.cpp index 2f13faa795..0593b1043d 100644 --- a/stepmania/src/PlayerOptions.cpp +++ b/stepmania/src/PlayerOptions.cpp @@ -274,7 +274,7 @@ void PlayerOptions::FromString( const RString &sOptions, bool bWarnOnInvalid ) vector matches; if( mult.Compare(sBit, matches) ) { - ::FromString( matches[0], level ); + StringConversion::FromString( matches[0], level ); SET_FLOAT( fScrollSpeed ) SET_FLOAT( fTimeSpacing ) m_fTimeSpacing = 0; diff --git a/stepmania/src/Preference.h b/stepmania/src/Preference.h index aea2ff3e8f..abb7699193 100644 --- a/stepmania/src/Preference.h +++ b/stepmania/src/Preference.h @@ -57,10 +57,10 @@ public: LoadDefault(); } - RString ToString() const { return ::ToString( m_currentValue ); } + RString ToString() const { return StringConversion::ToString( m_currentValue ); } void FromString( const RString &s ) { - if( !::FromString(s, m_currentValue) ) + if( !StringConversion::FromString(s, m_currentValue) ) m_currentValue = m_defaultValue; if( m_pfnValidate ) m_pfnValidate( m_currentValue ); @@ -83,7 +83,7 @@ public: void SetDefaultFromString( const RString &s ) { T def = m_defaultValue; - if( !::FromString(s, m_defaultValue) ) + if( !StringConversion::FromString(s, m_defaultValue) ) m_defaultValue = def; } diff --git a/stepmania/src/RageUtil.cpp b/stepmania/src/RageUtil.cpp index 58998114b2..517efa4136 100644 --- a/stepmania/src/RageUtil.cpp +++ b/stepmania/src/RageUtil.cpp @@ -1883,65 +1883,66 @@ void CollapsePath( RString &sPath, bool bRemoveLeadingDot ) sOut.swap( sPath ); } - -template<> bool FromString( const RString &sValue, int &out ) +namespace StringConversion { - if( sscanf( sValue.c_str(), "%d", &out ) == 1 ) - return true; + template<> bool FromString( const RString &sValue, int &out ) + { + if( sscanf( sValue.c_str(), "%d", &out ) == 1 ) + return true; - out = 0; - return false; -} - -template<> bool FromString( const RString &sValue, unsigned &out ) -{ - if( sscanf( sValue.c_str(), "%u", &out ) == 1 ) - return true; - - out = 0; - return false; -} - -template<> bool FromString( const RString &sValue, float &out ) -{ - const char *endptr = sValue.data() + sValue.size(); - out = strtof( sValue, (char **) &endptr ); - if( endptr != sValue.data() && isfinite( out ) ) - return true; - out = 0; - return false; -} - -template<> bool FromString( const RString &sValue, bool &out ) -{ - if( sValue.size() == 0 ) + out = 0; return false; + } - out = (atoi(sValue) != 0); - return true; + template<> bool FromString( const RString &sValue, unsigned &out ) + { + if( sscanf( sValue.c_str(), "%u", &out ) == 1 ) + return true; + + out = 0; + return false; + } + + template<> bool FromString( const RString &sValue, float &out ) + { + const char *endptr = sValue.data() + sValue.size(); + out = strtof( sValue, (char **) &endptr ); + if( endptr != sValue.data() && isfinite( out ) ) + return true; + out = 0; + return false; + } + + template<> bool FromString( const RString &sValue, bool &out ) + { + if( sValue.size() == 0 ) + return false; + + out = (atoi(sValue) != 0); + return true; + } + + template<> RString ToString( const int &value ) + { + return ssprintf( "%i", value ); + } + + template<> RString ToString( const unsigned &value ) + { + return ssprintf( "%u", value ); + } + + template<> RString ToString( const float &value ) + { + return ssprintf( "%f", value ); + } + + template<> RString ToString( const bool &value ) + { + return ssprintf( "%i", value ); + } } -template<> RString ToString( const int &value ) -{ - return ssprintf( "%i", value ); -} - -template<> RString ToString( const unsigned &value ) -{ - return ssprintf( "%u", value ); -} - -template<> RString ToString( const float &value ) -{ - return ssprintf( "%f", value ); -} - -template<> RString ToString( const bool &value ) -{ - return ssprintf( "%i", value ); -} - - // // Helper function for reading/writing scores // diff --git a/stepmania/src/RageUtil.h b/stepmania/src/RageUtil.h index 2ef3391d30..4afa55b560 100644 --- a/stepmania/src/RageUtil.h +++ b/stepmania/src/RageUtil.h @@ -532,27 +532,17 @@ void FlushDirCache(); void FixSlashesInPlace( RString &sPath ); void CollapsePath( RString &sPath, bool bRemoveLeadingDot=false ); -/* If the specified value is not a valid value for this type, and the type - * 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 -bool FromString( const RString &sValue, T &out ); +namespace StringConversion +{ + template + bool FromString( const RString &sValue, T &out ); -template<> bool FromString( const RString &sValue, int &out ); -template<> bool FromString( const RString &sValue, unsigned &out ); -template<> bool FromString( const RString &sValue, float &out ); -template<> bool FromString( const RString &sValue, bool &out ); -template<> inline bool FromString( const RString &sValue, RString &out ) { out = sValue; return true; } + template + RString ToString( const T &value ); -template -RString ToString( const T &value ); -template<> RString ToString( const int &value ); -template<> RString ToString( const unsigned &value ); -template<> RString ToString( const float &value ); -template<> RString ToString( const bool &value ); -template<> inline RString ToString( const RString &value ) { return value; } + template<> inline bool FromString( const RString &sValue, RString &out ) { out = sValue; return true; } + template<> inline RString ToString( const RString &value ) { return value; } +} // helper file functions used by Bookkeeper and ProfileManager class RageFileBasic; diff --git a/stepmania/src/ScreenOptionsMasterPrefs.cpp b/stepmania/src/ScreenOptionsMasterPrefs.cpp index 01c27a5adf..eae2610703 100644 --- a/stepmania/src/ScreenOptionsMasterPrefs.cpp +++ b/stepmania/src/ScreenOptionsMasterPrefs.cpp @@ -19,6 +19,8 @@ #include "SpecialFiles.h" #include "RageLog.h" +using namespace StringConversion; + static void GetPrefsDefaultModifiers( PlayerOptions &po, SongOptions &so ) { po.FromString( PREFSMAN->m_sDefaultModifiers );