Files
itgmania212121/stepmania/src/Preference.h
T

105 lines
2.8 KiB
C++
Raw Normal View History

2004-09-13 04:27:52 +00:00
/* Preference - Holds user-chosen preferences that are saved between sessions. */
#ifndef PREFERENCE_H
#define PREFERENCE_H
2004-12-04 07:15:22 +00:00
#include "EnumHelper.h"
class IniFile;
2004-09-13 04:27:52 +00:00
struct lua_State;
2004-09-13 04:27:52 +00:00
class IPreference
{
public:
IPreference( const CString& sName );
virtual ~IPreference();
2004-09-13 04:27:52 +00:00
virtual void LoadDefault() = 0;
virtual void ReadFrom( const IniFile &ini );
virtual void WriteTo( IniFile &ini ) const;
virtual CString ToString() const = 0;
virtual void FromString( const CString &s ) = 0;
2005-02-22 04:22:24 +00:00
virtual void SetFromStack( lua_State *L );
virtual void PushValue( lua_State *L ) const;
const CString &GetName() const { return m_sName; }
protected:
CString m_sName;
};
2004-12-04 07:15:22 +00:00
2005-05-06 20:41:05 +00:00
void BroadcastPreferenceChanged( const CString& sPreferenceName );
2004-09-13 04:27:52 +00:00
template <class T>
class Preference : public IPreference
{
private:
2004-12-04 10:35:50 +00:00
// Make currentValue first in the list so that we can pass this object
// as an argument in a var_arg function as in printf.
T m_currentValue;
2004-09-13 04:27:52 +00:00
T m_defaultValue;
2004-12-04 07:15:22 +00:00
2004-09-13 04:27:52 +00:00
public:
Preference( const CString& sName, const T& defaultValue ):
IPreference( sName ),
2004-12-04 10:35:50 +00:00
m_currentValue( defaultValue ),
m_defaultValue( defaultValue )
2004-09-13 04:27:52 +00:00
{
2004-12-04 07:15:22 +00:00
LoadDefault();
2004-09-13 04:27:52 +00:00
}
CString ToString() const;
void FromString( const CString &s );
2005-02-22 04:22:24 +00:00
void SetFromStack( lua_State *L );
void PushValue( lua_State *L ) const;
2004-09-13 04:27:52 +00:00
void LoadDefault()
{
m_currentValue = m_defaultValue;
}
2005-05-06 20:41:05 +00:00
T Get() const
{
return m_currentValue;
}
2004-12-04 20:36:29 +00:00
2005-05-06 20:41:05 +00:00
operator const T () const
{
return Get();
}
void Set( const T& other )
2004-09-13 04:27:52 +00:00
{
2004-12-04 10:35:50 +00:00
m_currentValue = other;
2005-05-06 20:41:05 +00:00
BroadcastPreferenceChanged( m_sName );
2004-09-13 04:27:52 +00:00
}
};
#endif
/*
* (c) 2001-2004 Chris Danford, Chris Gomez
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/