iniconf.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/msw/iniconf.h
  3. // Purpose: INI-file based wxConfigBase implementation
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 27.07.98
  7. // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_MSW_INICONF_H_
  11. #define _WX_MSW_INICONF_H_
  12. #include "wx/defs.h"
  13. #if wxUSE_CONFIG && wxUSE_INICONF
  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]
  23. //
  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.
  27. //
  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. // ----------------------------------------------------------------------------
  32. // for this class, "local" file is the file appname.ini and the global file
  33. // is the [vendor] subsection of win.ini (default for "vendor" is to be the
  34. // same as appname). The file name (strAppName parameter) may, in fact,
  35. // contain the full path to the file. If it doesn't, the file is searched for
  36. // in the Windows directory.
  37. class WXDLLIMPEXP_CORE wxIniConfig : public wxConfigBase
  38. {
  39. public:
  40. // ctor & dtor
  41. // if strAppName doesn't contain the extension and is not an absolute path,
  42. // ".ini" is appended to it. if strVendor is empty, it's taken to be the
  43. // same as strAppName.
  44. wxIniConfig(const wxString& strAppName = wxEmptyString, const wxString& strVendor = wxEmptyString,
  45. const wxString& localFilename = wxEmptyString, const wxString& globalFilename = wxEmptyString, long style = wxCONFIG_USE_LOCAL_FILE);
  46. virtual ~wxIniConfig();
  47. // implement inherited pure virtual functions
  48. virtual void SetPath(const wxString& strPath);
  49. virtual const wxString& GetPath() const;
  50. virtual bool GetFirstGroup(wxString& str, long& lIndex) const;
  51. virtual bool GetNextGroup (wxString& str, long& lIndex) const;
  52. virtual bool GetFirstEntry(wxString& str, long& lIndex) const;
  53. virtual bool GetNextEntry (wxString& str, long& lIndex) const;
  54. virtual size_t GetNumberOfEntries(bool bRecursive = false) const;
  55. virtual size_t GetNumberOfGroups(bool bRecursive = false) const;
  56. virtual bool HasGroup(const wxString& strName) const;
  57. virtual bool HasEntry(const wxString& strName) const;
  58. // return true if the current group is empty
  59. bool IsEmpty() const;
  60. virtual bool Flush(bool bCurrentOnly = false);
  61. virtual bool RenameEntry(const wxString& oldName, const wxString& newName);
  62. virtual bool RenameGroup(const wxString& oldName, const wxString& newName);
  63. virtual bool DeleteEntry(const wxString& Key, bool bGroupIfEmptyAlso = true);
  64. virtual bool DeleteGroup(const wxString& szKey);
  65. virtual bool DeleteAll();
  66. protected:
  67. // read/write
  68. bool DoReadString(const wxString& key, wxString *pStr) const;
  69. bool DoReadLong(const wxString& key, long *plResult) const;
  70. bool DoReadBinary(const wxString& key, wxMemoryBuffer *buf) const;
  71. bool DoWriteString(const wxString& key, const wxString& szValue);
  72. bool DoWriteLong(const wxString& key, long lValue);
  73. bool DoWriteBinary(const wxString& key, const wxMemoryBuffer& buf);
  74. private:
  75. // helpers
  76. wxString GetPrivateKeyName(const wxString& szKey) const;
  77. wxString GetKeyName(const wxString& szKey) const;
  78. wxString m_strLocalFilename; // name of the private INI file
  79. wxString m_strGroup, // current group in appname.ini file
  80. m_strPath; // the rest of the path (no trailing '_'!)
  81. wxDECLARE_NO_COPY_CLASS(wxIniConfig);
  82. DECLARE_ABSTRACT_CLASS(wxIniConfig)
  83. };
  84. #endif // wxUSE_CONFIG && wxUSE_INICONF
  85. #endif // _WX_MSW_INICONF_H_