Subversion Repository Public Repository

Divide-Framework

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

Diff Revisions 167 vs 168 for /trunk/Source Code/Core/Headers/ParamHandler.h

Diff revisions: vs.
  @@ -30,40 +30,46 @@
30 30 #include "Utility/Headers/Localization.h"
31 31 #include "Hardware/Platform/Headers/SharedMutex.h"
32 32 #include "Hardware/Platform/Headers/PlatformDefines.h"
33 + #include <boost/atomic.hpp>
33 34
34 35 DEFINE_SINGLETON (ParamHandler)
35 36 typedef Unordered_map<std::string, cdiggins::any> ParamMap;
36 37 typedef Unordered_map<std::string, const char* > ParamTypeMap;
37 - typedef cdiggins::anyimpl::bad_any_cast BadAnyCast;
38 +
38 39 public:
39 40
40 41 template <class T>
41 - T getParam(const std::string& name, const T& defaultValue = T()) {
42 +
43 + #ifndef _DEBUG
44 + inline
45 + #endif
46 +
47 + const T& getParam(const std::string& name, const T& defaultValue = T()) const {
42 48 ReadLock r_lock(_mutex);
43 - ParamMap::iterator it = _params.find(name);
49 + ParamMap::const_iterator it = _params.find(name);
50 + if(it != _params.end()) {
44 51 #ifdef _DEBUG
45 - if(it != _params.end()){
46 - try {
47 - return it->second.cast<T>();
48 - }catch(BadAnyCast){
49 - ERROR_FN(Locale::get("ERROR_PARAM_CAST"),name.c_str(),typeid(T).name());
50 - }
52 + try {
53 + return it->second.constant_cast<T>();
54 + }
55 + catch(cdiggins::anyimpl::bad_any_cast ) {
56 + ERROR_FN(Locale::get("ERROR_PARAM_CAST"),name.c_str(),typeid(T).name());
51 57 }
52 58 #else
53 - if(it != _params.end()){
54 - return it->second.cast<T>();
55 - }
59 + return it->second.constant_cast<T>();
56 60 #endif
61 + }
57 62 return defaultValue; //integrals will be 0, string will be empty, etc;
58 63 }
59 64
60 - void setParam(const std::string& name, const cdiggins::any& value){
65 + void setParam(const std::string& name, const cdiggins::any& value) {
61 66 WriteLock w_lock(_mutex);
62 67 std::pair<ParamMap::iterator, bool> result = _params.insert(std::make_pair(name,value));
63 - if(!result.second) (result.first)->second = value;
68 + if(!result.second)
69 + (result.first)->second = value;
64 70 }
65 71
66 - inline void delParam(const std::string& name){
72 + inline void delParam(const std::string& name) {
67 73 if(isParam(name)){
68 74 WriteLock w_lock(_mutex);
69 75 _params.erase(name);
  @@ -73,14 +79,22 @@
73 79 }
74 80 }
75 81
76 - inline void setDebugOutput(const bool logState) {WriteLock w_lock(_mutex); _logState = logState;}
82 + inline void setDebugOutput(bool logState) {
83 + _logState = logState;
84 + }
77 85
78 - inline U32 getSize() const {ReadLock r_lock(_mutex); return _params.size();}
86 + inline U32 getSize() const {
87 + ReadLock r_lock(_mutex);
88 + return _params.size();
89 + }
79 90
80 - inline bool isParam(const std::string& param) const {ReadLock r_lock(_mutex); return _params.find(param) != _params.end();}
91 + inline bool isParam(const std::string& param) const {
92 + ReadLock r_lock(_mutex);
93 + return _params.find(param) != _params.end();
94 + }
81 95
82 96 private:
83 - bool _logState;
97 + boost::atomic_bool _logState;
84 98 ParamMap _params;
85 99 mutable SharedLock _mutex;
86 100