Version: 3.1.5

#include <wx/fileconf.h>

+ Inheritance diagram for wxFileConfig:

Detailed Description

wxFileConfig implements wxConfigBase interface for storing and retrieving configuration information using plain text files.

The files have a simple format reminiscent of Windows INI files with lines of the form "key = value" defining the keys and lines of special form "[group]" indicating the start of each group.

This class is used by default for wxConfig on Unix platforms but may also be used explicitly if you want to use files and not the registry even under Windows.

Library:  wxBase
Category:  Application and System configuration
See also
wxFileConfig::Save

Public Member Functions

 wxFileConfig (const wxString &appName=wxEmptyString, const wxString &vendorName=wxEmptyString, const wxString &localFilename=wxEmptyString, const wxString &globalFilename=wxEmptyString, long style=wxCONFIG_USE_LOCAL_FILE|wxCONFIG_USE_GLOBAL_FILE, const wxMBConv &conv=wxConvAuto())
 Constructor allowing to choose the file names to use. More...
 
 wxFileConfig (wxInputStream &is, const wxMBConv &conv=wxConvAuto())
 Read the config data from the specified stream instead of the associated file, as usual. More...
 
virtual bool Save (wxOutputStream &os, const wxMBConv &conv=wxConvAuto())
 Saves all config data to the given stream, returns true if data was saved successfully or false on error. More...
 
void EnableAutoSave ()
 Enables saving data to the disk file when this object is destroyed. More...
 
void DisableAutoSave ()
 Prevent this object from saving data to the disk file when it is destroyed. More...
 
void SetUmask (int mode)
 Allows setting the mode to be used for the config file creation. More...
 
virtual void SetPath (const wxString &strPath)
 Set current path: if the first character is '/', it is the absolute path, otherwise it is a relative path. More...
 
virtual const wxStringGetPath () const
 Retrieve the current path (always as absolute path). More...
 
virtual bool GetFirstGroup (wxString &str, long &lIndex) const
 Gets the first group. More...
 
virtual bool GetNextGroup (wxString &str, long &lIndex) const
 Gets the next group. More...
 
virtual bool GetFirstEntry (wxString &str, long &lIndex) const
 Gets the first entry. More...
 
virtual bool GetNextEntry (wxString &str, long &lIndex) const
 Gets the next entry. More...
 
virtual size_t GetNumberOfEntries (bool bRecursive=false) const
 Get number of entries in the current group. More...
 
virtual size_t GetNumberOfGroups (bool bRecursive=false) const
 Get number of entries/subgroups in the current group, with or without its subgroups. More...
 
virtual bool HasGroup (const wxString &strName) const
 
virtual bool HasEntry (const wxString &strName) const
 
virtual bool Flush (bool bCurrentOnly=false)
 Permanently writes all changes (otherwise, they're only written from object's destructor). More...
 
virtual bool RenameEntry (const wxString &oldName, const wxString &newName)
 
virtual bool RenameGroup (const wxString &oldName, const wxString &newName)
 
virtual bool DeleteEntry (const wxString &key, bool bGroupIfEmptyAlso=true)
 
virtual bool DeleteGroup (const wxString &szKey)
 
virtual bool DeleteAll ()
 
- Public Member Functions inherited from wxConfigBase
 wxConfigBase (const wxString &appName=wxEmptyString, const wxString &vendorName=wxEmptyString, const wxString &localFilename=wxEmptyString, const wxString &globalFilename=wxEmptyString, long style=0, const wxMBConv &conv=wxConvAuto())
 This is the default and only constructor of the wxConfigBase class, and derived classes. More...
 
virtual ~wxConfigBase ()
 Empty but ensures that dtor of all derived classes is virtual. More...
 
bool Exists (const wxString &strName) const
 
virtual wxConfigBase::EntryType GetEntryType (const wxString &name) const
 Returns the type of the given entry or Unknown if the entry doesn't exist. More...
 
wxString GetAppName () const
 Returns the application name. More...
 
wxString GetVendorName () const
 Returns the vendor name. More...
 
bool Read (const wxString &key, wxString *str) const
 Read a string from the key, returning true if the value was read. More...
 
bool Read (const wxString &key, wxString *str, const wxString &defaultVal) const
 Read a string from the key. More...
 
const wxString Read (const wxString &key, const wxString &defaultVal) const
 Another version of Read(), returning the string value directly. More...
 
bool Read (const wxString &key, long *l) const
 Reads a long value, returning true if the value was found. More...
 
bool Read (const wxString &key, long *l, long defaultVal) const
 Reads a long value, returning true if the value was found. More...
 
