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