File indexing completed on 2024-04-06 12:03:52
0001
0002 #ifndef DataFormats_Common_Holder_h
0003 #define DataFormats_Common_Holder_h
0004 #include "DataFormats/Common/interface/CMS_CLASS_VERSION.h"
0005 #include "DataFormats/Common/interface/BaseHolder.h"
0006 #include "DataFormats/Common/interface/RefHolder.h"
0007 #include <memory>
0008
0009 namespace edm {
0010 namespace reftobase {
0011
0012
0013
0014
0015 template <class T, class REF>
0016 class Holder : public BaseHolder<T> {
0017 public:
0018 Holder();
0019 Holder(Holder const& other);
0020 explicit Holder(REF const& iRef);
0021 Holder& operator=(Holder const& rhs);
0022 void swap(Holder& other);
0023 ~Holder() override;
0024 BaseHolder<T>* clone() const override;
0025
0026 T const* getPtr() const override;
0027 ProductID id() const override;
0028 size_t key() const override;
0029 bool isEqualTo(BaseHolder<T> const& rhs) const override;
0030 REF const& getRef() const;
0031
0032 std::unique_ptr<RefHolderBase> holder() const override {
0033 return std::unique_ptr<RefHolderBase>(new RefHolder<REF>(ref_));
0034 }
0035 std::unique_ptr<BaseVectorHolder<T> > makeVectorHolder() const override;
0036 EDProductGetter const* productGetter() const override;
0037
0038
0039
0040 bool isAvailable() const override { return ref_.isAvailable(); }
0041
0042 bool isTransient() const override { return ref_.isTransient(); }
0043
0044
0045 CMS_CLASS_VERSION(10)
0046
0047 private:
0048 REF ref_;
0049 };
0050
0051
0052
0053
0054
0055 template <class T, class REF>
0056 inline Holder<T, REF>::Holder() : BaseHolder<T>(), ref_() {}
0057
0058 template <class T, class REF>
0059 inline Holder<T, REF>::Holder(Holder const& other) : BaseHolder<T>(other), ref_(other.ref_) {}
0060
0061 template <class T, class REF>
0062 inline Holder<T, REF>::Holder(REF const& r) : BaseHolder<T>(), ref_(r) {}
0063
0064 template <class T, class REF>
0065 inline Holder<T, REF>& Holder<T, REF>::operator=(Holder const& rhs) {
0066 Holder temp(rhs);
0067 swap(temp);
0068 return *this;
0069 }
0070
0071 template <class T, class REF>
0072 inline void Holder<T, REF>::swap(Holder& other) {
0073 std::swap(ref_, other.ref_);
0074 }
0075
0076 template <class T, class REF>
0077 inline Holder<T, REF>::~Holder() {}
0078
0079 template <class T, class REF>
0080 inline BaseHolder<T>* Holder<T, REF>::clone() const {
0081 return new Holder(*this);
0082 }
0083
0084 template <class T, class REF>
0085 inline T const* Holder<T, REF>::getPtr() const {
0086 return ref_.operator->();
0087 }
0088
0089 template <class T, class REF>
0090 inline ProductID Holder<T, REF>::id() const {
0091 return ref_.id();
0092 }
0093
0094 template <class T, class REF>
0095 inline bool Holder<T, REF>::isEqualTo(BaseHolder<T> const& rhs) const {
0096 Holder const* h = dynamic_cast<Holder const*>(&rhs);
0097 return h && (getRef() == h->getRef());
0098
0099
0100 }
0101
0102 template <class T, class REF>
0103 inline REF const& Holder<T, REF>::getRef() const {
0104 return ref_;
0105 }
0106
0107 template <class T, class REF>
0108 inline EDProductGetter const* Holder<T, REF>::productGetter() const {
0109 return ref_.productGetter();
0110 }
0111
0112 }
0113 }
0114
0115 #include "DataFormats/Common/interface/HolderToVectorTrait.h"
0116 #include "DataFormats/Common/interface/Ref.h"
0117
0118 namespace edm {
0119 namespace reftobase {
0120
0121 template <typename T, typename REF>
0122 std::unique_ptr<BaseVectorHolder<T> > Holder<T, REF>::makeVectorHolder() const {
0123 typedef typename HolderToVectorTrait<T, REF>::type helper;
0124 return helper::makeVectorHolder();
0125 }
0126 }
0127 }
0128
0129 #include "DataFormats/Common/interface/RefKeyTrait.h"
0130
0131 namespace edm {
0132 namespace reftobase {
0133
0134 template <class T, class REF>
0135 inline size_t Holder<T, REF>::key() const {
0136 typedef typename RefKeyTrait<REF>::type helper;
0137 return helper::key(ref_);
0138 }
0139
0140 }
0141 }
0142 #endif