identt
SharedStringMap.hpp
Go to the documentation of this file.
1 
33 #ifndef _IDENTT_UTILS_SHARED_STRING_MAP_HPP_
34 #define _IDENTT_UTILS_SHARED_STRING_MAP_HPP_
35 
36 #include <utils/SharedObject.hpp>
37 #include <string>
38 #include <unordered_map>
39 
40 namespace identt {
41 namespace utils {
42 template<class T>
43 class SharedStringMap : public SharedObject<std::unordered_map<std::string,T> > {
44 public:
45  using StringMapT = std::unordered_map<std::string,T>;
46  using LockT = SharedObject<StringMapT>::LockT;
47  using WriteLockT = SharedObject<StringMapT>::WriteLockT;
48  using ReadLockT = SharedObject<StringMapT>::ReadLockT;
49 
54  SharedStringMap(const SharedStringMap&) = delete;
55  SharedStringMap& operator=(const SharedStringMap&) = delete;
56 
62 
66  virtual ~SharedStringMap () {}
67 
80  void Add(std::string key, T value)
81  {
82  WriteLockT writelock(mutex_);
83  t_[key]=value;
84  }
85 
98  void Add(std::string& key, T value)
99  {
100  WriteLockT writelock(mutex_);
101  t_[key]=value;
102  }
103 
104 
114  T Get(std::string key)
115  {
116  ReadLockT readlock(mutex_);
117  StringMapT::const_iterator it = t_.find(key);
118  return (it!=t_.end()) ? it->second : T() ;
119  }
120 
130  T Get(std::string& key)
131  {
132  ReadLockT readlock(mutex_);
133  StringMapT::const_iterator it = t_.find(key);
134  return (it!=t_.end()) ? it->second : T() ;
135  }
136 
137 };
138 } // namespace utils
139 } // namespace identt
140 #endif /* _IDENTT_UTILS_SHARED_STRING_MAP_HPP_ */
virtual ~SharedStringMap()
destructor
Definition: SharedStringMap.hpp:66
void Add(std::string &key, T value)
Add : add one value by address.
Definition: SharedStringMap.hpp:98
T Get(std::string key)
Get : add one value.
Definition: SharedStringMap.hpp:114
Definition: SharedObject.hpp:43
SharedStringMap()
Constructor : default.
Definition: SharedStringMap.hpp:61
Definition: CryptoBase.hpp:49
T Get(std::string &key)
Get : add one value by address.
Definition: SharedStringMap.hpp:130
void Add(std::string key, T value)
Add : add one value.
Definition: SharedStringMap.hpp:80
Definition: SharedStringMap.hpp:43