Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Normally, you want just 1 instance of your Settings class
- # Here standart template for this behavior is provided:
- -------------------------------header file-----------------------------------
- #include "core/config.h"
- #include "core/settings.h"
- #define $CLASSNAME$Settings ($CLASSNAME$::instance())
- #define $CLASSNAME$Settings_writeable (const_cast<$CLASSNAME$*>($CLASSNAME$::instance()))
- class $CLASSNAME$ : public Settings
- {
- public:
- static const $CLASSNAME$ * instance();
- // put here your setting fields
- private:
- $CLASSNAME$();
- static $CLASSNAME$ *self;
- protected:
- // implementation of pure virtuals from base class
- void settingsChanged();
- void resetGui();
- void flushSettings();
- };
- -------------------------------source file-----------------------------------
- $CLASSNAME$ *$CLASSNAME$::self = 0;
- $CLASSNAME$::$CLASSNAME$() :
- Settings("$CLASSNAME$")
- {
- TRACE;
- // put here some initialization, probably reading settings from ini files, using
- // methods from base class
- }
- const $CLASSNAME$ * $CLASSNAME$::instance()
- {
- if(!self)
- self = new $CLASSNAME$;
- return self;
- }
- void $CLASSNAME$::settingsChanged()
- {
- TRACE;
- // this method is called, when user selects Ok in settings dialog -
- // it means, settings in GUI are accepted and have to be applied
- }
- void $CLASSNAME$::resetGui()
- {
- TRACE;
- // this method is called, when user clicks Cancel in settings dialog -
- // it means, settings in GUI are discarded, and class has to fill GUI with old settings
- }
- void $CLASSNAME$::flushSettings()
- {
- TRACE;
- // this method is called, when application terminates, and all settings have
- // to be flushed on disk
- }
Advertisement
Add Comment
Please, Sign In to add comment