regconf.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/msw/regconf.h
  3. // Purpose: Registry based implementation of wxConfigBase
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 27.04.98
  7. // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_MSW_REGCONF_H_
  11. #define _WX_MSW_REGCONF_H_
  12. #include "wx/defs.h"
  13. #if wxUSE_CONFIG && wxUSE_REGKEY
  14. #include "wx/msw/registry.h"
  15. #include "wx/object.h"
  16. #include "wx/confbase.h"
  17. #include "wx/buffer.h"
  18. // ----------------------------------------------------------------------------
  19. // wxRegConfig
  20. // ----------------------------------------------------------------------------
  21. class WXDLLIMPEXP_BASE wxRegConfig : public wxConfigBase
  22. {
  23. public:
  24. // ctor & dtor
  25. // will store data in HKLM\appName and HKCU\appName
  26. wxRegConfig(const wxString& appName = wxEmptyString,
  27. const wxString& vendorName = wxEmptyString,
  28. const wxString& localFilename = wxEmptyString,
  29. const wxString& globalFilename = wxEmptyString,
  30. long style = wxCONFIG_USE_GLOBAL_FILE);
  31. // dtor will save unsaved data
  32. virtual ~wxRegConfig(){}
  33. // implement inherited pure virtual functions
  34. // ------------------------------------------
  35. // path management
  36. virtual void SetPath(const wxString& strPath);
  37. virtual const wxString& GetPath() const { return m_strPath; }
  38. // entry/subgroup info
  39. // enumerate all of them
  40. virtual bool GetFirstGroup(wxString& str, long& lIndex) const;
  41. virtual bool GetNextGroup (wxString& str, long& lIndex) const;
  42. virtual bool GetFirstEntry(wxString& str, long& lIndex) const;
  43. virtual bool GetNextEntry (wxString& str, long& lIndex) const;
  44. // tests for existence
  45. virtual bool HasGroup(const wxString& strName) const;
  46. virtual bool HasEntry(const wxString& strName) const;
  47. virtual EntryType GetEntryType(const wxString& name) const;
  48. // get number of entries/subgroups in the current group, with or without
  49. // it's subgroups
  50. virtual size_t GetNumberOfEntries(bool bRecursive = false) const;
  51. virtual size_t GetNumberOfGroups(bool bRecursive = false) const;
  52. virtual bool Flush(bool WXUNUSED(bCurrentOnly) = false) { return true; }
  53. // rename
  54. virtual bool RenameEntry(const wxString& oldName, const wxString& newName);
  55. virtual bool RenameGroup(const wxString& oldName, const wxString& newName);
  56. // delete
  57. virtual bool DeleteEntry(const wxString& key, bool bGroupIfEmptyAlso = true);
  58. virtual bool DeleteGroup(const wxString& key);
  59. virtual bool DeleteAll();
  60. protected:
  61. // opens the local key creating it if necessary and returns it
  62. wxRegKey& LocalKey() const // must be const to be callable from const funcs
  63. {
  64. wxRegConfig* self = wxConstCast(this, wxRegConfig);
  65. if ( !m_keyLocal.IsOpened() )
  66. {
  67. // create on demand
  68. self->m_keyLocal.Create();
  69. }
  70. return self->m_keyLocal;
  71. }
  72. // implement read/write methods
  73. virtual bool DoReadString(const wxString& key, wxString *pStr) const;
  74. virtual bool DoReadLong(const wxString& key, long *plResult) const;
  75. virtual bool DoReadBinary(const wxString& key, wxMemoryBuffer* buf) const;
  76. virtual bool DoWriteString(const wxString& key, const wxString& szValue);
  77. virtual bool DoWriteLong(const wxString& key, long lValue);
  78. virtual bool DoWriteBinary(const wxString& key, const wxMemoryBuffer& buf);
  79. private:
  80. // these keys are opened during all lifetime of wxRegConfig object
  81. wxRegKey m_keyLocalRoot, m_keyLocal,
  82. m_keyGlobalRoot, m_keyGlobal;
  83. // current path (not '/' terminated)
  84. wxString m_strPath;
  85. wxDECLARE_NO_COPY_CLASS(wxRegConfig);
  86. DECLARE_ABSTRACT_CLASS(wxRegConfig)
  87. };
  88. #endif // wxUSE_CONFIG && wxUSE_REGKEY
  89. #endif // _WX_MSW_REGCONF_H_