iniconf.h 5.4 KB

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