wxPersistentObject Class Reference | wxWidgets

| Version: 3.2.11

Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
wxPersistentObject Class Referenceabstract

`#include </cygdrive/c/Users/Hamis/Cygwin-packaging/wxWidgets3.2/wxWidgets3.2-3.2.11-1.x86_64/src/wxWidgets-3.2.11/interface/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.
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 a value saved by SaveValue().

## 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< wxComboBox >, wxPersistentWindow< wxDataViewCtrl >, 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 wxPersistentBookCtrl, wxPersistentComboBox, wxPersistentDataViewCtrl, wxPersistentTLW, and wxPersistentTreeBookCtrl.

## ◆ 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 wxPersistentBookCtrl, wxPersistentComboBox, wxPersistentDataViewCtrl, wxPersistentTLW, and wxPersistentTreeBookCtrl.

## ◆ 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.