#include </home/zeitlin/src/wx/github/interface/wx/persist.h>
Provides support for automatically saving and restoring object properties to persistent storage.
This class is the central element of wxWidgets persistence framework, see Persistent Objects Overview for its overview.
This is a singleton class and its unique instance can be retrieved using Get() method.
Public Member Functions | |
void | DisableSaving () |
Globally disable saving the persistence object properties. | |
void | DisableRestoring () |
Globally disable restoring the persistence object properties. | |
template<class T > | |
wxPersistentObject * | Register (T *obj) |
Register an object with the manager automatically creating a persistence adapter for it. | |
wxPersistentObject * | Register (void *obj, wxPersistentObject *po) |
Register an object with the manager. | |
wxPersistentObject * | Find (void *obj) const |
Check if the object is registered and return the associated wxPersistentObject if it is or NULL otherwise. | |
void | Unregister (void *obj) |
Unregister the object and delete the associated wxPersistentObject. | |
void | Save (void *obj) |
Save the object properties to persistent storage. | |
bool | Restore (void *obj) |
Restore the object properties previously saved by Save(). | |
void | SaveAndUnregister (void *obj) |
Combines both Save() and Unregister() calls. | |
template<class T > | |
bool | RegisterAndRestore (T *obj) |
Combines both Register() and Restore() calls. | |
bool | RegisterAndRestore (void *obj, wxPersistentObject *po) |
Combines both Register() and Restore() calls. | |
Static Public Member Functions | |
static void | Set (wxPersistenceManager &manager) |
Set the global persistence manager to use. | |
static wxPersistenceManager & | Get () |
Returns the unique persistence manager object. | |
Protected Member Functions | |
wxPersistenceManager () | |
Protected default constructor. | |
virtual wxConfigBase * | GetConfig () const |
Return the config object to use. | |
virtual wxString | GetKey (const wxPersistentObject &who, const wxString &name) const |
Return the path to use for saving the setting with the given name for the specified object. |
wxPersistenceManager::wxPersistenceManager | ( | ) | [protected] |
Protected default constructor.
This constructor is only provided for the derived classes, to use an object of this class static Get() method should be called.
void wxPersistenceManager::DisableRestoring | ( | ) |
Globally disable restoring the persistence object properties.
By default, restoring properties in Restore() is enabled but this function allows to disable it. This is mostly useful for testing.
void wxPersistenceManager::DisableSaving | ( | ) |
Globally disable saving the persistence object properties.
By default, saving properties in Save() is enabled but the program may wish to disable if, for example, it detects that it is running on a system which shouldn't be modified in any way and so configuration file (or Windows registry) shouldn't be written to.
wxPersistentObject* wxPersistenceManager::Find | ( | void * | obj | ) | const |
Check if the object is registered and return the associated wxPersistentObject if it is or NULL otherwise.
static wxPersistenceManager& wxPersistenceManager::Get | ( | ) | [static] |
Returns the unique persistence manager object.
If Set() hadn't been called before, a default persistence manager implementation is returned.
virtual wxConfigBase* wxPersistenceManager::GetConfig | ( | ) | const [protected, virtual] |
Return the config object to use.
By default the global wxConfig, returned by wxConfigBase::Get(), is used but a derived class could override this function to return a different one if necessary.
virtual wxString wxPersistenceManager::GetKey | ( | const wxPersistentObject & | who, |
const wxString & | name | ||
) | const [protected, virtual] |
Return the path to use for saving the setting with the given name for the specified object.
Notice that the name argument is the name of the setting, not the name of the object itself which can be retrieved with its GetName() method.
This method can be overridden by a derived class to change where in wxConfig the different options are stored. By default, all settings of the persistent controls are stored under "Persistent_Options" group and grouped by control type (e.g. "Window" for top level windows or "Splitter") and name, so that the position of a splitter called "sep" could be stored under "Persistent_Options/Splitter/sep/Position" key.
wxPersistentObject* wxPersistenceManager::Register | ( | T * | obj | ) |
Register an object with the manager automatically creating a persistence adapter for it.
This is equivalent to calling Register(void *, wxPersistentObject *) with wxCreatePersistentObject(obj) as the second argument.
obj | The object to register. wxCreatePersistentObject() overload must be defined for the objects of this class. |
wxPersistentObject* wxPersistenceManager::Register | ( | void * | obj, |
wxPersistentObject * | po | ||
) |
Register an object with the manager.
Note that registering the object doesn't do anything except allowing to call Restore() for it later. If you want to register the object and restore its properties, use RegisterAndRestore().
The manager takes ownership of po and will delete it when it is unregistered.
obj | The object to register. |
po | The wxPersistentObject to use for saving and restoring this object properties. |
bool wxPersistenceManager::RegisterAndRestore | ( | T * | obj | ) |
Combines both Register() and Restore() calls.
bool wxPersistenceManager::RegisterAndRestore | ( | void * | obj, |
wxPersistentObject * | po | ||
) |
Combines both Register() and Restore() calls.
bool wxPersistenceManager::Restore | ( | void * | obj | ) |
Restore the object properties previously saved by Save().
This method does nothing if DisableRestoring() had been called.
obj | An object previously registered with Register(). |
void wxPersistenceManager::Save | ( | void * | obj | ) |
Save the object properties to persistent storage.
This method does nothing if DisableSaving() had been called.
obj | An object previously registered with Register(). |
void wxPersistenceManager::SaveAndUnregister | ( | void * | obj | ) |
Combines both Save() and Unregister() calls.
static void wxPersistenceManager::Set | ( | wxPersistenceManager & | manager | ) | [static] |
Set the global persistence manager to use.
Call this method to specify a non-default persistence manager to use. It should usually be called very early (e.g. in wxApp-derived class constructor or in the beginning of overridden wxApp::OnInit()) to affect creation of all persistent controls and the object passed to it must have a lifetime long enough to be still alive when the persistent controls are destroyed and need it to save their state so typically this would be a global or a wxApp member.
void wxPersistenceManager::Unregister | ( | void * | obj | ) |
Unregister the object and delete the associated wxPersistentObject.
For the persistent windows this is done automatically (via SaveAndUnregister()) when the window is destroyed so you only need to call this function explicitly if you are using custom persistent objects or if you want to prevent the object properties from being saved.
obj | An object previously registered with Register(). |