Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
art::Ptr< T > Class Template Reference

#include <fwd.h>

Public Types

using key_type = std::size_t
 
using value_type = T
 
using const_pointer = T const *
 
using const_reference = T const &
 

Public Member Functions

 Ptr ()=default
 
template<typename H >
 Ptr (H const &handle, typename Ptr< T >::key_type key)
 
 Ptr (ProductID const &productID)
 
 Ptr (ProductID const &productID, key_type itemKey, EDProductGetter const *prodGetter)
 
template<typename U >
 Ptr (Ptr< U > const &pu, std::enable_if_t< std::is_base_of_v< T, U >> *=nullptr)
 
template<typename U >
 Ptr (Ptr< U > const &pu, std::enable_if_t< std::is_base_of_v< U, T >> *=nullptr)
 
 Ptr (ProductID const &productID, T const *item, key_type const itemKey)
 
T const & operator* () const
 
T const * get () const
 
T const * operator-> () const
 
bool isNonnull () const noexcept
 
bool isNull () const noexcept
 
 operator bool () const
 
RefCore const & refCore () const noexcept
 
ProductID id () const noexcept
 
EDProductGetter const * productGetter () const noexcept
 
bool isAvailable () const
 
bool hasCache () const noexcept
 
key_type key () const noexcept
 

Static Public Member Functions

static constexpr short Class_Version () noexcept
 

Private Member Functions

EDProduct const * parentProduct_ () const
 

Private Attributes

RefCore core_ {}
 
key_type key_ {key_traits<key_type>::value}
 

Detailed Description

template<typename T>
class art::Ptr< T >

Definition at line 31 of file fwd.h.

Member Typedef Documentation

template<typename T>
using art::Ptr< T >::const_pointer = T const*

Definition at line 81 of file Ptr.h.

template<typename T>
using art::Ptr< T >::const_reference = T const&

Definition at line 82 of file Ptr.h.

template<typename T>
using art::Ptr< T >::key_type = std::size_t

Definition at line 79 of file Ptr.h.

template<typename T>
using art::Ptr< T >::value_type = T

Definition at line 80 of file Ptr.h.

Constructor & Destructor Documentation

template<typename T>
art::Ptr< T >::Ptr ( )
default
template<typename T>
template<typename H >
art::Ptr< T >::Ptr ( H const &  handle,
typename Ptr< T >::key_type  key 
)
inline

Definition at line 88 of file Ptr.h.

89  : core_{handle.id(),
90  detail::ItemGetter<T,
91  std::remove_const_t<std::remove_pointer_t<
92  decltype(handle.product())>>>()(
93  handle.product(),
94  key),
95  nullptr}
96  , key_{key}
97  {
98  if (core_.isNull()) {
100  << "Attempt to construct a Ptr from a Handle with invalid ProductID. "
101  "Perhaps a\n"
102  "default-constructed Ptr is what you want?";
103  }
104  }
RefCore core_
Definition: Ptr.h:256
key_type key_
Definition: Ptr.h:259
constexpr bool isNull() const noexcept
Definition: RefCore.h:33
key_type key() const noexcept
Definition: Ptr.h:216
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
constexpr ProductID id() const noexcept
Definition: RefCore.h:46
template<typename T>
art::Ptr< T >::Ptr ( ProductID const &  productID)
inlineexplicit

Definition at line 107 of file Ptr.h.

108  : core_{productID, nullptr, nullptr}
109  {}
RefCore core_
Definition: Ptr.h:256
template<typename T>
art::Ptr< T >::Ptr ( ProductID const &  productID,
key_type  itemKey,
EDProductGetter const *  prodGetter 
)
inline

Definition at line 112 of file Ptr.h.

115  : core_{productID, nullptr, prodGetter}, key_{itemKey}
116  {}
RefCore core_
Definition: Ptr.h:256
key_type key_
Definition: Ptr.h:259
template<typename T>
template<typename U >
art::Ptr< T >::Ptr ( Ptr< U > const &  pu,
std::enable_if_t< std::is_base_of_v< T, U >> *  = nullptr 
)
inline

Definition at line 120 of file Ptr.h.

121  : core_{pu.id(),
122  (pu.hasCache() ? static_cast<T const*>(pu.get()) : nullptr),
123  pu.productGetter()}
124  , key_{pu.key()}
125  {}
RefCore core_
Definition: Ptr.h:256
key_type key_
Definition: Ptr.h:259
constexpr ProductID id() const noexcept
Definition: RefCore.h:46
template<typename T>
template<typename U >
art::Ptr< T >::Ptr ( Ptr< U > const &  pu,
std::enable_if_t< std::is_base_of_v< U, T >> *  = nullptr 
)
inline

Definition at line 128 of file Ptr.h.

129  : core_{pu.id(), static_cast<T const*>(pu.get()), nullptr}, key_{pu.key()}
130  {}
RefCore core_
Definition: Ptr.h:256
key_type key_
Definition: Ptr.h:259
constexpr ProductID id() const noexcept
Definition: RefCore.h:46
template<typename T>
art::Ptr< T >::Ptr ( ProductID const &  productID,
T const *  item,
key_type const  itemKey 
)
inline

Definition at line 133 of file Ptr.h.

134  : core_{productID, item, nullptr}, key_{itemKey}
135  {}
RefCore core_
Definition: Ptr.h:256
key_type key_
Definition: Ptr.h:259

Member Function Documentation

template<typename T>
static constexpr short art::Ptr< T >::Class_Version ( )
inlinestaticnoexcept

