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

#include <fwd.h>

Classes

class  HandleTag
 

Public Types

using element_type = T
 

Public Member Functions

 ~Handle ()=default
 
constexpr Handle ()=default
 
 Handle (GroupQueryResult const &)
 
 Handle (Handle const &)=default
 
 Handle (Handle &&)=default
 
Handleoperator= (Handle const &)=default
 
Handleoperator= (Handle &&)=default
 
T const & operator* () const
 
T const * operator-> () const
 
T const * product () const
 
 operator bool () const noexcept
 
bool isValid () const noexcept
 
bool failedToGet () const
 
Provenance const * provenance () const
 
ProductID id () const
 
std::shared_ptr< art::Exception const > whyFailed () const
 
void swap (Handle< T > &other)
 
void clear ()
 

Private Attributes

T const * prod_ {nullptr}
 
Provenance prov_ {}
 
std::shared_ptr< art::Exception const > whyFailed_ {nullptr}
 

Detailed Description

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

Definition at line 19 of file fwd.h.

Member Typedef Documentation

template<typename T>
using art::Handle< T >::element_type = T

Definition at line 93 of file Handle.h.

Constructor & Destructor Documentation

template<typename T>
art::Handle< T >::~Handle ( )
default
template<typename T>
constexpr art::Handle< T >::Handle ( )
explicitdefault
template<class T >
art::Handle< T >::Handle ( GroupQueryResult const &  gqr)
explicit

Definition at line 133 of file Handle.h.

134  : prod_{nullptr}, prov_{gqr.result()}, whyFailed_{gqr.whyFailed()}
135 {
136  if (gqr.succeeded()) {
137  auto const wrapperPtr = dynamic_cast<Wrapper<T> const*>(
138  gqr.result()->uniqueProduct(TypeID{typeid(Wrapper<T>)}));
139  if (wrapperPtr != nullptr) {
140  prod_ = wrapperPtr->product();
141  } else {
143  e << "Product retrieval via Handle<T> succeeded for product:\n"
145  << "but an attempt to interpret it as an object of type '"
146  << cet::demangle_symbol(typeid(T).name()) << "' failed.\n";
147  whyFailed_ = std::make_shared<art::Exception const>(std::move(e));
148  }
149  }
150 }
static QCString name
Definition: declinfo.cpp:673
BranchDescription const & productDescription() const noexcept
Definition: Provenance.cc:24
T const * prod_
Definition: Handle.h:124
std::shared_ptr< art::Exception const > whyFailed_
Definition: Handle.h:126
const double e
def move(depos, offset)
Definition: depos.py:107
Provenance prov_
Definition: Handle.h:125
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
template<typename T>
art::Handle< T >::Handle ( Handle< T > const &  )
default
template<typename T>
art::Handle< T >::Handle ( Handle< T > &&  )
default

Member Function Documentation

template<class T >
void art::Handle< T >::clear ( )

Definition at line 236 of file Handle.h.

237 {
238  Handle<T> tmp;
239  swap(tmp);
240 }
void swap(Handle< T > &other)
Definition: Handle.h:229
string tmp
Definition: languages.py:63
template<class T >
bool art::Handle< T >::failedToGet ( ) const

Definition at line 198 of file Handle.h.

199 {
200  return whyFailed_.get();
201 }
std::shared_ptr< art::Exception const > whyFailed_
Definition: Handle.h:126
template<class T >
art::ProductID art::Handle< T >::id ( ) const
inline

Definition at line 212 of file Handle.h.

213 {
214  return prov_.isValid() ? prov_.productID() : ProductID{};
215 }
bool isValid() const noexcept
Definition: Provenance.cc:18
ProductID productID() const noexcept
Definition: Provenance.cc:72
Provenance prov_
Definition: Handle.h:125
template<class T >
bool art::Handle< T >::isValid ( ) const
noexcept

Definition at line 191 of file Handle.h.

192 {
193  return prod_ && prov_.isValid();
194 }
bool isValid() const noexcept
Definition: Provenance.cc:18
T const * prod_
Definition: Handle.h:124
Provenance prov_
Definition: Handle.h:125
template<class T >
art::Handle< T >::operator bool ( ) const
inlineexplicitnoexcept

Definition at line 184 of file Handle.h.

185 {
186  return isValid();
187 }
bool isValid() const noexcept
Definition: Handle.h:191
template<class T >
T const & art::Handle< T >::operator* ( ) const
inline

Definition at line 156 of file Handle.h.

157 {
158  return *product();
159 }
T const * product() const
Definition: Handle.h:163
template<class T >
T const * art::Handle< T >::operator-> ( ) const
inline

Definition at line 175 of file Handle.h.

176 {
177  return product();
178 }
T const * product() const
Definition: Handle.h:163
template<typename T>
Handle& art::Handle< T >::operator= ( Handle< T > const &  )
default
template<typename T>
Handle& art::Handle< T >::operator= ( Handle< T > &&  )
default
template<class T >
T const * art::Handle< T >::product ( ) const

Definition at line 163 of file Handle.h.

164 {
165  if (failedToGet()) {
166  throw *whyFailed_;
167  }
168  if (prod_ == nullptr)
170  << "Attempt to de-reference product that points to 'nullptr'.\n";
171  return prod_;
172 }
T const * prod_
Definition: Handle.h:124
std::shared_ptr< art::Exception const > whyFailed_
Definition: Handle.h:126
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
bool failedToGet() const
Definition: Handle.h:198
template<class T >
art::Provenance const * art::Handle< T >::provenance ( ) const
inline

Definition at line 205 of file Handle.h.

206 {
207  return &prov_;
208 }
Provenance prov_
Definition: Handle.h:125
template<class T>
void art::Handle< T >::swap ( Handle< T > &  other)

Definition at line 229 of file Handle.h.

230 {
231  std::swap(*this, other);
232 }
void swap(ValidHandle< T > &a, ValidHandle< T > &b)
template<class T >
std::shared_ptr< art::Exception const > art::Handle< T >::whyFailed ( ) const
inline

Definition at line 219 of file Handle.h.

220 {
221  return whyFailed_;
222 }
std::shared_ptr< art::Exception const > whyFailed_
Definition: Handle.h:126

Member Data Documentation

template<typename T>
T const* art::Handle< T >::prod_ {nullptr}
private

Definition at line 124 of file Handle.h.

template<typename T>
Provenance art::Handle< T >::prov_ {}
private

Definition at line 125 of file Handle.h.

template<typename T>
std::shared_ptr<art::Exception const> art::Handle< T >::whyFailed_ {nullptr}
private

Definition at line 126 of file Handle.h.


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