# wxPersistentObject Class Reference

`#include <wx/persist.h>`

Inheritance diagram for wxPersistentObject:
[legend]

## Detailed Description

Base class for persistent object adapters.

wxWidgets persistence framework is non-intrusive, i.e. can work with the classes which have no relationship to nor knowledge of it. To allow this, an intermediate persistence adapter is used: this is just a simple object which provides the methods used by wxPersistenceManager to save and restore the object properties and implements them using the concrete class methods.

You may derive your own classes from wxPersistentObject to implement persistence support for your common classes, see Defining Custom Persistent Windows.

See also:
  wxPersistentWindow<>

## Public Member Functions
| wxPersistentObject (void *obj)
| Constructor takes the object which we're associated with.
virtual | ~wxPersistentObject ()
| Trivial but virtual destructor.
void * | GetObject () const
| Return the associated object.
Methods to be implemented in the derived classes.
Notice that these methods are only used by wxPersistenceManager normally and shouldn't be called directly.
virtual void | Save () const =0
| Save the object properties.
virtual bool | Restore ()=0
| Restore the object properties.
virtual wxString | GetKind () const =0
| Returns the string uniquely identifying the objects supported by this adapter.
virtual wxString | GetName () const =0
| Returns the string uniquely identifying the object we're associated with among all the other objects of the same type.
## Protected Member Functions
template<typename T >
bool | SaveValue (const wxString &name, T value) const
| Save the specified value using the given name.
template<typename T >
bool | RestoreValue (const wxString &name, T *value)
| Restore the value saved by Save().

List of all members.

## Constructor & Destructor Documentation

wxPersistentObject::wxPersistentObject | ( | void * | obj | ) |

Constructor takes the object which we're associated with.

This object must have life-time greater than ours as we keep a pointer to it.

virtual wxPersistentObject::~wxPersistentObject | ( |  | ) | `[virtual]`

Trivial but virtual destructor.

## Member Function Documentation

virtual wxString wxPersistentObject::GetKind | ( |  | ) | const`[pure virtual]`

Returns the string uniquely identifying the objects supported by this adapter.

This method is called from SaveValue() and RestoreValue() and normally returns some short (but not too cryptic) strings, e.g. `"Checkbox"`.

virtual wxString wxPersistentObject::GetName | ( |  | ) | const`[pure virtual]`

Returns the string uniquely identifying the object we're associated with among all the other objects of the same type.

This method is used together with GetKind() to construct the unique full name of the object in e.g. a configuration file.

Implemented in wxPersistentWindow< T >, wxPersistentWindow< wxBookCtrlBase >, and wxPersistentWindow< wxTopLevelWindow >.

void* wxPersistentObject::GetObject | ( |  | ) | const

Return the associated object.

virtual bool wxPersistentObject::Restore | ( |  | ) | `[pure virtual]`

Restore the object properties.

The implementation of this method should use RestoreValue().

Implemented in wxPersistentBookCtrl, wxPersistentTLW, and wxPersistentTreeBook.

template<typename T >

bool wxPersistentObject::RestoreValue | ( | const wxString & | name,
|  | T * | value |
| ) |  |  | `[inline, protected]`

Restore the value saved by Save().

Parameters:

  | name | The same name as was used by Save().
  | value | Non-NULL pointer which will be filled with the value if it was read successfully or not modified if it wasn't.

Returns:
  true if the value was successfully read or false if it was not found or an error occurred.

virtual void wxPersistentObject::Save | ( |  | ) | const`[pure virtual]`

Save the object properties.

The implementation of this method should use SaveValue().

Implemented in wxPersistentBookCtrl, wxPersistentTLW, and wxPersistentTreeBook.

template<typename T >

bool wxPersistentObject::SaveValue | ( | const wxString & | name,
|  | T | value |
| ) |  |  | const`[inline, protected]`

Save the specified value using the given name.

Parameters:

  | name | The name of the value in the configuration file.
  | value | The value to save, currently must be a type supported by wxConfig.

Returns:
  true if the value was saved or false if an error occurred.

|  | [ top ]