wxWidgets: wxConfigPathChanger Class Reference

| Version: 3.1.5

Loading...
Searching...
No Matches
Public Member Functions | List of all members
wxConfigPathChanger Class Reference
Class List by Category » Application and System configuration

`#include </cygdrive/c/Users/Hamis/Cygwin-packaging/wxWidgets3.1/wxWidgets3.1-3.1.5-4.x86_64/src/wxWidgets-3.1.5/interface/wx/config.h>`

## Detailed Description

A handy little class which changes the current path in a wxConfig object and restores it in dtor.

Declaring a local variable of this type, it's possible to work in a specific directory and ensure that the path is automatically restored when the function returns.

For example:

// this function loads some settings from the given wxConfig object;
// the path selected inside it is left unchanged
bool LoadMySettings(wxConfigBase* cfg)
{
wxConfigPathChanger changer(cfg, "/Foo/Data/SomeString");
wxString str;
if ( !config->Read("SomeString", &str) ) {
wxLogError("Couldn't read SomeString!");
return false;
// NOTE: without wxConfigPathChanger it would be easy to forget to
// set the old path back into the wxConfig object before this return!
}
// do something useful with SomeString...
return true; // again: wxConfigPathChanger dtor will restore the original wxConfig path
}
wxConfigBase
wxConfigBase defines the basic interface of all config classes.
Definition config.h:260
wxConfigPathChanger::wxConfigPathChanger
wxConfigPathChanger(const wxConfigBase *pContainer, const wxString &strEntry)
Changes the path of the given wxConfigBase object so that the key strEntry is accessible (for read or...
wxString
String class for passing textual data to or receiving it from wxWidgets.
Definition string.h:315
wxLogError
void wxLogError(const char *formatString,...)
The functions to use for error messages, i.e.

##

Library: wxBase

<>< =''>:</>&;&;< =''>\ </></>

## Public Member Functions
| wxConfigPathChanger (const wxConfigBase *pContainer, const wxString &strEntry)
| Changes the path of the given wxConfigBase object so that the key strEntry is accessible (for read or write).
| ~wxConfigPathChanger ()
| Restores the path selected, inside the wxConfig object passed to the ctor, to the path which was selected when the wxConfigPathChanger ctor was called.
const wxString & | Name () const
| Returns the name of the key which was passed to the ctor.
void | UpdateIfDeleted ()
| This method must be called if the original path inside the wxConfig object (i.e.

## Constructor & Destructor Documentation

## ◆ wxConfigPathChanger()

wxConfigPathChanger::wxConfigPathChanger | ( | const wxConfigBase * | pContainer,
|  | const wxString & | strEntry )

Changes the path of the given wxConfigBase object so that the key strEntry is accessible (for read or write).

In other words, the ctor uses wxConfigBase::SetPath() with everything which precedes the last slash of strEntry, so that:

wxConfigPathChanger(wxConfigBase::Get(), "/MyProgram/SomeKeyName");

has the same effect of:

wxConfigPathChanger(wxConfigBase::Get(), "/MyProgram/");

## ◆ ~wxConfigPathChanger()

wxConfigPathChanger::~wxConfigPathChanger | ( |  | ) |

Restores the path selected, inside the wxConfig object passed to the ctor, to the path which was selected when the wxConfigPathChanger ctor was called.

## Member Function Documentation

## ◆ Name()

const wxString & wxConfigPathChanger::Name | ( |  | ) | const

Returns the name of the key which was passed to the ctor.

The "name" is just anything which follows the last slash of the string given to the ctor.

## ◆ UpdateIfDeleted()

void wxConfigPathChanger::UpdateIfDeleted | ( |  | ) |

This method must be called if the original path inside the wxConfig object (i.e.

the current path at the moment of creation of this wxConfigPathChanger object) could have been deleted, thus preventing wxConfigPathChanger from restoring the not existing (any more) path.

If the original path doesn't exist any more, the path will be restored to the deepest still existing component of the old path.