bool Read (const wxString &key, wxLongLong_t *ll) const
 Reads a 64-bit long long value, returning true if the value was found. More...
 
- Public Member Functions inherited from wxObject
 wxObject ()
 Default ctor; initializes to NULL the internal reference data. More...
 
 wxObject (const wxObject &other)
 Copy ctor. More...
 
virtual ~wxObject ()
 Destructor. More...
 
virtual wxClassInfoGetClassInfo () const
 This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More...
 
wxObjectRefDataGetRefData () const
 Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More...
 
bool IsKindOf (const wxClassInfo *info) const
 Determines whether this class is a subclass of (or the same class as) the given class. More...
 
bool IsSameAs (const wxObject &obj) const
 Returns true if this object has the same data pointer as obj. More...
 
void Ref (const wxObject &clone)
 Makes this object refer to the data in clone. More...
 
void SetRefData (wxObjectRefData *data)
 Sets the wxObject::m_refData pointer. More...
 
void UnRef ()
 Decrements the reference count in the associated data, and if it is zero, deletes the data. More...
 
void UnShare ()
 This is the same of AllocExclusive() but this method is public. More...
 
void operator delete (void *buf)
 The delete operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined. More...
 
void * operator new (size_t size, const wxString &filename=NULL, int lineNum=0)
 The new operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined. More...
 

Static Public Member Functions

static wxFileName GetGlobalFile (const wxString &basename)
 Return the full path to the file which would be used by wxFileConfig as global, system-wide, file if it were constructed with basename as "global filename" parameter in the constructor. More...
 
static wxFileName GetLocalFile (const wxString &basename, int style=0)
 Return the full path to the file which would be used by wxFileConfig as local, user-specific, file if it were constructed with basename as "local filename" parameter in the constructor. More...
 
static wxString GetGlobalFileName (const wxString &szFile)
 
static wxString GetLocalFileName (const wxString &szFile, int style=0)
 

Additional Inherited Members

- Public Types inherited from wxConfigBase
enum  EntryType {
  Type_Unknown,
  Type_String,
  Type_Boolean,
  Type_Integer,
  Type_Float
}
 
- Protected Member Functions inherited from wxObject
void AllocExclusive ()
 Ensure that this object's data is not shared with any other object. More...
 
virtual wxObjectRefDataCreateRefData () const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More...
 
virtual wxObjectRefDataCloneRefData (const wxObjectRefData *data) const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. More...
 
- Protected Attributes inherited from wxObject
wxObjectRefDatam_refData
 Pointer to an object which is the object's reference-counted data. More...
 

Constructor & Destructor Documentation

wxFileConfig::wxFileConfig ( const wxString appName = wxEmptyString,
const wxString vendorName = wxEmptyString,
const wxString localFilename = wxEmptyString,
const wxString globalFilename = wxEmptyString,
long  style = wxCONFIG_USE_LOCAL_FILE|wxCONFIG_USE_GLOBAL_FILE,
const wxMBConv conv = wxConvAuto() 
)

Constructor allowing to choose the file names to use.

If localFilename and/or globalFilename are explicitly specified, they are used as the names of the user and system-wide configuration files (the latter is only read by the program while the former is read from and written to). Otherwise the behaviour depends on style parameter. If it includes wxCONFIG_USE_LOCAL_FILE, then the local file name is constructed from the information in appName and vendorName arguments in a system-dependent way. If wxCONFIG_USE_GLOBAL_FILE is not specified at all (and globalFilename is empty) then the system-wide file is not used at all. Otherwise its name and path are also constructed in the way appropriate for the current platform from the application and vendor names.

wxFileConfig::wxFileConfig ( wxInputStream is,
const wxMBConv conv = wxConvAuto() 
)

Read the config data from the specified stream instead of the associated file, as usual.

See also
Save()

Member Function Documentation

virtual bool wxFileConfig::DeleteAll ( )
virtual
virtual bool wxFileConfig::DeleteEntry ( const wxString key,
bool  bGroupIfEmptyAlso = true 
)
virtual
virtual bool wxFileConfig::DeleteGroup ( const wxString szKey)
virtual
void wxFileConfig::DisableAutoSave ( )

Prevent this object from saving data to the disk file when it is destroyed.

By default, changes to this object are only saved permanently when Flush() is explicitly called or when it is destroyed. If this method is called, Flush() won't be called automatically from the destructor, meaning that any non-explicitly-flushed changes will be lost.

Since
3.1.3
void wxFileConfig::EnableAutoSave ( )