Definition at line 223 of file Ptr.h.

224  {
225  return 10;
226  }
template<typename T>
T const* art::Ptr< T >::get ( ) const
inline

Definition at line 149 of file Ptr.h.

150  {
151  return isNull() ? nullptr : operator->();
152  }
T const * operator->() const
Definition: Ptr.h:154
bool isNull() const noexcept
Definition: Ptr.h:173
template<typename T>
bool art::Ptr< T >::hasCache ( ) const
inlinenoexcept

Definition at line 210 of file Ptr.h.

211  {
212  return core_.productPtr() != nullptr;
213  }
RefCore core_
Definition: Ptr.h:256
void const * productPtr() const noexcept
Definition: RefCore.cc:34
template<typename T>
ProductID art::Ptr< T >::id ( ) const
inlinenoexcept

Definition at line 190 of file Ptr.h.

191  {
192  return core_.id();
193  }
RefCore core_
Definition: Ptr.h:256
constexpr ProductID id() const noexcept
Definition: RefCore.h:46
template<typename T>
bool art::Ptr< T >::isAvailable ( ) const
inline

Definition at line 204 of file Ptr.h.

205  {
206  return core_.isAvailable();
207  }
RefCore core_
Definition: Ptr.h:256
bool isAvailable() const
Definition: RefCore.cc:24
template<typename T>
bool art::Ptr< T >::isNonnull ( ) const
inlinenoexcept

Definition at line 166 of file Ptr.h.

167  {
169  }
key_type key_
Definition: Ptr.h:259
static constexpr key_type value
Definition: traits.h:38
template<typename T>
bool art::Ptr< T >::isNull ( ) const
inlinenoexcept

Definition at line 173 of file Ptr.h.

174  {
175  return !isNonnull();
176  }
bool isNonnull() const noexcept
Definition: Ptr.h:166
template<typename T>
key_type art::Ptr< T >::key ( ) const
inlinenoexcept

Definition at line 216 of file Ptr.h.

217  {
218  return key_;
219  }
key_type key_
Definition: Ptr.h:259
template<typename T>
art::Ptr< T >::operator bool ( ) const
inlineexplicit

Definition at line 178 of file Ptr.h.

179  {
181  }
RefCore core_
Definition: Ptr.h:256
key_type key_
Definition: Ptr.h:259
bool isAvailable() const
Definition: RefCore.cc:24
static constexpr key_type value
Definition: traits.h:38
template<typename T>
T const& art::Ptr< T >::operator* ( ) const
inline

Definition at line 141 of file Ptr.h.

142  {
143  // FIXME: This causes an nullptr dereference if isNull!
144  // return isNull() ? nullptr : operator->();
145  return *get();
146  }
template<typename T>
T const* art::Ptr< T >::operator-> ( ) const
inline

Definition at line 154 of file Ptr.h.

155  {
156  if (core_.productPtr() == nullptr) {
157  EDProduct const* prod = parentProduct_();
158  void const* ad = prod->getElementAddress(typeid(T), key_);
159  core_.setProductPtr(ad);
160  }
161  return reinterpret_cast<T const*>(core_.productPtr());
162  }
RefCore core_
Definition: Ptr.h:256
EDProduct const * parentProduct_() const
Definition: Ptr.h:230
key_type key_
Definition: Ptr.h:259
void const * productPtr() const noexcept
Definition: RefCore.cc:34
void setProductPtr(void const *prodPtr) const noexcept
Definition: RefCore.cc:48
template<typename T>
EDProduct const* art::Ptr< T >::parentProduct_ ( ) const
inlineprivate

Definition at line 230 of file Ptr.h.

231  {
232  EDProduct const* product{nullptr};
233  if (productGetter()) {
234  product = productGetter()->getIt();
235  }
236  if (product == nullptr) {
238  e << "A request to resolve an Ptr to a product containing items of "
239  "type: "
240  << cet::demangle_symbol(typeid(T).name()) << " with ProductID "
241  << core_.id()
242  << "\ncannot be satisfied because the product cannot be found.\n";
243  if (productGetter() == nullptr) {
244  e << "The productGetter was not set -- are you trying to "
245  "dereference a Ptr during mixing?\n";
246  } else {
247  e << "Probably the branch containing the product is not stored in "
248  "the input file.\n";
249  }
250  throw e;
251  }
252  return product;
253  }
static QCString name
Definition: declinfo.cpp:673
EDProduct const * getIt() const
RefCore core_
Definition: Ptr.h:256
const double e
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
EDProductGetter const * productGetter() const noexcept
Definition: Ptr.h:196
constexpr ProductID id() const noexcept
Definition: RefCore.h:46
template<typename T>
EDProductGetter const* art::Ptr< T >::productGetter ( ) const
inlinenoexcept

Definition at line 196 of file Ptr.h.

197  {
198  return core_.productGetter();
199  }
EDProductGetter const * productGetter() const noexcept
Definition: RefCore.cc:41
RefCore core_
Definition: Ptr.h:256
template<typename T>
RefCore const& art::Ptr< T >::refCore ( ) const
inlinenoexcept

Definition at line 184 of file Ptr.h.

185  {
186  return core_;
187  }
RefCore core_
Definition: Ptr.h:256

Member Data Documentation

template<typename T>
RefCore art::Ptr< T >::core_ {}
private

Definition at line 256 of file Ptr.h.

template<typename T>
key_type art::Ptr< T >::key_ {key_traits<key_type>::value}
private

Definition at line 259 of file Ptr.h.


The documentation for this class was generated from the following files: