1 #ifndef DataFormats_Common_Ref_h
2 #define DataFormats_Common_Ref_h
115 #include "boost/functional.hpp"
118 #include <type_traits>
124 template <
typename,
typename =
void>
126 template <
typename T>
129 template <
typename C,
typename K>
132 using comparison_functor =
typename C::key_compare;
133 return comparison_functor()(lhs, rhs);
139 template <
typename C,
typename T,
typename F>
142 template <
typename T>
145 template <
typename C,
163 typedef typename boost::binary_traits<F>::second_argument_type
argument_type;
184 Ref(
C const* product,
key_type itemKey,
bool setNow =
true);
285 #define REF_FOR_VECTOR_ARGS \
286 std::vector<E>, typename refhelper::ValueTrait<std::vector<E>>::value, \
287 typename refhelper::FindTrait<std::vector<E>, typename refhelper::ValueTrait<std::vector<E>>::value>::value
289 template <
typename E>
300 friend class
RefVector<RefVector<std::vector<E>, T, F>, T, VF>;
301 friend class
RefVector<RefVector<std::vector<E>, T, F>, T, VBF>;
310 typedef typename boost::binary_traits<F>::second_argument_type
argument_type;
358 :
product_(iProductID,
item, nullptr, transient, itemKey) {}
436 template <
typename C,
typename T,
typename F>
438 : product_(
handle.
id(), nullptr, nullptr,
false), index_(itemKey) {
441 refitem::findRefItem<C, T, F, key_type>(product_,
handle.product(), itemKey);
445 template <
typename E>
450 refitem::findRefItem<product_type, value_type, finder_type, key_type>(
451 product_.toRefCore(),
handle.product(), itemKey);
455 template <
typename C,
typename T,
typename F>
457 : product_(
handle.
id(), nullptr, nullptr,
false), index_(itemKey) {
460 refitem::findRefItem<C, T, F, key_type>(product_,
handle.product(), itemKey);
464 template <
typename E>
469 refitem::findRefItem<product_type, value_type, finder_type, key_type>(
470 product_.toRefCore(),
handle.product(), itemKey);
480 template <
typename C,
typename T,
typename F>
484 if (iProduct !=
nullptr) {
485 refitem::findRefItem<C, T, F, key_type>(product_, iProduct, itemKey);
489 template <
typename E>
492 if (iProduct !=
nullptr) {
493 refitem::findRefItem<product_type, value_type, finder_type, key_type>(product_.toRefCore(), iProduct, itemKey);
499 template <
typename C,
typename T,
typename F>
501 : product_(
handle.
id(), nullptr, nullptr,
true), index_(itemKey) {
504 refitem::findRefItem<C, T, F, key_type>(product_,
handle.product(), itemKey);
507 template <
typename E>
509 : product_(
handle.
id(), nullptr, nullptr,
true, itemKey) {
512 refitem::findRefItem<product_type, value_type, finder_type, key_type>(
513 product_.toRefCore(),
handle.product(), itemKey);
517 template <
typename C,
typename T,
typename F>
519 : product_(refProd.
id(), nullptr, refProd.refCore().
productGetter(), refProd.refCore().isTransient()),
522 refitem::findRefItem<C, T, F, key_type>(
523 product_, static_cast<product_type const*>(refProd.
refCore().productPtr()), itemKey);
527 template <
typename E>
529 : product_(refProd.
id(), nullptr, refProd.refCore().
productGetter(), refProd.refCore().isTransient(), itemKey) {
531 refitem::findRefItem<product_type, value_type, finder_type, key_type>(
532 product_.toRefCore(), static_cast<product_type const*>(refProd.refCore().productPtr()), itemKey);
536 template <
typename C,
typename T,
typename F>
538 if (product_.isAvailable()) {
541 return isThinnedAvailable<C>(product_, index_);
544 template <
typename E>
546 if (product_.isAvailable()) {
549 return isThinnedAvailable<std::vector<E>>(product_.toRefCore(),
key());
553 template <
typename C,
typename T,
typename F>
555 return *getRefPtr<C, T, F>(product_, index_);
557 template <
typename E>
559 return *getRefPtr<REF_FOR_VECTOR_ARGS>(product_.toRefCore(),
key());
563 template <
typename C,
typename T,
typename F>
565 return getRefPtr<C, T, F>(product_, index_);
567 template <
typename E>
569 return getRefPtr<REF_FOR_VECTOR_ARGS>(product_.toRefCore(),
key());
572 template <
typename C,
typename T,
typename F>
574 return lhs.key() == rhs.key() && lhs.refCore() == rhs.refCore();
577 template <
typename C,
typename T,
typename F>
579 return !(lhs == rhs);
582 template <
typename C,
typename T,
typename F>
586 return (lhs.refCore() == rhs.refCore() ? compare_key<C>(lhs.key(), rhs.key()) : lhs.refCore() < rhs.refCore());