wxWidgets: wxPersistentObject Class Reference

| Version: 3.2.5

Public Member Functions | Protected Member Functions | List of all members
wxPersistentObject Class Referenceabstract

`#include <wx/persist.h>`

Inheritance diagram for wxPersistentObject:
[legend]

## Detailed Description

Base class for persistent object adapters.

See Persistent Objects Overview for an overview of persistent objects within wxWidgets.

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. More...
virtual | ~wxPersistentObject ()
| Trivial but virtual destructor. More...
void * | GetObject () const
| Return the associated object. More...
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. More...
virtual bool | Restore ()=0
| Restore the object properties. More...
virtual wxString | GetKind () const =0
| Returns the string uniquely identifying the objects supported by this adapter. More...
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. More...

## Protected Member Functions
template<typename T >
bool | SaveValue (const wxString &name, T value) const
| Save the specified value using the given name. More...
template<typename T >
bool | RestoreValue (const wxString &name, T *value)
| Restore a value saved by SaveValue(). More...

## Constructor & Destructor Documentation

## ◆ wxPersistentObject()

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.

## ◆ ~wxPersistentObject()

virtual wxPersistentObject::~wxPersistentObject | ( |  | ) |
| virtual

Trivial but virtual destructor.

## Member Function Documentation

## ◆ GetKind()

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"`.

## ◆ GetName()

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 >, wxPersistentWindow< wxDataViewCtrl >, wxPersistentWindow< wxComboBox >, and wxPersistentWindow< wxTopLevelWindow >.

## ◆ GetObject()

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

Return the associated object.

## ◆ Restore()

virtual bool wxPersistentObject::Restore | ( |  | ) |
| pure virtual

Restore the object properties.

The implementation of this method should use RestoreValue().

Implemented in wxPersistentDataViewCtrl, wxPersistentTreeBookCtrl, wxPersistentTLW, wxPersistentComboBox, and wxPersistentBookCtrl.

## ◆ RestoreValue()

template<typename T >

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

Restore a value saved by SaveValue().

Parameters

  name | The same name as was used by SaveValue().
  value | Non-NULL pointer to the same type that was passed to SaveValue(). The pointed to object will be filled with the saved value if it was read successfully or not modified otherwise.

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

## ◆ Save()

virtual void wxPersistentObject::Save | ( |  | ) | const
| pure virtual

Save the object properties.

The implementation of this method should use SaveValue().

Implemented in wxPersistentDataViewCtrl, wxPersistentTreeBookCtrl, wxPersistentTLW, wxPersistentComboBox, and wxPersistentBookCtrl.

## ◆ SaveValue()

template<typename T >

bool wxPersistentObject::SaveValue | ( | const wxString & | name,
|  | T | value
| ) |  | const
| 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.