CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ThreadSafeIndexedRegistry.h
Go to the documentation of this file.
1 #ifndef FWCore_Utilities_ThreadSafeIndexedRegistry_h
2 #define FWCore_Utilities_ThreadSafeIndexedRegistry_h
3 
4 #include <vector>
5 #include "boost/thread.hpp"
6 
7 // ----------------------------------------------------------------------
8 
16 // ----------------------------------------------------------------------
17 
18 #pragma GCC visibility push(default)
19 namespace edm {
20  namespace detail {
21  struct Empty { };
22 
23  template <typename T, typename E=Empty>
25  public:
26  typedef T value_type;
27  typedef E extra_type;
28  typedef typename std::vector<value_type> collection_type;
30 
31  typedef typename collection_type::const_iterator const_iterator;
32 
34 
41 
44  bool insertMapped(value_type const& v);
45 
48  void insertCollection(collection_type const& c);
49 
51  bool empty() const;
52 
54  bool notEmpty() const;
55 
57  size_type size() const;
58 
61  const_iterator begin() const;
62  const_iterator end() const;
63 
65  void print(std::ostream& os) const;
66 
69  collection_type const& data() const;
70 
74  extra_type& extra();
75  extra_type const& extra() const;
76 
77  private:
80 
81  // The following two are not implemented.
83 
86 
89 
90  };
91 
92  template <typename T, typename E>
93  inline
94  std::ostream&
95  operator<< (std::ostream& os, ThreadSafeIndexedRegistry<T, E> const& reg) {
96  reg.print(os);
97  return os;
98  }
99 
100  template <typename T, typename E>
101  void
103  for (typename collection_type::const_iterator it = c.begin(), itEnd = c.end(); it != itEnd; ++it) {
104  insertMapped(*it);
105  }
106  }
107 
108  template <typename T, typename E>
109  inline
110  bool
112  return data_.empty();
113  }
114 
115  template <typename T, typename E>
116  inline
117  bool
119  return !empty();
120  }
121 
122  template <typename T, typename E>
123  inline
126  return data_.size();
127  }
128 
129  template <typename T, typename E>
130  inline
133  return data_.begin();
134  }
135 
136  template <typename T, typename E>
137  inline
140  return data_.end();
141  }
142 
143  template <typename T, typename E>
144  void
145  ThreadSafeIndexedRegistry<T, E>::print(std::ostream& os) const {
146  os << "Registry with " << size() << " entries\n";
147  for (const_iterator i = begin(), e = end(); i != e; ++i) {
148  os << i - begin() << " " << i << '\n';
149  }
150  }
151 
152  template <typename T, typename E>
153  inline
156  return data_;
157  }
158 
159  template <typename T, typename E>
160  inline
163  return extra_;
164  }
165 
166  template <typename T, typename E>
167  inline
170  return extra_;
171  }
172 
173  template <typename T, typename E>
174  inline
177  return data_;
178  }
179 
180  template <typename T, typename E>
182  data_()
183  { }
184 
185 
186  template <typename T, typename E>
188  { }
189 
190  } // namespace detail
191 } // namespace edm
192 #pragma GCC visibility pop
193 
194 #endif // FWCore_Utilities_ThreadSafeIndexedRegistry_h
int i
Definition: DBlmapReader.cc:9
size_type size() const
Return the number of contained value_type objects.
collection_type::const_iterator const_iterator
uint16_t size_type
static ThreadSafeIndexedRegistry * instance()
tuple result
Definition: query.py:137
bool insertMapped(value_type const &v)
bool notEmpty() const
Return true if there are any contained value_type objects.
#define end
Definition: vmac.h:38
ThreadSafeIndexedRegistry< T, E > & operator=(ThreadSafeIndexedRegistry< T, E > const &)
#define begin
Definition: vmac.h:31
collection_type & data()
Provide access to the contained collection.
void getMapped(size_type index, value_type &result) const
long double T
bool empty() const
Return true if there are no contained value_type objects.
tuple size
Write out results.
mathSSE::Vec4< T > v
void insertCollection(collection_type const &c)
void print(std::ostream &os) const
Print the contents of this registry to the given ostream.