]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/iniconf.h
added disambiguation for Clear() too
[wxWidgets.git] / include / wx / msw / iniconf.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/msw/iniconf.h
3 // Purpose: INI-file based wxConfigBase implementation
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 27.07.98
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_MSW_INICONF_H_
13 #define _WX_MSW_INICONF_H_
14
15 #if wxUSE_INICONF
16
17 // ----------------------------------------------------------------------------
18 // wxIniConfig is a wxConfig implementation which uses MS Windows INI files to
19 // store the data. Because INI files don't really support arbitrary nesting of
20 // groups, we do the following:
21 // (1) in win.ini file we store all entries in the [vendor] section and
22 // the value group1/group2/key is mapped to the value group1_group2_key
23 // in this section, i.e. all path separators are replaced with underscore
24 // (2) in appname.ini file we map group1/group2/group3/key to the entry
25 // group2_group3_key in [group1]
26 //
27 // Of course, it might lead to indesirable results if '_' is also used in key
28 // names (i.e. group/key is the same as group_key) and also GetPath() result
29 // may be not what you would expect it to be.
30 //
31 // Another limitation: the keys and section names are never case-sensitive
32 // which might differ from wxFileConfig it it was compiled with
33 // wxCONFIG_CASE_SENSITIVE option.
34 // ----------------------------------------------------------------------------
35
36 // for this class, "local" file is the file appname.ini and the global file
37 // is the [vendor] subsection of win.ini (default for "vendor" is to be the
38 // same as appname). The file name (strAppName parameter) may, in fact,
39 // contain the full path to the file. If it doesn't, the file is searched for
40 // in the Windows directory.
41 class WXDLLEXPORT wxIniConfig : public wxConfigBase
42 {
43 public:
44 // ctor & dtor
45 // if strAppName doesn't contain the extension and is not an absolute path,
46 // ".ini" is appended to it. if strVendor is empty, it's taken to be the
47 // same as strAppName.
48 wxIniConfig(const wxString& strAppName = wxEmptyString, const wxString& strVendor = wxEmptyString,
49 const wxString& localFilename = wxEmptyString, const wxString& globalFilename = wxEmptyString, long style = wxCONFIG_USE_LOCAL_FILE);
50 virtual ~wxIniConfig();
51
52 // implement inherited pure virtual functions
53 virtual void SetPath(const wxString& strPath);
54 virtual const wxString& GetPath() const;
55
56 virtual bool GetFirstGroup(wxString& str, long& lIndex) const;
57 virtual bool GetNextGroup (wxString& str, long& lIndex) const;
58 virtual bool GetFirstEntry(wxString& str, long& lIndex) const;
59 virtual bool GetNextEntry (wxString& str, long& lIndex) const;
60
61 virtual size_t GetNumberOfEntries(bool bRecursive = false) const;
62 virtual size_t GetNumberOfGroups(bool bRecursive = false) const;
63
64 virtual bool HasGroup(const wxString& strName) const;
65 virtual bool HasEntry(const wxString& strName) const;
66
67 // return true if the current group is empty
68 bool IsEmpty() const;
69
70 virtual bool Flush(bool bCurrentOnly = false);
71
72 virtual bool RenameEntry(const wxString& oldName, const wxString& newName);
73 virtual bool RenameGroup(const wxString& oldName, const wxString& newName);
74
75 virtual bool DeleteEntry(const wxString& Key, bool bGroupIfEmptyAlso = true);
76 virtual bool DeleteGroup(const wxString& szKey);
77 virtual bool DeleteAll();
78
79 protected:
80 // read/write
81 bool DoReadString(const wxString& key, wxString *pStr) const;
82 bool DoReadLong(const wxString& key, long *plResult) const;
83 bool DoReadBinary(const wxString& key, wxMemoryBuffer *buf) const;
84
85 bool DoWriteString(const wxString& key, const wxString& szValue);
86 bool DoWriteLong(const wxString& key, long lValue);
87 bool DoWriteBinary(const wxString& key, const wxMemoryBuffer& buf);
88
89 private:
90 // helpers
91 wxString GetPrivateKeyName(const wxString& szKey) const;
92 wxString GetKeyName(const wxString& szKey) const;
93
94 wxString m_strLocalFilename; // name of the private INI file
95 wxString m_strGroup, // current group in appname.ini file
96 m_strPath; // the rest of the path (no trailing '_'!)
97
98 DECLARE_NO_COPY_CLASS(wxIniConfig)
99 DECLARE_ABSTRACT_CLASS(wxIniConfig)
100 };
101
102 #endif // wxUSE_INICONF
103
104 #endif //_WX_MSW_INICONF_H_