Version: 3.1.0
wxPersistenceManager Class Reference

#include <wx/persist.h>

Detailed Description

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.

Since
2.9.0

Library:  wxCore

Public Member Functions

void DisableSaving ()
 Globally disable saving the persistence object properties. More...
 
void DisableRestoring ()
 Globally disable restoring the persistence object properties. More...
 
template<class T >
wxPersistentObjectRegister (T *obj)
 Register an object with the manager automatically creating a persistence adapter for it. More...
 
wxPersistentObjectRegister (void *obj, wxPersistentObject *po)
 Register an object with the manager. More...
 
wxPersistentObjectFind (void *obj) const
 Check if the object is registered and return the associated wxPersistentObject if it is or NULL otherwise. More...
 
void Unregister (void *obj)
 Unregister the object and delete the associated wxPersistentObject. More...
 
void Save (void *obj)
 Save the object properties to persistent storage. More...
 
bool Restore (void *obj)
 Restore the object properties previously saved by Save(). More...
 
void SaveAndUnregister (void *obj)
 Combines both Save() and Unregister() calls. More...
 
template<class T >
bool RegisterAndRestore (T *obj)
 Combines both Register() and Restore() calls. More...
 
bool RegisterAndRestore (void *obj, wxPersistentObject *po)
 Combines both Register() and Restore() calls. More...
 

Static Public Member Functions

static void Set (wxPersistenceManager &manager)
 Set the global persistence manager to use. More...
 
static wxPersistenceManagerGet ()
 Returns the unique persistence manager object. More...
 

Protected Member Functions

 wxPersistenceManager ()
 Protected default constructor. More...
 
virtual wxConfigBaseGetConfig () const
 Return the config object to use. More...
 
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. More...
 

Constructor & Destructor Documentation

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.

Member Function Documentation

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.

See also
DisableSaving()
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.

See also
DisableRestoring()
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
protectedvirtual

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.

Since
2.9.3
virtual wxString wxPersistenceManager::GetKey ( const wxPersistentObject who,
const wxString name 
) const
protectedvirtual

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.

Since
2.9.3
template<class T >
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.

Parameters
objThe 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.

Parameters
objThe object to register.
poThe wxPersistentObject to use for saving and restoring this object properties.
template<class T >
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.

Parameters
objAn object previously registered with Register().
Returns
true if the object properties were restored or false if nothing was found to restore or the saved settings were invalid.
See also
RegisterAndRestore()
void wxPersistenceManager::Save ( void *  obj)

Save the object properties to persistent storage.

This method does nothing if DisableSaving() had been called.

Parameters
objAn object previously registered with Register().
See also
SaveAndUnregister()
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.

Since
2.9.3
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.

Parameters
objAn object previously registered with Register().