Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
cet::maybe_ref< T > Class Template Reference

#include <maybe_ref.h>

Public Types

typedef T value_type
 

Public Member Functions

 maybe_ref ()
 
 maybe_ref (T &t)
 
bool isValid () const
 
 operator bool () const
 
void reseat ()
 
void reseat (T &p)
 
T & ref ()
 
T const & ref () const
 
void swap (maybe_ref &other)
 

Private Member Functions

T & ref_iff_valid () const
 

Private Attributes

T * ptr_
 

Detailed Description

template<class T>
class cet::maybe_ref< T >

Definition at line 35 of file maybe_ref.h.

Member Typedef Documentation

template<class T>
typedef T cet::maybe_ref< T >::value_type

Definition at line 52 of file maybe_ref.h.

Constructor & Destructor Documentation

template<class T>
cet::maybe_ref< T >::maybe_ref ( )
inline

Definition at line 54 of file maybe_ref.h.

54 : ptr_(0) {}
template<class T>
cet::maybe_ref< T >::maybe_ref ( T &  t)
inlineexplicit

Definition at line 55 of file maybe_ref.h.

Member Function Documentation

template<class T>
bool cet::maybe_ref< T >::isValid ( ) const
inline

Definition at line 60 of file maybe_ref.h.

61  {
62  return ptr_;
63  }
template<class T>
cet::maybe_ref< T >::operator bool ( ) const
inlineexplicit

Definition at line 64 of file maybe_ref.h.

64 { return isValid(); }
bool isValid() const
Definition: maybe_ref.h:60
template<class T>
T& cet::maybe_ref< T >::ref ( )
inline

Definition at line 78 of file maybe_ref.h.

79  {
80  return ref_iff_valid();
81  }
T & ref_iff_valid() const
Definition: maybe_ref.h:98
template<class T>
T const& cet::maybe_ref< T >::ref ( ) const
inline

Definition at line 83 of file maybe_ref.h.

84  {
85  return ref_iff_valid();
86  }
T & ref_iff_valid() const
Definition: maybe_ref.h:98
template<class T>
T& cet::maybe_ref< T >::ref_iff_valid ( ) const
inlineprivate

Definition at line 98 of file maybe_ref.h.

99  {
100  if (isValid())
101  return *ptr_;
102 
103  // TODO: consider throwing a cet::exception
104  throw std::logic_error("cet::maybe_ref<>: referent does not exist");
105  }
bool isValid() const
Definition: maybe_ref.h:60
template<class T>
void cet::maybe_ref< T >::reseat ( )
inline

Definition at line 67 of file maybe_ref.h.

68  {
69  ptr_ = 0;
70  }
template<class T>
void cet::maybe_ref< T >::reseat ( T &  p)
inline

Definition at line 72 of file maybe_ref.h.

73  {
74  ptr_ = &p;
75  }
p
Definition: test.py:223
template<class T>
void cet::maybe_ref< T >::swap ( maybe_ref< T > &  other)
inline

Definition at line 89 of file maybe_ref.h.

90  {
91  std::swap(ptr_, other.ptr_);
92  }
void swap(maybe_ref< T > &, maybe_ref< T > &)
Definition: maybe_ref.h:113

Member Data Documentation

template<class T>
T* cet::maybe_ref< T >::ptr_
private

Definition at line 95 of file maybe_ref.h.


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