move more common stuff out of the template class, so g_pvpSubscribers is
more useful
This commit is contained in:
@@ -10,31 +10,54 @@ static const CString PrefsGroupNames[NUM_PREFS_GROUPS] = {
|
|||||||
};
|
};
|
||||||
XToString( PrefsGroup );
|
XToString( PrefsGroup );
|
||||||
|
|
||||||
void SubscribePreference( IPreference *p )
|
IPreference::IPreference( PrefsGroup PrefsGroup, const CString& sName ):
|
||||||
|
m_PrefsGroup( PrefsGroup ),
|
||||||
|
m_sName( sName )
|
||||||
{
|
{
|
||||||
PrefsManager::Subscribe( p );
|
PrefsManager::Subscribe( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnsubscribePreference( IPreference *p )
|
IPreference::~IPreference()
|
||||||
{
|
{
|
||||||
PrefsManager::Unsubscribe( p );
|
PrefsManager::Unsubscribe( this );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Preference<CString>::FromString( const CString &s )
|
||||||
|
{
|
||||||
|
m_currentValue = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
CString Preference<CString>::ToString() const
|
||||||
|
{
|
||||||
|
return m_currentValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define READFROM_AND_WRITETO( type ) \
|
#define READFROM_AND_WRITETO( type ) \
|
||||||
void Preference<type>::ReadFrom( const IniFile &ini ) \
|
void Preference<type>::FromString( const CString &s ) \
|
||||||
{ \
|
{ \
|
||||||
ini.GetValue( PrefsGroupToString(m_PrefsGroup), m_sName, m_currentValue ); \
|
::FromString( s, m_currentValue ); \
|
||||||
} \
|
} \
|
||||||
void Preference<type>::WriteTo( IniFile &ini ) const \
|
CString Preference<type>::ToString() const \
|
||||||
{ \
|
{ \
|
||||||
ini.SetValue( PrefsGroupToString(m_PrefsGroup), m_sName, m_currentValue ); \
|
return ::ToString( m_currentValue ); \
|
||||||
} \
|
} \
|
||||||
|
|
||||||
READFROM_AND_WRITETO( CString )
|
|
||||||
READFROM_AND_WRITETO( int )
|
READFROM_AND_WRITETO( int )
|
||||||
READFROM_AND_WRITETO( float )
|
READFROM_AND_WRITETO( float )
|
||||||
READFROM_AND_WRITETO( bool )
|
READFROM_AND_WRITETO( bool )
|
||||||
|
|
||||||
|
void IPreference::ReadFrom( const IniFile &ini )
|
||||||
|
{
|
||||||
|
CString sVal;
|
||||||
|
if( ini.GetValue( PrefsGroupToString(m_PrefsGroup), m_sName, sVal ) )
|
||||||
|
FromString( sVal );
|
||||||
|
}
|
||||||
|
|
||||||
|
void IPreference::WriteTo( IniFile &ini ) const
|
||||||
|
{
|
||||||
|
ini.SetValue( PrefsGroupToString(m_PrefsGroup), m_sName, ToString() );
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (c) 2001-2004 Chris Danford, Chris Gomez
|
* (c) 2001-2004 Chris Danford, Chris Gomez
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
|
|||||||
+19
-22
@@ -19,14 +19,23 @@ const CString& PrefsGroupToString( PrefsGroup pg );
|
|||||||
class IPreference
|
class IPreference
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~IPreference() { }
|
IPreference( PrefsGroup PrefsGroup, const CString& sName );
|
||||||
virtual void LoadDefault() = 0;
|
virtual ~IPreference();
|
||||||
virtual void ReadFrom( const IniFile &ini ) = 0;
|
|
||||||
virtual void WriteTo( IniFile &ini ) const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
void SubscribePreference( IPreference *p );
|
virtual void LoadDefault() = 0;
|
||||||
void UnsubscribePreference( IPreference *p );
|
virtual void ReadFrom( const IniFile &ini );
|
||||||
|
virtual void WriteTo( IniFile &ini ) const;
|
||||||
|
|
||||||
|
virtual CString ToString() const = 0;
|
||||||
|
virtual void FromString( const CString &s ) = 0;
|
||||||
|
|
||||||
|
PrefsGroup GetPrefsGroup() const { return m_PrefsGroup; }
|
||||||
|
const CString &GetName() const { return m_sName; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
PrefsGroup m_PrefsGroup;
|
||||||
|
CString m_sName;
|
||||||
|
};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class Preference : public IPreference
|
class Preference : public IPreference
|
||||||
@@ -35,37 +44,25 @@ private:
|
|||||||
// Make currentValue first in the list so that we can pass this object
|
// Make currentValue first in the list so that we can pass this object
|
||||||
// as an argument in a var_arg function as in printf.
|
// as an argument in a var_arg function as in printf.
|
||||||
T m_currentValue;
|
T m_currentValue;
|
||||||
PrefsGroup m_PrefsGroup;
|
|
||||||
CString m_sName;
|
|
||||||
T m_defaultValue;
|
T m_defaultValue;
|
||||||
|
|
||||||
CString ToString();
|
|
||||||
void FromString( const CString &s );
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Preference( PrefsGroup PrefsGroup, const CString& sName, const T& defaultValue ):
|
Preference( PrefsGroup PrefsGroup, const CString& sName, const T& defaultValue ):
|
||||||
|
IPreference( PrefsGroup, sName ),
|
||||||
m_currentValue( defaultValue ),
|
m_currentValue( defaultValue ),
|
||||||
m_PrefsGroup( PrefsGroup ),
|
|
||||||
m_sName( sName ),
|
|
||||||
m_defaultValue( defaultValue )
|
m_defaultValue( defaultValue )
|
||||||
{
|
{
|
||||||
SubscribePreference( this );
|
|
||||||
LoadDefault();
|
LoadDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
~Preference()
|
CString ToString() const;
|
||||||
{
|
void FromString( const CString &s );
|
||||||
UnsubscribePreference( this );
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoadDefault()
|
void LoadDefault()
|
||||||
{
|
{
|
||||||
m_currentValue = m_defaultValue;
|
m_currentValue = m_defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadFrom( const IniFile &ini );
|
|
||||||
void WriteTo( IniFile &ini ) const;
|
|
||||||
|
|
||||||
operator T () const
|
operator T () const
|
||||||
{
|
{
|
||||||
return m_currentValue;
|
return m_currentValue;
|
||||||
|
|||||||
Reference in New Issue
Block a user