Files
itgmania212121/stepmania/src/Preference.h
T

106 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
enum PrefsGroup
{
Debug,
Editor,
Options,
2004-12-04 07:15:22 +00:00
NUM_PREFS_GROUPS
2004-09-13 04:27:52 +00:00
};
2004-12-04 07:15:22 +00:00
const CString& PrefsGroupToString( PrefsGroup pg );
2004-09-13 04:27:52 +00:00
class IPreference
{
public:
virtual ~IPreference() { }
2004-09-13 04:27:52 +00:00
virtual void LoadDefault() = 0;
virtual void ReadFrom( const IniFile &ini ) = 0;
virtual void WriteTo( IniFile &ini ) const = 0;
};
2004-12-04 07:15:22 +00:00
void SubscribePreference( IPreference *p );
void UnsubscribePreference( IPreference *p );
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
PrefsGroup m_PrefsGroup;
CString m_sName;
T m_defaultValue;
2004-12-04 07:15:22 +00:00
CString ToString();
void FromString( const CString &s );
2004-09-13 04:27:52 +00:00
public:
2004-09-13 04:45:36 +00:00
Preference( PrefsGroup PrefsGroup, const CString& sName, const T& defaultValue ):
2004-12-04 10:35:50 +00:00
m_currentValue( defaultValue ),
2004-09-13 04:27:52 +00:00
m_PrefsGroup( PrefsGroup ),
m_sName( sName ),
2004-12-04 10:35:50 +00:00
m_defaultValue( defaultValue )
2004-09-13 04:27:52 +00:00
{
2004-12-04 07:15:22 +00:00
SubscribePreference( this );
LoadDefault();
2004-09-13 04:27:52 +00:00
}
~Preference()
{
2004-12-04 07:15:22 +00:00
UnsubscribePreference( this );
}
2004-09-13 04:27:52 +00:00
void LoadDefault()
{
m_currentValue = m_defaultValue;
}
2004-12-04 07:15:22 +00:00
void ReadFrom( const IniFile &ini );
void WriteTo( IniFile &ini ) const;
2004-09-13 04:27:52 +00:00
2004-12-04 10:35:50 +00:00
operator T () const
{
return m_currentValue;
}
2004-12-04 07:15:22 +00:00
2004-12-04 10:35:50 +00:00
void operator=( const T& other )
2004-09-13 04:27:52 +00:00
{
2004-12-04 10:35:50 +00:00
m_currentValue = other;
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.
*/