File indexing completed on 2024-04-06 12:03:55
0001 #ifndef DataFormats_Common_WrapperView_icc
0002 #define DataFormats_Common_WrapperView_icc
0003
0004
0005
0006
0007
0008
0009
0010 #include "DataFormats/Common/interface/fwd_fillPtrVector.h"
0011 #include "DataFormats/Common/interface/fwd_setPtr.h"
0012 #include "DataFormats/Common/interface/traits.h"
0013 #include "FWCore/Utilities/interface/EDMException.h"
0014 #include <type_traits>
0015
0016 namespace edm {
0017
0018 template <typename T>
0019 struct DoFillView {
0020 void operator()(T const& obj,
0021 ProductID const& id,
0022 std::vector<void const*>& pointers,
0023 FillViewHelperVector& helpers) const;
0024 };
0025
0026 template <typename T>
0027 struct DoNotFillView {
0028 void operator()(T const&, ProductID const&, std::vector<void const*>&, FillViewHelperVector&) const {
0029 Exception::throwThis(
0030 errors::ProductDoesNotSupportViews, "The product type ", typeid(T).name(), "\ndoes not support Views\n");
0031 }
0032 };
0033
0034 template <typename T>
0035 inline void Wrapper<T>::do_fillView(ProductID const& id,
0036 std::vector<void const*>& pointers,
0037 FillViewHelperVector& helpers) const {
0038 typename std::conditional<has_fillView<T>::value, DoFillView<T>, DoNotFillView<T> >::type maybe_filler;
0039 maybe_filler(obj, id, pointers, helpers);
0040 }
0041
0042 template <typename T>
0043 struct DoSetPtr {
0044 void operator()(T const& obj, std::type_info const& iToType, unsigned long iIndex, void const*& oPtr) const;
0045 void operator()(T const& obj,
0046 std::type_info const& iToType,
0047 std::vector<unsigned long> const& iIndex,
0048 std::vector<void const*>& oPtr) const;
0049 };
0050
0051 template <typename T>
0052 struct DoNotSetPtr {
0053 void operator()(T const& , std::type_info const& iToType, unsigned long iIndex, void const*& oPtr) const {
0054 Exception::throwThis(
0055 errors::ProductDoesNotSupportPtr, "The product type ", typeid(T).name(), "\ndoes not support edm::Ptr\n");
0056 }
0057 void operator()(T const& obj,
0058 std::type_info const& iToType,
0059 std::vector<unsigned long> const& iIndexes,
0060 std::vector<void const*>& oPtrs) const {
0061 Exception::throwThis(errors::ProductDoesNotSupportPtr,
0062 "The product type ",
0063 typeid(T).name(),
0064 "\ndoes not support edm::PtrVector\n");
0065 }
0066 };
0067
0068 template <typename T>
0069 inline void Wrapper<T>::do_setPtr(std::type_info const& iToType, unsigned long iIndex, void const*& oPtr) const {
0070 typename std::conditional<has_setPtr<T>::value, DoSetPtr<T>, DoNotSetPtr<T> >::type maybe_filler;
0071 maybe_filler(this->obj, iToType, iIndex, oPtr);
0072 }
0073
0074 template <typename T>
0075 void Wrapper<T>::do_fillPtrVector(std::type_info const& iToType,
0076 std::vector<unsigned long> const& iIndices,
0077 std::vector<void const*>& oPtr) const {
0078 typename std::conditional<has_setPtr<T>::value, DoSetPtr<T>, DoNotSetPtr<T> >::type maybe_filler;
0079 maybe_filler(this->obj, iToType, iIndices, oPtr);
0080 }
0081 }
0082
0083 namespace edm {
0084
0085 template <typename T>
0086 class PtrVector;
0087
0088 namespace helpers {
0089 template <typename T>
0090 struct ViewFiller {
0091 static void fill(T const& obj,
0092 ProductID const& id,
0093 std::vector<void const*>& pointers,
0094 FillViewHelperVector& helpers) {
0095 fillView(obj, id, pointers, helpers);
0096 assert(pointers.size() == helpers.size());
0097 }
0098 };
0099
0100 template <typename T>
0101 struct PtrSetter {
0102 static void set(T const& obj, std::type_info const& iToType, unsigned long iIndex, void const*& oPtr) {
0103
0104
0105 setPtr(obj, iToType, iIndex, oPtr);
0106 }
0107
0108 static void fill(T const& obj,
0109 std::type_info const& iToType,
0110 std::vector<unsigned long> const& iIndex,
0111 std::vector<void const*>& oPtr) {
0112
0113
0114 fillPtrVector(obj, iToType, iIndex, oPtr);
0115 }
0116 };
0117 }
0118
0119 template <typename T>
0120 void DoFillView<T>::operator()(T const& obj,
0121 ProductID const& id,
0122 std::vector<void const*>& pointers,
0123 FillViewHelperVector& helpers) const {
0124 helpers::ViewFiller<T>::fill(obj, id, pointers, helpers);
0125 }
0126
0127 template <typename T>
0128 void DoSetPtr<T>::operator()(T const& obj,
0129 std::type_info const& iToType,
0130 unsigned long iIndex,
0131 void const*& oPtr) const {
0132 helpers::PtrSetter<T>::set(obj, iToType, iIndex, oPtr);
0133 }
0134
0135 template <typename T>
0136 void DoSetPtr<T>::operator()(T const& obj,
0137 std::type_info const& iToType,
0138 std::vector<unsigned long> const& iIndices,
0139 std::vector<void const*>& oPtr) const {
0140 helpers::PtrSetter<T>::fill(obj, iToType, iIndices, oPtr);
0141 }
0142
0143 }
0144
0145 #include "DataFormats/Common/interface/FillView.h"
0146 #include "DataFormats/Common/interface/setPtr.h"
0147 #include "DataFormats/Common/interface/fillPtrVector.h"
0148
0149 #endif