]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/iniconf.h
Don't define __STRICT_ANSI__, we should build both with and without it.
[wxWidgets.git] / include / wx / msw / iniconf.h
CommitLineData
8f494e5d 1///////////////////////////////////////////////////////////////////////////////
233f5738 2// Name: wx/msw/iniconf.h
8f494e5d
VZ
3// Purpose: INI-file based wxConfigBase implementation
4// Author: Vadim Zeitlin
59af881e 5// Modified by:
8f494e5d 6// Created: 27.07.98
8f494e5d 7// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
65571936 8// Licence: wxWindows licence
8f494e5d
VZ
9///////////////////////////////////////////////////////////////////////////////
10
61873536
VZ
11#ifndef _WX_MSW_INICONF_H_
12#define _WX_MSW_INICONF_H_
13
101b2420
VZ
14#include "wx/defs.h"
15
16#if wxUSE_CONFIG && wxUSE_INICONF
8f494e5d
VZ
17
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]
27//
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.
31//
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// ----------------------------------------------------------------------------
36
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.
53a2db12 42class WXDLLIMPEXP_CORE wxIniConfig : public wxConfigBase
8f494e5d
VZ
43{
44public:
45 // ctor & dtor
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.
18244936
JS
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);
8f494e5d
VZ
51 virtual ~wxIniConfig();
52
53 // implement inherited pure virtual functions
54 virtual void SetPath(const wxString& strPath);
55 virtual const wxString& GetPath() const;
56
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;
61
59af881e
WS
62 virtual size_t GetNumberOfEntries(bool bRecursive = false) const;
63 virtual size_t GetNumberOfGroups(bool bRecursive = false) const;
8f494e5d
VZ
64
65 virtual bool HasGroup(const wxString& strName) const;
66 virtual bool HasEntry(const wxString& strName) const;
67
59af881e 68 // return true if the current group is empty
8f494e5d
VZ
69 bool IsEmpty() const;
70
59af881e 71 virtual bool Flush(bool bCurrentOnly = false);
8f494e5d 72
5d1902d6
VZ
73 virtual bool RenameEntry(const wxString& oldName, const wxString& newName);
74 virtual bool RenameGroup(const wxString& oldName, const wxString& newName);
75
59af881e 76 virtual bool DeleteEntry(const wxString& Key, bool bGroupIfEmptyAlso = true);
1e6d9499 77 virtual bool DeleteGroup(const wxString& szKey);
8f494e5d
VZ
78 virtual bool DeleteAll();
79
2ba41305
VZ
80protected:
81 // read/write
82 bool DoReadString(const wxString& key, wxString *pStr) const;
83 bool DoReadLong(const wxString& key, long *plResult) const;
5814e8ba 84 bool DoReadBinary(const wxString& key, wxMemoryBuffer *buf) const;
2ba41305
VZ
85
86 bool DoWriteString(const wxString& key, const wxString& szValue);
87 bool DoWriteLong(const wxString& key, long lValue);
5814e8ba 88 bool DoWriteBinary(const wxString& key, const wxMemoryBuffer& buf);
2ba41305 89
8f494e5d
VZ
90private:
91 // helpers
18244936
JS
92 wxString GetPrivateKeyName(const wxString& szKey) const;
93 wxString GetKeyName(const wxString& szKey) const;
8f494e5d 94
18244936 95 wxString m_strLocalFilename; // name of the private INI file
8f494e5d
VZ
96 wxString m_strGroup, // current group in appname.ini file
97 m_strPath; // the rest of the path (no trailing '_'!)
c4ec0ce8 98
c0c133e1 99 wxDECLARE_NO_COPY_CLASS(wxIniConfig);
c4ec0ce8 100 DECLARE_ABSTRACT_CLASS(wxIniConfig)
8f494e5d
VZ
101};
102
101b2420 103#endif // wxUSE_CONFIG && wxUSE_INICONF
61873536 104
101b2420 105#endif // _WX_MSW_INICONF_H_