Version: 1.0.0
xmlconf.h
Go to the documentation of this file.
1 #ifndef _WX_MLBASE_XMLCONF_H_
2 #define _WX_MLBASE_XMLCONF_H_
3 
4 #include "wx/base/wxprec.h"
5 
6 //*****************************************************************************
7 // @file wxXmlConfig.h
8 // @author Nicolas Dextraze
9 // @web http://www.nicdex.com
10 // @date February 17, 2007
11 // @desc wxXmlConfig class header
12 //*****************************************************************************
13 #pragma once
14 
15 #include <wx/textfile.h>
16 #include <wx/confbase.h>
17 #include <wx/xml/xml.h>
18 #ifdef wxUSE_STREAMS
19 #include <wx/stream.h>
20 #endif
21 
22 class wxXmlConfig;
23 
24 /*AML
25 #ifdef wxConfig
26  #undef wxConfig
27 #endif
28 #define wxConfig wxXmlConfig
29 AML*/
30 
31 #define wxXmlConfigEntry wxXmlNode
32 #define wxXmlConfigGroup wxXmlNode
33 
35  : public wxConfigBase
36 {
37 public:
38  wxXmlConfig( const wxString& appName = wxEmptyString,
39  const wxString& vendorName = wxEmptyString,
40  const wxString& localFilename = wxEmptyString,
41  const wxString& globalFilename = wxEmptyString,
42  long style = wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_GLOBAL_FILE,
43  const wxMBConv& conv = wxConvAuto());
44 #ifdef wxUSE_STREAMS
45  wxXmlConfig( wxInputStream& inStream, const wxMBConv& conv = wxConvAuto() );
46 #endif
47  virtual ~wxXmlConfig();
48 
49  static wxString GetGlobalFileName( const wxChar *szFile );
50  static wxString GetLocalFileName( const wxChar *szFile );
51 
52  virtual void SetPath( const wxString& strPath );
53  virtual const wxString& GetPath() const { return m_strPath; }
54 
55  virtual bool GetFirstGroup( wxString& str, long& lIndex ) const;
56  virtual bool GetNextGroup( wxString& str, long& lIndex ) const;
57  virtual bool GetFirstEntry( wxString& str, long& lIndex ) const;
58  virtual bool GetNextEntry( wxString& str, long& lIndex ) const;
59 
60  virtual size_t GetNumberOfEntries( bool bRecursive = false ) const;
61  virtual size_t GetNumberOfGroups( bool bRecursive = false ) const;
62 
63  virtual bool HasGroup( const wxString& strName ) const;
64  virtual bool HasEntry( const wxString& strName ) const;
65 
66  virtual bool Flush( bool bCurrentOnly = false );
67 
68  virtual bool RenameEntry( const wxString& oldName, const wxString& newName );
69  virtual bool RenameGroup( const wxString& oldName, const wxString& newName );
70 
71  virtual bool DeleteEntry( const wxString& key, bool bGroupIfEmptyAlso = true );
72  virtual bool DeleteGroup( const wxString& key );
73  virtual bool DeleteAll();
74 
75 #if wxUSE_STREAMS
76  virtual bool Save( wxOutputStream& os, const wxMBConv& conv = wxConvAuto() );
77 #endif
78 
79 protected:
80  virtual bool DoReadString( const wxString& key, wxString* pStr ) const;
81  virtual bool DoReadLong( const wxString& key, long* pl ) const;
82 
83  virtual bool DoWriteString( const wxString& key, const wxString& szValue );
84  virtual bool DoWriteLong( const wxString& key, long lValue );
85 #if wxCHECK_VERSION(2,9,0) && wxUSE_BASE64
86  virtual bool DoReadBinary( const wxString& key, wxMemoryBuffer* buf ) const;
87  virtual bool DoWriteBinary( const wxString& key, const wxMemoryBuffer& buf );
88 #endif
89 private:
90  static wxString GetGlobalDir();
91  static wxString GetLocalDir();
92 
93  void Init();
94 
95  void CleanUp();
96 
97  void Parse( const wxXmlDocument& xmlDocument, bool bLocal );
98 
99  void SetRootPath();
100 
101  bool DoSetPath( const wxString& strPath, bool createMissingComponents );
102 
103  void SetDirty() { m_isDirty = true; }
104  void ResetDirty() { m_isDirty = false; }
105  bool IsDirty() { return m_isDirty; }
106 
107  bool IsGroup( const wxXmlConfigGroup *group ) const;
108  bool IsEntry( const wxXmlConfigEntry *entry ) const;
109 
110  wxXmlConfigEntry *FindEntry( const wxString& key ) const;
111  wxXmlConfigEntry *AddEntry( const wxString& key );
112  wxXmlConfigGroup *FindGroup( const wxString& key ) const;
113  wxXmlConfigGroup *AddGroup( const wxString& key );
114 
115  wxXmlDocument *m_xmlDoc;
117  wxString m_strLocalFile;
118  wxString m_strGlobalFile;
119  wxString m_strPath;
120  bool m_isDirty;
121 
122  wxDECLARE_NO_COPY_CLASS(wxXmlConfig);
123  wxDECLARE_ABSTRACT_CLASS(wxXmlConfig);
124 };
125 
126 #endif//_WX_MLBASE_XMLCONF_H_
bool m_isDirty
Definition: xmlconf.h:120
#define wxXmlConfigEntry
Definition: xmlconf.h:31
wxXmlDocument * m_xmlDoc
Definition: xmlconf.h:115
wxString m_strGlobalFile
Definition: xmlconf.h:118
void ResetDirty()
Definition: xmlconf.h:104
bool IsDirty()
Definition: xmlconf.h:105
#define WXDLLIMPEXP_MLBASE
Definition: base/dlimpexp.h:21
wxString m_strLocalFile
Definition: xmlconf.h:117
void SetDirty()
Definition: xmlconf.h:103
wxString m_strPath
Definition: xmlconf.h:119
#define wxXmlConfigGroup
Definition: xmlconf.h:32
virtual const wxString & GetPath() const
Definition: xmlconf.h:53
wxXmlConfigGroup * m_pCurrentGroup
Definition: xmlconf.h:116