1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/msw/iniconf.h
3 // Purpose: INI-file based wxConfigBase implementation
4 // Author: David Webster
7 // Copyright: David Webster
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
14 // ----------------------------------------------------------------------------
15 // wxIniConfig is a wxConfig implementation which uses MS Windows INI files to
16 // store the data. Because INI files don't really support arbitrary nesting of
17 // groups, we do the following:
18 // (1) in win.ini file we store all entries in the [vendor] section and
19 // the value group1/group2/key is mapped to the value group1_group2_key
20 // in this section, i.e. all path separators are replaced with underscore
21 // (2) in appname.ini file we map group1/group2/group3/key to the entry
22 // group2_group3_key in [group1]
24 // Of course, it might lead to indesirable results if '_' is also used in key
25 // names (i.e. group/key is the same as group_key) and also GetPath() result
26 // may be not what you would expect it to be.
28 // Another limitation: the keys and section names are never case-sensitive
29 // which might differ from wxFileConfig it it was compiled with
30 // wxCONFIG_CASE_SENSITIVE option.
31 // ----------------------------------------------------------------------------
33 // for this class, "local" file is the file appname.ini and the global file
34 // is the [vendor] subsection of win.ini (default for "vendor" is to be the
35 // same as appname). The file name (strAppName parameter) may, in fact,
36 // contain the full path to the file. If it doesn't, the file is searched for
37 // in the Windows directory.
38 class WXDLLIMPEXP_CORE wxIniConfig
: public wxConfigBase
42 // if strAppName doesn't contain the extension and is not an absolute path,
43 // ".ini" is appended to it. if strVendor is empty, it's taken to be the
44 // same as strAppName.
45 wxIniConfig(const wxString
& strAppName
= wxEmptyString
, const wxString
& strVendor
= wxEmptyString
,
46 const wxString
& localFilename
= wxEmptyString
, const wxString
& globalFilename
= wxEmptyString
, long style
= wxCONFIG_USE_LOCAL_FILE
);
47 virtual ~wxIniConfig();
49 // implement inherited pure virtual functions
50 virtual void SetPath(const wxString
& strPath
);
51 virtual const wxString
& GetPath() const;
53 virtual bool GetFirstGroup(wxString
& str
, long& lIndex
) const;
54 virtual bool GetNextGroup (wxString
& str
, long& lIndex
) const;
55 virtual bool GetFirstEntry(wxString
& str
, long& lIndex
) const;
56 virtual bool GetNextEntry (wxString
& str
, long& lIndex
) const;
58 virtual size_t GetNumberOfEntries(bool bRecursive
= FALSE
) const;
59 virtual size_t GetNumberOfGroups(bool bRecursive
= FALSE
) const;
61 virtual bool HasGroup(const wxString
& strName
) const;
62 virtual bool HasEntry(const wxString
& strName
) const;
64 // return TRUE if the current group is empty
68 bool Read(const wxString
& key
, wxString
*pStr
) const;
69 bool Read(const wxString
& key
, wxString
*pStr
, const wxString
& szDefault
) const;
70 bool Read(const wxString
& key
, long *plResult
) const;
72 // The following are necessary to satisfy the compiler
73 wxString
Read(const wxString
& key
, const wxString
& defVal
) const
74 { return wxConfigBase::Read(key
, defVal
); }
75 bool Read(const wxString
& key
, long *pl
, long defVal
) const
76 { return wxConfigBase::Read(key
, pl
, defVal
); }
77 long Read(const wxString
& key
, long defVal
) const
78 { return wxConfigBase::Read(key
, defVal
); }
79 bool Read(const wxString
& key
, int *pi
, int defVal
) const
80 { return wxConfigBase::Read(key
, pi
, defVal
); }
81 bool Read(const wxString
& key
, int *pi
) const
82 { return wxConfigBase::Read(key
, pi
); }
83 bool Read(const wxString
& key
, double* val
) const
84 { return wxConfigBase::Read(key
, val
); }
85 bool Read(const wxString
& key
, double* val
, double defVal
) const
86 { return wxConfigBase::Read(key
, val
, defVal
); }
88 bool Write(const wxString
& key
, const wxString
& szValue
);
89 bool Write(const wxString
& key
, long lValue
);
91 virtual bool Flush(bool bCurrentOnly
= FALSE
);
93 virtual bool RenameEntry(const wxString
& oldName
, const wxString
& newName
);
94 virtual bool RenameGroup(const wxString
& oldName
, const wxString
& newName
);
96 virtual bool DeleteEntry(const wxString
& Key
, bool bGroupIfEmptyAlso
);
97 virtual bool DeleteGroup(const wxString
& szKey
);
98 virtual bool DeleteAll();
102 wxString
GetPrivateKeyName(const wxString
& szKey
) const;
103 wxString
GetKeyName(const wxString
& szKey
) const;
105 wxString m_strLocalFilename
; // name of the private INI file
106 wxString m_strGroup
, // current group in appname.ini file
107 m_strPath
; // the rest of the path (no trailing '_'!)
108 // Virtual function hiding
109 virtual bool Read(const wxString
& key
, bool* val
) const
110 { return(wxConfigBase::Read(key
, val
));};
111 virtual bool Read(const wxString
& key
, bool* val
, bool defVal
) const
112 { return(wxConfigBase::Read(key
, val
, defVal
));};
113 virtual bool Write(const wxString
& key
, double value
)
114 { return(wxConfigBase::Write(key
, value
));};
115 virtual bool Write(const wxString
& key
, bool value
)
116 { return(wxConfigBase::Write(key
, value
));};
117 virtual bool Write(const wxString
& key
, const char* value
)
118 { return(wxConfigBase::Write(key
, value
));};