CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ThreadSafeRegistry.h
Go to the documentation of this file.
1 #ifndef FWCore_Utilities_ThreadSafeRegistry_h
2 #define FWCore_Utilities_ThreadSafeRegistry_h
3 
4 #include <map>
5 #include <vector>
6 #include "boost/thread.hpp"
7 
8 // ----------------------------------------------------------------------
9 
26 // ----------------------------------------------------------------------
27 
28 #pragma GCC visibility push(default)
29 namespace edm {
30  namespace detail {
31  struct empty { };
32 
33  template <typename KEY, typename T, typename E=empty>
35  public:
36  typedef KEY key_type;
37  typedef T value_type;
38  typedef E extra_type;
39  typedef typename std::map<key_type, value_type> collection_type;
41 
42  typedef typename collection_type::const_iterator const_iterator;
43 
44  typedef typename std::vector<value_type> vector_type;
45 
46  static ThreadSafeRegistry* instance();
47 
53  bool getMapped(key_type const& k, value_type& result) const;
54 
58  value_type const* getMapped(key_type const& k) const;
59 
67  bool insertMapped(value_type const& v);
68 
71  void insertCollection(collection_type const& c);
72  void insertCollection(vector_type const& c);
73 
75  bool empty() const;
76 
78  bool notEmpty() const;
79 
81  size_type size() const;
82 
85  const_iterator begin() const;
86  const_iterator end() const;
87 
89  void print(std::ostream& os) const;
90 
93  collection_type const& data() const;
94 
99  extra_type const& extra() const;
100 
101  private:
104 
105  // The following two are not implemented.
107 
110 
113  };
114 
115  template <typename KEY, typename T, typename E>
116  inline
117  std::ostream&
118  operator<< (std::ostream& os, ThreadSafeRegistry<KEY,T,E> const& reg) {
119  reg.print(os);
120  return os;
121  }
122 
123  template <typename KEY, typename T, typename E>
124  void
126  for (typename collection_type::const_iterator it = c.begin(), itEnd = c.end(); it != itEnd; ++it) {
127  insertMapped(it->second);
128  }
129  }
130 
131  template <typename KEY, typename T, typename E>
132  void
134  for (typename vector_type::const_iterator it = c.begin(), itEnd = c.end(); it != itEnd; ++it) {
135  insertMapped(*it);
136  }
137  }
138 
139  template <typename KEY, typename T, typename E>
140  inline
141  bool
143  return data_.empty();
144  }
145 
146  template <typename KEY, typename T, typename E>
147  inline
148  bool
150  return !empty();
151  }
152 
153  template <typename KEY, typename T, typename E>
154  inline
157  return data_.size();
158  }
159 
160  template <typename KEY, typename T, typename E>
161  inline
164  return data_.begin();
165  }
166 
167  template <typename KEY, typename T, typename E>
168  inline
171  return data_.end();
172  }
173 
174  template <typename KEY, typename T, typename E>
175  void
176  ThreadSafeRegistry<KEY,T,E>::print(std::ostream& os) const {
177  os << "Registry with " << size() << " entries\n";
178  for (const_iterator i=begin(), e=end(); i!=e; ++i) {
179  os << i->first << " " << i->second << '\n';
180  }
181  }
182 
183  template <typename KEY, typename T, typename E>
184  inline
187  return data_;
188  }
189 
190  template <typename KEY, typename T, typename E>
191  inline
194  return extra_;
195  }
196 
197  template <typename KEY, typename T, typename E>
198  inline
201  return extra_;
202  }
203 
204  template <typename KEY, typename T, typename E>
205  inline
208  return data_;
209  }
210 
211  template <typename KEY, typename T, typename E>
213  data_()
214  { }
215 
216 
217  template <typename KEY, typename T, typename E>
219  { }
220 
221  } // namespace detail
222 } // namespace edm
223 #pragma GCC visibility pop
224 #endif // FWCore_Utilities_ThreadSafeRegistry_h
int i
Definition: DBlmapReader.cc:9
static ThreadSafeRegistry * instance()
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)
uint16_t size_type
void print(std::ostream &os) const
Print the contents of this registry to the given ostream.
extra_type const & extra() const
std::map< key_type, value_type > collection_type
collection_type::const_iterator const_iterator
tuple result
Definition: query.py:137
#define end
Definition: vmac.h:37
void insertCollection(collection_type const &c)
int k[5][pyjets_maxn]
ThreadSafeRegistry< KEY, T, E > & operator=(ThreadSafeRegistry< KEY, T, E > const &)
collection_type & dataForUpdate()
Provide access to the contained collection.
#define begin
Definition: vmac.h:30
std::vector< value_type > vector_type
long double T
tuple size
Write out results.
collection_type::size_type size_type
bool notEmpty() const
Return true if there are any contained value_type objects.
collection_type const & data() const