.\" This is a wxWidgets manpage page generated from the XML docs .TH wxConfigBase 3wx 2005-02-15 "wxWidgets" "wxWidgets class documentation" .SH NAME wxConfigBase \- .SH DESCRIPTION wxConfigBase class defines the basic interface of all config classes. It can not be used by itself (it is an abstract base class) and you will always use one of its derivations: wxFileConfig , wxRegConfig or any other. However, usually you don't even need to know the precise nature of the class you're working with but you would just use the wxConfigBase methods. This allows you to write the same code regardless of whether you're working with the registry under Win32 or text-based config files under Unix (or even Windows 3.1 .INI files if you're really unlucky). To make writing the portable code even easier, wxWidgets provides a typedef wxConfig which is mapped onto the native wxConfigBase implementation on the given platform: i.e. wxRegConfig under Win32 and wxFileConfig otherwise. See config overview for the descriptions of all features of this class. It is highly recommended to use static functions Get() and/or Set() , so please have a look at them. .SH "PARENTS" .SH "INCLUDE FILES" wx/config.hto let wxWidgets choose a wxConfig class for your platformwx/confbase.hbase config classwx/fileconf.hwxFileConfig classwx/msw/regconf.hwxRegConfig class .SH MEMBERS .SS wxConfigBase (const wxString& appName = wxEmptyStringconst wxString& vendorName = wxEmptyStringconst wxString& localFilename = wxEmptyStringconst wxString& globalFilename = wxEmptyStringlong style = 0wxMBConv& conv = wxConvUTF8) This is the default and only constructor of the wxConfigBase class, and derived classes. .SS ~wxConfigBase () Empty but ensures that dtor of all derived classes is virtual. .SS static wxConfigBase * Create () Create a new config object: this function will create the "best" implementation of wxConfig available for the current platform, see comments near the definition of wxCONFIG_WIN32_NATIVE for details. It returns the created object and also sets it as the current one. .SS void DontCreateOnDemand () Calling this function will prevent Get() from automatically creating a new config object if the current one is NULL. It might be useful to call it near the program end to prevent "accidental" creation of a new config object. .SS bool DeleteAll () Delete the whole underlying object (disk file, registry key, ...). Primarly for use by uninstallation routine. .SS bool DeleteEntry (const wxString& keybool bDeleteGroupIfEmpty = true) Deletes the specified entry and the group it belongs to if it was the last key in it and the second parameter is true. .SS bool DeleteGroup (const wxString& key) Delete the group (with all subgroups) .SS bool Exists (wxString& strName) returns true if either a group or an entry with a given name exists .SS bool Flush (bool bCurrentOnly = false) permanently writes all changes (otherwise, they're only written from object's destructor) .SS static wxConfigBase * Get (bool CreateOnDemand = true) Get the current config object. If there is no current object and CreateOnDemand is true, creates one (using Create ) unless DontCreateOnDemand was called previously. .SS wxString GetAppName () Returns the application name. .SS enum wxConfigBase::EntryType GetEntryType (const wxString& name) Returns the type of the given entry or Unknown if the entry doesn't exist. This function should be used to decide which version of Read() should be used because some of wxConfig implementations will complain about type mismatch otherwise: e.g., an attempt to read a string value from an integer key with wxRegConfig will fail. The result is an element of enum EntryType: enum EntryType { Type_Unknown, Type_String, Type_Boolean, Type_Integer, Type_Float }; .SS bool GetFirstGroup (wxString& strlong& index) Gets the first group. .SS bool GetFirstEntry (wxString& strlong& index) Gets the first entry. .SS bool GetNextGroup (wxString& strlong& index) Gets the next group. .SS bool GetNextEntry (wxString& strlong& index) Gets the next entry. .SS uint GetNumberOfEntries (bool bRecursive = false) .SS uint GetNumberOfGroups (bool bRecursive = false) Get number of entries/subgroups in the current group, with or without its subgroups. .SS const wxString& GetPath () Retrieve the current path (always as absolute path). .SS wxString GetVendorName () Returns the vendor name. .SS bool HasEntry (wxString& strName) returns true if the entry by this name exists .SS bool HasGroup (const wxString& strName) returns true if the group by this name exists .SS bool IsExpandingEnvVars () Returns true if we are expanding environment variables in key values. .SS bool IsRecordingDefaults () Returns true if we are writing defaults back to the config file. .SS bool Read (const wxString& keywxString* str) Read a string from the key, returning true if the value was read. If the key was not found, str is not changed. .SS bool Read (const wxString& keywxString* strconst wxString& defaultVal) Read a string from the key. The default value is returned if the key was not found. Returns true if value was really read, false if the default was used. .SS wxString Read (const wxString& keyconst wxString& defaultVal) Another version of Read() , returning the string value directly. .SS bool Read (const wxString& keylong* l) Reads a long value, returning true if the value was found. If the value was not found, l is not changed. .SS bool Read (const wxString& keylong* llong defaultVal) Reads a long value, returning true if the value was found. If the value was not found, defaultVal is used instead. .SS long Read (const wxString& keylong defaultVal) Reads a long value from the key and returns it. defaultVal is returned if the key is not found. NB: writing conf->Read("key", 0); won't work because the call is ambiguous: compiler can not choose between two Read functions. Instead, write: conf->Read("key", 0l); .SS bool Read (const wxString& keydouble* d) Reads a double value, returning true if the value was found. If the value was not found, d is not changed. .SS bool Read (const wxString& keydouble* ddouble defaultVal) Reads a double value, returning true if the value was found. If the value was not found, defaultVal is used instead. .SS bool Read (const wxString& keybool* b) Reads a bool value, returning true if the value was found. If the value was not found, b is not changed. .SS bool Read (const wxString& keybool* dbool defaultVal) Reads a bool value, returning true if the value was found. If the value was not found, defaultVal is used instead. .SS bool RenameEntry (const wxString& oldNameconst wxString& newName) Renames an entry in the current group. The entries names (both the old and the new one) shouldn't contain backslashes, i.e. only simple names and not arbitrary paths are accepted by this function. Returns false if oldName doesn't exist or if newName already exists. .SS bool RenameGroup (const wxString& oldNameconst wxString& newName) Renames a subgroup of the current group. The subgroup names (both the old and the new one) shouldn't contain backslashes, i.e. only simple names and not arbitrary paths are accepted by this function. Returns false if oldName doesn't exist or if newName already exists. .SS static wxConfigBase * Set (wxConfigBase *pConfig) Sets the config object as the current one, returns the pointer to the previous current object (both the parameter and returned value may be NULL) .SS void SetExpandEnvVars (bool bDoIt = true) Determine whether we wish to expand environment variables in key values. .SS void SetPath (const wxString& strPath) 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. .SS void SetRecordDefaults (bool bDoIt = true) Sets whether defaults are recorded to the config file whenever an attempt to read the value which is not present in it is done. If on (default is off) all default values for the settings used by the program are written back to the config file. This allows the user to see what config options may be changed and is probably useful only for wxFileConfig. .SS bool Write (const wxString& keyconst wxString& value) .SS bool Write (const wxString& keylong value) .SS bool Write (const wxString& keydouble value) .SS bool Write (const wxString& keybool value) These functions write the specified value to the config file and return true on success. .SH EXAMPLE Here is how you would typically use this class: // using wxConfig instead of writing wxFileConfig or wxRegConfig enhances // portability of the code wxConfig *config = new wxConfig("MyAppName"); wxString str; if ( config->Read("LastPrompt", &str) ) { // last prompt was found in the config file/registry and its value is now // in str ... } else { // no last prompt... } // another example: using default values and the full path instead of just // key name: if the key is not found , the value 17 is returned long value = config->Read("/LastRun/CalculatedValues/MaxValue", 17); ... ... ... // at the end of the program we would save everything back config->Write("LastPrompt", str); config->Write("/LastRun/CalculatedValues/MaxValue", value); // the changes will be written back automatically delete config; This basic example, of course, doesn't show all wxConfig features, such as enumerating, testing for existence and deleting the entries and groups of entries in the config file, its abilities to automatically store the default values or expand the environment variables on the fly. However, the main idea is that using this class is easy and that it should normally do what you expect it to. NB: in the documentation of this class, the words "config file" also mean "registry hive" for wxRegConfig and, generally speaking, might mean any physical storage where a wxConfigBase-derived class stores its data. .SH "SEE ALSO" .SH "AUTHORS" Documentation content by Julian Smart, Robert Roebling, Vadim Zeitlin, Robin Dunn, et al Conversion to manpage format by Arnout Engelen (http://bzzt.net), bugreports welcome.