File indexing completed on 2024-04-06 12:03:53
0001 #ifndef DataFormats_Common_RefHolder__h
0002 #define DataFormats_Common_RefHolder__h
0003 #include "DataFormats/Common/interface/CMS_CLASS_VERSION.h"
0004
0005 #include "DataFormats/Common/interface/RefHolderBase.h"
0006 #include "DataFormats/Provenance/interface/ProductID.h"
0007 #include "FWCore/Utilities/interface/OffsetToBase.h"
0008 #include <memory>
0009 #include <typeinfo>
0010 #include <string>
0011
0012 namespace edm {
0013 namespace reftobase {
0014
0015
0016
0017
0018 template <class REF>
0019 class RefHolder : public RefHolderBase {
0020 public:
0021 RefHolder();
0022 explicit RefHolder(REF const& ref);
0023 void swap(RefHolder& other);
0024 ~RefHolder() override;
0025 RefHolderBase* clone() const override;
0026
0027 ProductID id() const override;
0028 size_t key() const override;
0029 bool isEqualTo(RefHolderBase const& rhs) const override;
0030 REF const& getRef() const;
0031 void setRef(REF const& r);
0032 std::unique_ptr<RefVectorHolderBase> makeVectorHolder() const override;
0033 EDProductGetter const* productGetter() const override;
0034
0035
0036
0037 bool isAvailable() const override { return ref_.isAvailable(); }
0038
0039 bool isTransient() const override { return ref_.isTransient(); }
0040
0041
0042 CMS_CLASS_VERSION(10)
0043 private:
0044 void const* pointerToType(std::type_info const& iToType) const override;
0045 REF ref_;
0046 };
0047
0048
0049
0050
0051
0052 template <class REF>
0053 RefHolder<REF>::RefHolder() : RefHolderBase(), ref_() {}
0054
0055 template <class REF>
0056 RefHolder<REF>::RefHolder(REF const& ref) : RefHolderBase(), ref_(ref) {}
0057
0058 template <class REF>
0059 RefHolder<REF>::~RefHolder() {}
0060
0061 template <class REF>
0062 RefHolderBase* RefHolder<REF>::clone() const {
0063 return new RefHolder(ref_);
0064 }
0065
0066 template <class REF>
0067 ProductID RefHolder<REF>::id() const {
0068 return ref_.id();
0069 }
0070
0071 template <class REF>
0072 bool RefHolder<REF>::isEqualTo(RefHolderBase const& rhs) const {
0073 RefHolder const* h(dynamic_cast<RefHolder const*>(&rhs));
0074 return h && (getRef() == h->getRef());
0075 }
0076
0077 template <class REF>
0078 inline REF const& RefHolder<REF>::getRef() const {
0079 return ref_;
0080 }
0081
0082 template <class REF>
0083 EDProductGetter const* RefHolder<REF>::productGetter() const {
0084 return ref_.productGetter();
0085 }
0086
0087 template <class REF>
0088 inline void RefHolder<REF>::swap(RefHolder& other) {
0089 std::swap(ref_, other.ref_);
0090 }
0091
0092 template <class REF>
0093 inline void RefHolder<REF>::setRef(REF const& r) {
0094 ref_ = r;
0095 }
0096
0097 template <class REF>
0098 void const* RefHolder<REF>::pointerToType(std::type_info const& iToType) const {
0099 typedef typename REF::value_type contained_type;
0100 if (iToType == typeid(contained_type)) {
0101 return ref_.get();
0102 }
0103 return pointerToBase(iToType, ref_.get());
0104 }
0105 }
0106 }
0107
0108 #endif