| Version: 3.2.5

Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
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 >
wxPersistentObject * | Register (T *obj)
| Register an object with the manager automatically creating a persistence adapter for it. More...
wxPersistentObject * | Register (void *obj, wxPersistentObject *po)
| Register an object with the manager. More...
wxPersistentObject * | Find (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 wxPersistenceManager & | Get ()
| Returns the unique persistence manager object. More...

## Protected Member Functions

| wxPersistenceManager ()
| Protected default constructor. More...
virtual wxConfigBase * | GetConfig () 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::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

## ◆ DisableRestoring()

void wxPersistenceManager::DisableRestoring | ( |  | ) |

Globally disable restoring the persistence object properties.

By default, restoring properties in Restore() is enabled but this function allows disabling it. This is mostly useful for testing.

See also
  DisableSaving()

## ◆ 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()

## ◆ Find()

wxPersistentObject* wxPersistenceManager::Find | ( | void * | obj | ) | const

Check if the object is registered and return the associated wxPersistentObject if it is or NULL otherwise.

## ◆ Get()

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.

## ◆ GetConfig()

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.

Since
  2.9.3

## ◆ GetKey()

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.

Since
  2.9.3

## ◆ Register() [1/2]

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

  obj | The object to register. wxCreatePersistentObject() overload must be defined for the objects of this class.

## ◆ Register() [2/2]

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

  obj | The object to register.
  po | The wxPersistentObject to use for saving and restoring this object properties.

## ◆ RegisterAndRestore() [1/2]

template<class T >

bool wxPersistenceManager::RegisterAndRestore | ( | T * | obj | ) |

Combines both Register() and Restore() calls.

## ◆ RegisterAndRestore() [2/2]

bool wxPersistenceManager::RegisterAndRestore | ( | void * | obj,
|  | wxPersistentObject * | po
| ) |  |

Combines both Register() and Restore() calls.

## ◆ Restore()

bool wxPersistenceManager::Restore | ( | void * | obj | ) |

Restore the object properties previously saved by Save().

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

Parameters

  obj | An 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()

## ◆ Save()

void wxPersistenceManager::Save | ( | void * | obj | ) |

Save the object properties to persistent storage.

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

Parameters

  obj | An object previously registered with Register().

See also
  SaveAndUnregister()

## ◆ SaveAndUnregister()

void wxPersistenceManager::SaveAndUnregister | ( | void * | obj | ) |

Combines both Save() and Unregister() calls.

## ◆ Set()

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

## ◆ Unregister()

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

  obj | An object previously registered with Register().