Version: 0.6.0
config.h
1 /******************************************************************************
2  * Project: wxGIS
3  * Purpose: wxGISConfig class.
4  * Author: Dmitry Baryshnikov (aka Bishop), polimax@mail.ru
5  ******************************************************************************
6 * Copyright (C) 2009,2011-2013 Dmitry Baryshnikov
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  ****************************************************************************/
21 #pragma once
22 
23 #include "wxgis/core/core.h"
24 
25 #include <wx/stdpaths.h>
26 #include <wx/filename.h>
27 #include <wx/hashmap.h>
28 #include <wx/xml/xml.h>
29 
30 WX_DECLARE_STRING_HASH_MAP( wxXmlNode*, wxGISConfigNodesMap );
31 
38 class WXDLLIMPEXP_GIS_CORE wxGISConfig : public wxObject
39 {
40  DECLARE_CLASS(wxGISConfig)
41 public:
42  wxGISConfig(void);
43  wxGISConfig(bool bPortable);
44  void Create(bool bPortable = false);
45  void ReportPaths(void);
46 
47  bool IsOk() const { return m_refData != NULL; };
48 
49  bool operator == ( const wxGISConfig& obj ) const;
50  bool operator != (const wxGISConfig& obj) const { return !(*this == obj); };
51 
52  wxString Read(wxGISEnumConfigKey Key, const wxString &sPath, const wxString &sDefaultValue);
53  int ReadInt(wxGISEnumConfigKey Key, const wxString &sPath, int nDefaultValue);
54  double ReadDouble(wxGISEnumConfigKey Key, const wxString &sPath, double dDefaultValue);
55  bool ReadBool(wxGISEnumConfigKey Key, const wxString &sPath, bool bDefaultValue);
56  bool Write(wxGISEnumConfigKey Key, const wxString &sPath, const wxString &sValue);
57  bool Write(wxGISEnumConfigKey Key, const wxString &sPath, bool bValue);
58  bool Write(wxGISEnumConfigKey Key, const wxString &sPath, int nValue);
59 
60  static void DeleteNodeChildren(wxXmlNode* pNode);
61  wxXmlNode *GetConfigNode(wxGISEnumConfigKey Key, const wxString &sPath);
62  wxXmlNode *CreateConfigNode(wxGISEnumConfigKey Key, const wxString &sPath);
63 
64  wxString GetLocalConfigDir(void) const;
65  wxString GetGlobalConfigDir(void) const;
66  wxString GetLocalConfigDirNonPortable(void) const;
67 
68  void Save(const wxGISEnumConfigKey Key = enumGISHKAny);
69 protected:
70  bool SplitPathToXml(const wxString & fullpath, wxString *psFileName, wxString *psPathInXml);
71  bool SplitPathToAttribute(const wxString & fullpath, wxString *psPathToAttribute, wxString *psAttributeName);
72  wxXmlNode* GetConfigRootNode(wxGISEnumConfigKey Key, const wxString &sFileName) const;
73 protected:
74  virtual wxObjectRefData *CreateRefData() const;
75  virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
76 };
77 
85 class wxGISConfigRefData : public wxObjectRefData
86 {
87  friend class wxGISConfig;
88  friend class wxGISAppConfig;
89 public:
91  virtual ~wxGISConfigRefData();
92  void Save(const wxGISEnumConfigKey Key = enumGISHKAny, const wxString& sXmlFileName = wxEmptyString);
94  bool operator == (const wxGISConfigRefData& data) const;
95 
96  //typedefs
97  typedef struct wxxmlconf
98  {
99  wxXmlDocument *pXmlDoc;
100  wxGISEnumConfigKey eKey;
101  wxString sXmlFileName;
102  wxString sXmlFilePath;
103  }WXXMLCONF;
104 
105 protected:
106  wxString m_sLocalConfigDirPath, m_sGlobalConfigDirPath, m_sAppExeDirPath;
107  wxString m_sLocalConfigDirPathNonPortable;
108  bool m_bPortable;
109  wxVector<WXXMLCONF> m_paConfigFiles;
110  wxGISConfigNodesMap m_pmConfigNodes;
111 protected:
112  wxCriticalSection m_oCritSect;
113 };
114 
123 class WXDLLIMPEXP_GIS_CORE wxGISAppConfig : public wxGISConfig
124 {
125  DECLARE_CLASS(wxGISAppConfig);
126 public:
127  wxGISAppConfig(void);
128  wxGISAppConfig(bool bPortable);
129 
130  wxString GetLocale(void);
131  wxString GetLocaleDir(void);
132  wxString GetSysDir(void);
133  wxString GetTempDir(void);
134  wxString GetLogDir(void);
135  bool GetDebugMode(void);
136  void SetLocale(const wxString &sLocale);
137  void SetLocaleDir(const wxString &sLocaleDir);
138  void SetSysDir(const wxString &sSysDir);
139  void SetLogDir(const wxString &sLogDir);
140  void SetDebugMode(bool bDebug);
141 };
142 
150 WXDLLIMPEXP_GIS_CORE wxGISAppConfig GetConfig(void);
151 
Definition: config.h:85
Definition: config.h:97
Definition: config.h:123
Definition: config.h:38