DoFillView

DoNotFillView

DoNotSetPtr

DoSetPtr

PtrSetter

ViewFiller

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
#ifndef DataFormats_Common_WrapperView_icc
#define DataFormats_Common_WrapperView_icc

/*----------------------------------------------------------------------

Code from Wrapper.h supporting Views

----------------------------------------------------------------------*/

#include "DataFormats/Common/interface/fwd_fillPtrVector.h"
#include "DataFormats/Common/interface/fwd_setPtr.h"
#include "DataFormats/Common/interface/traits.h"
#include "FWCore/Utilities/interface/EDMException.h"
#include <type_traits>

namespace edm {

  template <typename T>
  struct DoFillView {
    void operator()(T const& obj,
                    ProductID const& id,
                    std::vector<void const*>& pointers,
                    FillViewHelperVector& helpers) const;
  };

  template <typename T>
  struct DoNotFillView {
    void operator()(T const&, ProductID const&, std::vector<void const*>&, FillViewHelperVector&) const {
      Exception::throwThis(
          errors::ProductDoesNotSupportViews, "The product type ", typeid(T).name(), "\ndoes not support Views\n");
    }
  };

  template <typename T>
  inline void Wrapper<T>::do_fillView(ProductID const& id,
                                      std::vector<void const*>& pointers,
                                      FillViewHelperVector& helpers) const {
    typename std::conditional<has_fillView<T>::value, DoFillView<T>, DoNotFillView<T> >::type maybe_filler;
    maybe_filler(obj, id, pointers, helpers);
  }

  template <typename T>
  struct DoSetPtr {
    void operator()(T const& obj, std::type_info const& iToType, unsigned long iIndex, void const*& oPtr) const;
    void operator()(T const& obj,
                    std::type_info const& iToType,
                    std::vector<unsigned long> const& iIndex,
                    std::vector<void const*>& oPtr) const;
  };

  template <typename T>
  struct DoNotSetPtr {
    void operator()(T const& /*obj*/, std::type_info const& iToType, unsigned long iIndex, void const*& oPtr) const {
      Exception::throwThis(
          errors::ProductDoesNotSupportPtr, "The product type ", typeid(T).name(), "\ndoes not support edm::Ptr\n");
    }
    void operator()(T const& obj,
                    std::type_info const& iToType,
                    std::vector<unsigned long> const& iIndexes,
                    std::vector<void const*>& oPtrs) const {
      Exception::throwThis(errors::ProductDoesNotSupportPtr,
                           "The product type ",
                           typeid(T).name(),
                           "\ndoes not support edm::PtrVector\n");
    }
  };

  template <typename T>
  inline void Wrapper<T>::do_setPtr(std::type_info const& iToType, unsigned long iIndex, void const*& oPtr) const {
    typename std::conditional<has_setPtr<T>::value, DoSetPtr<T>, DoNotSetPtr<T> >::type maybe_filler;
    maybe_filler(this->obj, iToType, iIndex, oPtr);
  }

  template <typename T>
  void Wrapper<T>::do_fillPtrVector(std::type_info const& iToType,
                                    std::vector<unsigned long> const& iIndices,
                                    std::vector<void const*>& oPtr) const {
    typename std::conditional<has_setPtr<T>::value, DoSetPtr<T>, DoNotSetPtr<T> >::type maybe_filler;
    maybe_filler(this->obj, iToType, iIndices, oPtr);
  }
}  // namespace edm

namespace edm {

  template <typename T>
  class PtrVector;

  namespace helpers {
    template <typename T>
    struct ViewFiller {
      static void fill(T const& obj,
                       ProductID const& id,
                       std::vector<void const*>& pointers,
                       FillViewHelperVector& helpers) {
        fillView(obj, id, pointers, helpers);
        assert(pointers.size() == helpers.size());
      }
    };

    template <typename T>
    struct PtrSetter {
      static void set(T const& obj, std::type_info const& iToType, unsigned long iIndex, void const*& oPtr) {
        // setPtr is the name of an overload set; each concrete collection T should supply a fillView function, in the same
        // namespace at that in which T is defined, or in the 'edm' namespace.
        setPtr(obj, iToType, iIndex, oPtr);
      }

      static void fill(T const& obj,
                       std::type_info const& iToType,
                       std::vector<unsigned long> const& iIndex,
                       std::vector<void const*>& oPtr) {
        // fillPtrVector is the name of an overload set; each concrete collection T should supply a fillPtrVector function,
        // in the same namespace at that in which T is defined, or in the 'edm'  namespace.
        fillPtrVector(obj, iToType, iIndex, oPtr);
      }
    };
  }  // namespace helpers

  template <typename T>
  void DoFillView<T>::operator()(T const& obj,
                                 ProductID const& id,
                                 std::vector<void const*>& pointers,
                                 FillViewHelperVector& helpers) const {
    helpers::ViewFiller<T>::fill(obj, id, pointers, helpers);
  }

  template <typename T>
  void DoSetPtr<T>::operator()(T const& obj,
                               std::type_info const& iToType,
                               unsigned long iIndex,
                               void const*& oPtr) const {
    helpers::PtrSetter<T>::set(obj, iToType, iIndex, oPtr);
  }

  template <typename T>
  void DoSetPtr<T>::operator()(T const& obj,
                               std::type_info const& iToType,
                               std::vector<unsigned long> const& iIndices,
                               std::vector<void const*>& oPtr) const {
    helpers::PtrSetter<T>::fill(obj, iToType, iIndices, oPtr);
  }

}  // namespace edm

#include "DataFormats/Common/interface/FillView.h"
#include "DataFormats/Common/interface/setPtr.h"
#include "DataFormats/Common/interface/fillPtrVector.h"

#endif