File: SettingsManager.h

package info (click to toggle)
mygui 3.2.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 36,224 kB
  • sloc: cpp: 118,031; ansic: 30,202; xml: 15,544; cs: 12,602; tcl: 776; python: 417; makefile: 34
file content (106 lines) | stat: -rw-r--r-- 2,711 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*!
	@file
	@author		Albert Semenov
	@date		07/2012
*/

#ifndef _f620c4fc_5a1d_4280_86ca_ac59deeae6e0_
#define _f620c4fc_5a1d_4280_86ca_ac59deeae6e0_

#include <MyGUI.h>
#include "pugixml.hpp"
#include "StringUtility.h"
#include "sigslot.h"

namespace tools
{

	class MYGUI_EXPORT_DLL SettingsManager :
		public MyGUI::Singleton<SettingsManager>
	{
	public:
		SettingsManager();
		virtual ~SettingsManager();

		bool loadSettingsFile(const std::string& _fileName);
		void saveSettingsFile(const std::string& _fileName);

		bool loadUserSettingsFile(const std::string& _fileName);
		void saveUserSettingsFile();

		bool getExistValue(const std::string& _path);

		template <typename Type>
		bool tryGetValue(const std::string& _path, Type& _result)
		{
			_result = Type();
			if (getExistValue(_path))
			{
				std::string value = getValue(_path);
				return MyGUI::utility::parseComplex<Type>(value, _result);
			}
			return false;
		}

		std::string getValue(const std::string& _path);
		void setValue(const std::string& _path, const std::string& _value);

		template <typename Type>
		Type getValue(const std::string& _path)
		{
			return MyGUI::utility::parseValue<Type>(getValue(_path));
		}

		template <typename Type>
		void setValue(const std::string& _path, const Type& value)
		{
			setValue(_path, MyGUI::utility::toString(value));
		}

		typedef std::vector<std::string> VectorString;
		VectorString getValueList(const std::string& _path);

		template <typename Type>
		std::vector<Type> getValueList(const std::string& _path)
		{
			VectorString resultString = getValueList(_path);
			std::vector<Type> result;
			result.reserve(resultString.size());

			for (VectorString::const_iterator item = resultString.begin(); item != resultString.end(); item ++)
				result.push_back(MyGUI::utility::parseValue<Type>(*item));

			return result;
		}

		void setValueList(const std::string& _path, const VectorString& _values);

		template <typename Type>
		void setValueList(const std::string& _path, const std::vector<Type>& _values)
		{
			VectorString values;
			values.reserve(_values.size());

			for (typename std::vector<Type>::const_iterator item = _values.begin(); item != _values.end(); item ++)
				values.push_back(MyGUI::utility::toString(*item));

			setValueList(_path, values);
		}

		pugi::xpath_node_set getValueNodeList(const std::string& _path);

		sigslot::signal1<const std::string&> eventSettingsChanged;

	private:
		void mergeNodes(pugi::xml_node _node1, pugi::xml_node _node2);
		void mergeAttributes(pugi::xml_node _node1, pugi::xml_node _node2);

	private:
		pugi::xml_document* mDocument;
		pugi::xml_document* mUserDocument;
		std::string mUserSettingsFileName;
	};

}

#endif