maybe workaround g++ 3.3 weirdness
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+54
-53
@@ -1883,65 +1883,66 @@ void CollapsePath( RString &sPath, bool bRemoveLeadingDot )
|
|||||||
sOut.swap( sPath );
|
sOut.swap( sPath );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace StringConversion
|
||||||
template<> bool FromString<int>( const RString &sValue, int &out )
|
|
||||||
{
|
{
|
||||||
if( sscanf( sValue.c_str(), "%d", &out ) == 1 )
|
template<> bool FromString<int>( const RString &sValue, int &out )
|
||||||
return true;
|
{
|
||||||
|
if( sscanf( sValue.c_str(), "%d", &out ) == 1 )
|
||||||
|
return true;
|
||||||
|
|
||||||
out = 0;
|
out = 0;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<> bool FromString<unsigned>( const RString &sValue, unsigned &out )
|
|
||||||
{
|
|
||||||
if( sscanf( sValue.c_str(), "%u", &out ) == 1 )
|
|
||||||
return true;
|
|
||||||
|
|
||||||
out = 0;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<> bool FromString<float>( 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<bool>( const RString &sValue, bool &out )
|
|
||||||
{
|
|
||||||
if( sValue.size() == 0 )
|
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
out = (atoi(sValue) != 0);
|
template<> bool FromString<unsigned>( const RString &sValue, unsigned &out )
|
||||||
return true;
|
{
|
||||||
|
if( sscanf( sValue.c_str(), "%u", &out ) == 1 )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
out = 0;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<> bool FromString<float>( 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<bool>( const RString &sValue, bool &out )
|
||||||
|
{
|
||||||
|
if( sValue.size() == 0 )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
out = (atoi(sValue) != 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<> RString ToString<int>( const int &value )
|
||||||
|
{
|
||||||
|
return ssprintf( "%i", value );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<> RString ToString<unsigned>( const unsigned &value )
|
||||||
|
{
|
||||||
|
return ssprintf( "%u", value );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<> RString ToString<float>( const float &value )
|
||||||
|
{
|
||||||
|
return ssprintf( "%f", value );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<> RString ToString<bool>( const bool &value )
|
||||||
|
{
|
||||||
|
return ssprintf( "%i", value );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> RString ToString<int>( const int &value )
|
|
||||||
{
|
|
||||||
return ssprintf( "%i", value );
|
|
||||||
}
|
|
||||||
|
|
||||||
template<> RString ToString<unsigned>( const unsigned &value )
|
|
||||||
{
|
|
||||||
return ssprintf( "%u", value );
|
|
||||||
}
|
|
||||||
|
|
||||||
template<> RString ToString<float>( const float &value )
|
|
||||||
{
|
|
||||||
return ssprintf( "%f", value );
|
|
||||||
}
|
|
||||||
|
|
||||||
template<> RString ToString<bool>( const bool &value )
|
|
||||||
{
|
|
||||||
return ssprintf( "%i", value );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Helper function for reading/writing scores
|
// Helper function for reading/writing scores
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -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
|
template<typename T>
|
||||||
* "invalid" sentinels is NULL for pointers.) In either case, false will
|
bool FromString( const RString &sValue, T &out );
|
||||||
* be returned. */
|
|
||||||
template<typename T>
|
|
||||||
bool FromString( const RString &sValue, T &out );
|
|
||||||
|
|
||||||
template<> bool FromString<int>( const RString &sValue, int &out );
|
template<typename T>
|
||||||
template<> bool FromString<unsigned>( const RString &sValue, unsigned &out );
|
RString ToString( const T &value );
|
||||||
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<> inline bool FromString<RString>( const RString &sValue, RString &out ) { out = sValue; return true; }
|
||||||
RString ToString( const T &value );
|
template<> inline RString ToString<RString>( const RString &value ) { return value; }
|
||||||
template<> RString ToString<int>( const int &value );
|
}
|
||||||
template<> RString ToString<unsigned>( const unsigned &value );
|
|
||||||
template<> RString ToString<float>( const float &value );
|
|
||||||
template<> RString ToString<bool>( const bool &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 );
|
||||||
|
|||||||
Reference in New Issue
Block a user