CMS 3D CMS Logo

HcalItemColl.h
Go to the documentation of this file.
1 #ifndef CondFormats_HcalObjects_HcalItemColl_h
2 #define CondFormats_HcalObjects_HcalItemColl_h
3 
4 #include "boost/serialization/access.hpp"
5 #include "boost/serialization/version.hpp"
6 #include "boost/serialization/shared_ptr.hpp"
7 #include "boost/serialization/vector.hpp"
8 
9 #include <memory>
10 #include <vector>
11 
12 //
13 // This collection manages only pointers and references.
14 // In particular, it can be used for storing objects in
15 // an inheritance hierarchy by their base pointers.
16 // The pointee objects are owned by this collection.
17 // If copies of this collection are made, all copies
18 // will share the ownership of the same set of objects.
19 //
20 template <typename Item>
21 class HcalItemColl {
22 public:
23  typedef Item value_type;
24 
25  // The following method adds a new item to the collection
26  inline void push_back(std::unique_ptr<Item> ptr) { data_.push_back(std::shared_ptr<Item>(ptr.release())); }
27 
28  // Other modifiers
29  inline void clear() { data_.clear(); }
30  inline void reserve(const unsigned n) { data_.reserve(n); }
31 
32  // Some inspectors
33  inline std::size_t size() const { return data_.size(); }
34  inline bool empty() const { return data_.empty(); }
35 
36  // The following function returns nullptr if the index is out of range
37  inline const Item* get(const unsigned index) const {
38  if (index < data_.size())
39  return data_[index].get();
40  else
41  return nullptr;
42  }
43 
44  // The following function throws an exception if the index is out of range
45  inline const Item& at(const unsigned index) const { return *data_.at(index); }
46 
47  // Deep comparison for equality is useful for testing serialization
48  bool operator==(const HcalItemColl& r) const {
49  const std::size_t sz = data_.size();
50  if (sz != r.data_.size())
51  return false;
52  for (std::size_t i = 0; i < sz; ++i)
53  if (!(*data_[i] == *r.data_[i]))
54  return false;
55  return true;
56  }
57 
58  inline bool operator!=(const HcalItemColl& r) const { return !(*this == r); }
59 
60 private:
61  std::vector<std::shared_ptr<Item> > data_;
62 
63  friend class boost::serialization::access;
64 
65  template <class Archive>
66  inline void serialize(Archive& ar, unsigned /* version */) {
67  ar& data_;
68  }
69 };
70 
71 // boost serialization version number for this template
72 namespace boost {
73  namespace serialization {
74  template <typename Item>
75  struct version<HcalItemColl<Item> > {
76  BOOST_STATIC_CONSTANT(int, value = 1);
77  };
78  } // namespace serialization
79 } // namespace boost
80 
81 #endif // CondFormats_HcalObjects_HcalItemColl_h
mps_fire.i
i
Definition: mps_fire.py:355
HcalItemColl::get
const Item * get(const unsigned index) const
Definition: HcalItemColl.h:37
HcalItemColl
Definition: HcalItemColl.h:21
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
HcalItemColl::clear
void clear()
Definition: HcalItemColl.h:29
HcalItemColl::data_
std::vector< std::shared_ptr< Item > > data_
Definition: HcalItemColl.h:61
boost
Definition: CLHEP.h:16
HcalItemColl::operator!=
bool operator!=(const HcalItemColl &r) const
Definition: HcalItemColl.h:58
HcalItemColl::value_type
Item value_type
Definition: HcalItemColl.h:23
HcalItemColl::size
std::size_t size() const
Definition: HcalItemColl.h:33
HcalItemColl::reserve
void reserve(const unsigned n)
Definition: HcalItemColl.h:30
value
Definition: value.py:1
HcalItemColl::push_back
void push_back(std::unique_ptr< Item > ptr)
Definition: HcalItemColl.h:26
HcalItemColl::at
const Item & at(const unsigned index) const
Definition: HcalItemColl.h:45
alignCSCRings.r
r
Definition: alignCSCRings.py:93
HcalItemColl::serialize
void serialize(Archive &ar, unsigned)
Definition: HcalItemColl.h:66
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
HcalItemColl::operator==
bool operator==(const HcalItemColl &r) const
Definition: HcalItemColl.h:48
HcalItemColl::empty
bool empty() const
Definition: HcalItemColl.h:34
BeamSplash_cfg.version
version
Definition: BeamSplash_cfg.py:45