Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 336 vs 337 for /trunk/Source Code/Core/Headers/ParamHandler.h

Diff revisions: vs.
  @@ -20,8 +20,8 @@
20 20
21 21 */
22 22
23 - #ifndef _PARAM_HANDLER_H_
24 - #define _PARAM_HANDLER_H_
23 + #ifndef _CORE_PARAM_HANDLER_H_
24 + #define _CORE_PARAM_HANDLER_H_
25 25
26 26 #include "Console.h"
27 27 #include "cdigginsAny.h"
  @@ -41,186 +41,66 @@
41 41 typedef hashMapImpl<stringImpl, bool > ParamBoolMap;
42 42
43 43 public:
44 - inline void setDebugOutput(bool logState) {
45 - _logState = logState;
46 - }
47 -
48 - template<typename T>
49 - inline T getParam(const stringImpl& name, T defaultValue = T()) const {
50 - ReadLock r_lock(_mutex);
51 - ParamMap::const_iterator it = _params.find(name);
52 - if(it != _params.end()) {
53 - bool success = false;
54 - const T& ret = it->second.constant_cast<T>(success);
55 - # ifdef _DEBUG
56 - if (!success) {
57 - ERROR_FN(Locale::get("ERROR_PARAM_CAST"),name.c_str());
58 - DIVIDE_ASSERT(success,
59 - "ParamHandler error: Can't cast requested param to specified type!");
60 - }
61 - # endif
62 -
63 - return ret;
64 - }
65 -
66 - ERROR_FN(Locale::get("ERROR_PARAM_GET"), name.c_str());
67 - return defaultValue; //integers will be 0, string will be empty, etc;
68 - }
44 + void setDebugOutput(bool logState);
69 45
70 46 template<typename T>
71 - void setParam(const stringImpl& name, const T& value) {
72 - WriteLock w_lock(_mutex);
73 - ParamMap::iterator it = _params.find(name);
74 - if (it == _params.end()) {
75 - DIVIDE_ASSERT(emplace(_params, name, cdiggins::any(value)).second,
76 - "ParamHandler error: can't add specified value to map!");
77 - } else {
78 - it->second = cdiggins::any(value);
79 - }
80 - }
81 -
82 - template<typename T>
83 - inline void delParam(const stringImpl& name) {
84 - if (isParam(name)) {
85 - WriteLock w_lock(_mutex);
86 - _params.erase(name);
87 - if (_logState) {
88 - PRINT_FN(Locale::get("PARAM_REMOVE"), name.c_str());
89 - }
90 - } else {
91 - ERROR_FN(Locale::get("ERROR_PARAM_REMOVE"),name.c_str());
92 - }
93 - }
94 -
95 - template<typename T>
96 - inline bool isParam(const stringImpl& param) const {
97 - ReadLock r_lock(_mutex);
98 - return _params.find(param) != _params.end();
99 - }
100 -
101 - template<>
102 - inline stringImpl getParam(const stringImpl& name, stringImpl defaultValue) const {
103 - ReadLock r_lock(_mutex);
104 - ParamStringMap::const_iterator it = _paramsStr.find(name);
105 - if (it != _paramsStr.end()) {
106 - return it->second;
107 - }
108 -
109 - ERROR_FN(Locale::get("ERROR_PARAM_GET"), name.c_str());
110 - return defaultValue;
111 - }
112 -
113 - template<>
114 - void setParam(const stringImpl& name, const stringImpl& value) {
115 - WriteLock w_lock(_mutex);
116 - ParamStringMap::iterator it = _paramsStr.find(name);
117 - if (it == _paramsStr.end()) {
118 - DIVIDE_ASSERT(emplace(_paramsStr, name, value).second,
119 - "ParamHandler error: can't add specified value to map!");
120 - } else {
121 - it->second = value;
122 - }
123 - }
47 + T getParam(const stringImpl& name, T defaultValue = T()) const;
48 +
49 + template<typename T>
50 + void setParam(const stringImpl& name, const T& value);
51 +
52 + template<typename T>
53 + void delParam(const stringImpl& name);
54 +
55 + template<typename T>
56 + bool isParam(const stringImpl& param) const;
57 +
58 + template<>
59 + stringImpl getParam(const stringImpl& name, stringImpl defaultValue) const;
60 +
61 + template<>
62 + void setParam(const stringImpl& name, const stringImpl& value);
124 63
125 64 #if defined(STRING_IMP) && STRING_IMP != 1
126 - template<>
127 - inline std::string getParam(const stringImpl& name, std::string defaultValue) const {
128 - return stringAlg::fromBase(getParam<stringImpl>(name, stringAlg::toBase(defaultValue)));
129 - }
130 -
131 - template<>
132 - inline void setParam(const stringImpl& name, const std::string& value) {
133 - setParam(name, stringImpl(value.c_str()));
134 - }
135 -
136 - template<>
137 - inline void delParam<std::string>(const stringImpl& name) {
138 - delParam<stringImpl>(name);
139 - }
65 + template<>
66 + std::string getParam(const stringImpl& name, std::string defaultValue) const;
67 +
68 + template<>
69 + void setParam(const stringImpl& name, const std::string& value);
70 +
71 + template<>
72 + void delParam<std::string>(const stringImpl& name);
140 73 #endif
141 74
142 - template<>
143 - inline void delParam<stringImpl>(const stringImpl& name) {
144 - if (isParam<stringImpl>(name)) {
145 - WriteLock w_lock(_mutex);
146 - _paramsStr.erase(name);
147 - if (_logState) {
148 - PRINT_FN(Locale::get("PARAM_REMOVE"), name.c_str());
149 - }
150 - } else {
151 - ERROR_FN(Locale::get("ERROR_PARAM_REMOVE"), name.c_str());
152 - }
153 - }
154 -
155 - template<>
156 - inline bool isParam<stringImpl>(const stringImpl& param) const {
157 - ReadLock r_lock(_mutex);
158 - return _paramsStr.find(param) != _paramsStr.end();
159 - }
160 -
161 - template<>
162 - inline bool getParam(const stringImpl& name, bool defaultValue) const {
163 - ReadLock r_lock(_mutex);
164 - ParamBoolMap::const_iterator it = _paramBool.find(name);
165 - if (it != _paramBool.end()) {
166 - return it->second;
167 - }
168 -
169 - ERROR_FN(Locale::get("ERROR_PARAM_GET"), name.c_str());
170 - return defaultValue;
171 - }
172 -
173 - template<>
174 - void setParam(const stringImpl& name, const bool& value) {
175 - WriteLock w_lock(_mutex);
176 - ParamBoolMap::iterator it = _paramBool.find(name);
177 - if (it == _paramBool.end()) {
178 - DIVIDE_ASSERT(emplace(_paramBool, name, value).second,
179 - "ParamHandler error: can't add specified value to map!");
180 - } else {
181 - it->second = value;
182 - }
183 - }
184 -
185 - template<>
186 - inline void delParam<bool>(const stringImpl& name) {
187 - if (isParam<stringImpl>(name)) {
188 - WriteLock w_lock(_mutex);
189 - _paramBool.erase(name);
190 - if (_logState) {
191 - PRINT_FN(Locale::get("PARAM_REMOVE"), name.c_str());
192 - }
193 - } else {
194 - ERROR_FN(Locale::get("ERROR_PARAM_REMOVE"), name.c_str());
195 - }
196 - }
197 -
198 - template<>
199 - inline bool isParam<bool>(const stringImpl& param) const {
200 - ReadLock r_lock(_mutex);
201 - return _paramBool.find(param) != _paramBool.end();
202 - }
203 -
204 - protected:
205 - ParamHandler()
206 - {
207 - }
208 -
209 - ~ParamHandler()
210 - {
211 - _params.clear();
212 - _paramBool.clear();
213 - _paramsStr.clear();
214 - }
75 + template<>
76 + void delParam<stringImpl>(const stringImpl& name);
77 +
78 + template<>
79 + bool isParam<stringImpl>(const stringImpl& param) const;
80 +
81 + template<>
82 + bool getParam(const stringImpl& name, bool defaultValue) const;
83 +
84 + template<>
85 + void setParam(const stringImpl& name, const bool& value);
86 +
87 + template<>
88 + void delParam<bool>(const stringImpl& name);
89 +
90 + template<>
91 + bool isParam<bool>(const stringImpl& param) const;
92 +
215 93 private:
216 - ParamMap _params;
217 - ParamBoolMap _paramBool;
218 - ParamStringMap _paramsStr;
219 - mutable SharedLock _mutex;
220 - std::atomic_bool _logState;
94 + ParamMap _params;
95 + ParamBoolMap _paramBool;
96 + ParamStringMap _paramsStr;
97 + mutable SharedLock _mutex;
98 + std::atomic_bool _logState;
221 99
222 100 END_SINGLETON
223 101
224 102 }; //namespace Divide
225 103
226 - #endif
104 + #endif //_CORE_PARAM_HANDLER_H_
105 +
106 + #include "ParamHandler.inl"