File indexing completed on 2024-09-07 04:35:38
0001 #ifndef CondFormats_HcalObjects_HcalItemColl_h
0002 #define CondFormats_HcalObjects_HcalItemColl_h
0003
0004 #include "boost/serialization/access.hpp"
0005 #include "boost/serialization/version.hpp"
0006 #include "boost/serialization/shared_ptr.hpp"
0007 #include "boost/serialization/vector.hpp"
0008
0009 #include <memory>
0010 #include <vector>
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 template <typename Item>
0021 class HcalItemColl {
0022 public:
0023 typedef Item value_type;
0024
0025
0026 inline void push_back(std::unique_ptr<Item> ptr) { data_.push_back(std::shared_ptr<Item>(ptr.release())); }
0027
0028
0029 inline void clear() { data_.clear(); }
0030 inline void reserve(const unsigned n) { data_.reserve(n); }
0031
0032
0033 inline std::size_t size() const { return data_.size(); }
0034 inline bool empty() const { return data_.empty(); }
0035
0036
0037 inline const Item* get(const unsigned index) const {
0038 if (index < data_.size())
0039 return data_[index].get();
0040 else
0041 return nullptr;
0042 }
0043
0044
0045 inline const Item& at(const unsigned index) const { return *data_.at(index); }
0046
0047
0048 bool operator==(const HcalItemColl& r) const {
0049 const std::size_t sz = data_.size();
0050 if (sz != r.data_.size())
0051 return false;
0052 for (std::size_t i = 0; i < sz; ++i)
0053 if (!(*data_[i] == *r.data_[i]))
0054 return false;
0055 return true;
0056 }
0057
0058 inline bool operator!=(const HcalItemColl& r) const { return !(*this == r); }
0059
0060 private:
0061 std::vector<std::shared_ptr<Item> > data_;
0062
0063 friend class boost::serialization::access;
0064
0065 template <class Archive>
0066 inline void serialize(Archive& ar, unsigned ) {
0067 ar & data_;
0068 }
0069 };
0070
0071
0072 namespace boost {
0073 namespace serialization {
0074 template <typename Item>
0075 struct version<HcalItemColl<Item> > {
0076 BOOST_STATIC_CONSTANT(int, value = 1);
0077 };
0078 }
0079 }
0080
0081 #endif