Enables saving data to the disk file when this object is destroyed.

This is the default behaviour and this function doesn't need to be called explicitly unless DisableAutoSave() had been previously called.

Since
3.1.3
virtual bool wxFileConfig::Flush ( bool  bCurrentOnly = false)
virtual

Permanently writes all changes (otherwise, they're only written from object's destructor).

Implements wxConfigBase.

virtual bool wxFileConfig::GetFirstEntry ( wxString str,
long &  index 
) const
virtual

Gets the first entry.

wxPerl Note: In wxPerl this method takes no parameters and returns a 3-element list (continue_flag, string, index_for_getnextentry).

Implements wxConfigBase.

virtual bool wxFileConfig::GetFirstGroup ( wxString str,
long &  index 
) const
virtual

Gets the first group.

wxPerl Note: In wxPerl this method takes no parameters and returns a 3-element list (continue_flag, string, index_for_getnextentry).

Implements wxConfigBase.

static wxFileName wxFileConfig::GetGlobalFile ( const wxString basename)
static

Return the full path to the file which would be used by wxFileConfig as global, system-wide, file if it were constructed with basename as "global filename" parameter in the constructor.

Notice that this function cannot be used if basename is already a full path name.

static wxString wxFileConfig::GetGlobalFileName ( const wxString szFile)
static
static wxFileName wxFileConfig::GetLocalFile ( const wxString basename,
int  style = 0 
)
static

Return the full path to the file which would be used by wxFileConfig as local, user-specific, file if it were constructed with basename as "local filename" parameter in the constructor.

style has the same meaning as in wxConfig constructor and can contain any combination of styles but only wxCONFIG_USE_SUBDIR bit is examined by this function.

Notice that this function cannot be used if basename is already a full path name.

static wxString wxFileConfig::GetLocalFileName ( const wxString szFile,
int  style = 0 
)
static
virtual bool wxFileConfig::GetNextEntry ( wxString str,
long &  index 
) const
virtual

Gets the next entry.

wxPerl Note: In wxPerl this method only takes the index parameter and returns a 3-element list (continue_flag, string, index_for_getnextentry).

Implements wxConfigBase.

virtual bool wxFileConfig::GetNextGroup ( wxString str,
long &  index 
) const
virtual

Gets the next group.

wxPerl Note: In wxPerl this method only takes the index parameter and returns a 3-element list (continue_flag, string, index_for_getnextentry).

Implements wxConfigBase.

virtual size_t wxFileConfig::GetNumberOfEntries ( bool  bRecursive = false) const
virtual

Get number of entries in the current group.

Implements wxConfigBase.

virtual size_t wxFileConfig::GetNumberOfGroups ( bool  bRecursive = false) const
virtual

Get number of entries/subgroups in the current group, with or without its subgroups.

Implements wxConfigBase.

virtual const wxString& wxFileConfig::GetPath ( ) const
virtual

Retrieve the current path (always as absolute path).

Implements wxConfigBase.

virtual bool wxFileConfig::HasEntry ( const wxString strName) const
virtual
Returns
true if the entry by this name exists.

Implements wxConfigBase.

virtual bool wxFileConfig::HasGroup ( const wxString strName) const
virtual
Returns
true if the group by this name exists.

Implements wxConfigBase.

virtual bool wxFileConfig::RenameEntry ( const wxString oldName,
const wxString newName 
)
virtual
virtual bool wxFileConfig::RenameGroup ( const wxString oldName,
const wxString newName 
)
virtual
virtual bool wxFileConfig::Save ( wxOutputStream os,
const wxMBConv conv = wxConvAuto() 
)
virtual

Saves all config data to the given stream, returns true if data was saved successfully or false on error.

Note the interaction of this function with the internal "dirty flag": the data is saved unconditionally, i.e. even if the object is not dirty. However after saving it successfully, the dirty flag is reset so no changes will be written back to the file this object is associated with until you change its contents again.

See also
wxConfigBase::Flush
virtual void wxFileConfig::SetPath ( const wxString strPath)
virtual

Set current path: if the first character is '/', it is the absolute path, otherwise it is a relative path.

'..' is supported. If strPath doesn't exist, it is created.

See also
wxConfigPathChanger

Implements wxConfigBase.

void wxFileConfig::SetUmask ( int  mode)

Allows setting the mode to be used for the config file creation.

For example, to create a config file which is not readable by other users (useful if it stores some sensitive information, such as passwords), you could use SetUmask(0077).

This function doesn't do anything on non-Unix platforms.

See also
wxCHANGE_UMASK()