1 #ifndef FWCore_Utilities_ThreadSafeRegistry_h
2 #define FWCore_Utilities_ThreadSafeRegistry_h
6 #include "boost/thread.hpp"
32 template <
typename KEY,
typename T,
typename E=empty>
88 void print(std::ostream& os)
const;
118 template <
typename KEY,
typename T,
typename E>
121 operator<< (std::ostream& os, ThreadSafeRegistry<KEY,T,E>
const& reg) {
130 template <
typename KEY,
typename T,
typename E>
131 ThreadSafeRegistry<KEY,T,E>* ThreadSafeRegistry<KEY,T,E>::instance_ = 0;
133 template <
typename KEY,
typename T,
typename E>
134 boost::mutex ThreadSafeRegistry<KEY,T,E>::registry_mutex;
138 template <
typename KEY,
typename T,
typename E>
139 ThreadSafeRegistry<KEY,T,E>*
141 if (instance_ == 0) {
142 boost::mutex::scoped_lock
lock(registry_mutex);
143 if (instance_ == 0) {
151 template <
typename KEY,
typename T,
typename E>
159 boost::mutex::scoped_lock
lock(registry_mutex);
161 found = (i != data_.end());
163 if (found) result = i->second;
167 template <
typename KEY,
typename T,
typename E>
175 boost::mutex::scoped_lock
lock(registry_mutex);
177 found = (i != data_.end());
179 return found ? &(i->second) : static_cast<value_type const*> (0);
182 template <
typename KEY,
typename T,
typename E>
185 bool newly_added =
false;
186 boost::mutex::scoped_lock
lock(registry_mutex);
189 if (data_.find(
id) == data_.end()) {
196 template <
typename KEY,
typename T,
typename E>
199 for (
typename collection_type::const_iterator it = c.begin(), itEnd = c.end(); it != itEnd; ++it) {
200 insertMapped(it->second);
204 template <
typename KEY,
typename T,
typename E>
207 for (
typename vector_type::const_iterator it = c.begin(), itEnd = c.end(); it != itEnd; ++it) {
212 template <
typename KEY,
typename T,
typename E>
216 return data_.empty();
219 template <
typename KEY,
typename T,
typename E>
226 template <
typename KEY,
typename T,
typename E>
233 template <
typename KEY,
typename T,
typename E>
237 return data_.begin();
240 template <
typename KEY,
typename T,
typename E>
247 template <
typename KEY,
typename T,
typename E>
250 os <<
"Registry with " <<
size() <<
" entries\n";
252 os <<
i->first <<
" " <<
i->second <<
'\n';
256 template <
typename KEY,
typename T,
typename E>
263 template <
typename KEY,
typename T,
typename E>
270 template <
typename KEY,
typename T,
typename E>
277 template <
typename KEY,
typename T,
typename E>
284 template <
typename KEY,
typename T,
typename E>
290 template <
typename KEY,
typename T,
typename E>
297 #endif // FWCore_Utilities_ThreadSafeRegistry_h
static boost::mutex mutex
bool empty() const
Return true if there are no contained value_type objects.
bool getMapped(key_type const &k, value_type &result) const
size_type size() const
Return the number of contained value_type objects.
bool insertMapped(value_type const &v)
void print(std::ostream &os) const
Print the contents of this registry to the given ostream.
std::map< key_type, value_type > collection_type
const_iterator begin() const
collection_type::const_iterator const_iterator
static boost::mutex registry_mutex
void insertCollection(collection_type const &c)
ThreadSafeRegistry< KEY, T, E > & operator=(ThreadSafeRegistry< KEY, T, E > const &)
static ThreadSafeRegistry * instance_
std::vector< value_type > vector_type
const_iterator end() const
static ThreadSafeRegistry * instance()
collection_type & data()
Provide access to the contained collection.
tuple size
Write out results.
collection_type::size_type size_type
bool notEmpty() const
Return true if there are any contained value_type objects.