CMS 3D CMS Logo

FwdPtr.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_FwdPtr_h
2 #define DataFormats_Common_FwdPtr_h
3 // -*- C++ -*-
4 //
5 // Package: Common
6 // Class : FwdPtr
7 //
16 //
17 // Original Author: Salvatore Rappoccio
18 // Created: Fri Feb 5 14:58:49 CST 2010
19 //
20 
21 // user include files
31 
33 
34 // system include files
35 #include <cassert>
36 
37 // forward declarations
38 namespace edm {
39  template <typename T>
40  class FwdPtr {
41  friend class FwdPtrVectorBase;
42 
43  public:
44  typedef unsigned long key_type;
45  typedef T value_type;
46 
47  // General purpose constructor from two Ptrs.
48  template <typename C>
49  FwdPtr(const Ptr<C>& f, const Ptr<C>& b) : ptr_(f), backPtr_(b) {
50  assert(f.isNull() == b.isNull());
51  }
52 
53  FwdPtr() : ptr_(), backPtr_() {}
54 
55  /* template<typename U> */
56  /* FwdPtr(FwdPtr<U> const& iOther, typename boost::enable_if_c<boost::is_base_of<T, U>::value>::type * t = 0): */
57  /* ptr_(iOther.ptr_, t), backPtr_(iOther.backPtr_,t) */
58  /* { */
59  /* } */
60 
61  /* template<typename U> */
62  /* explicit */
63  /* FwdPtr(FwdPtr<U> const& iOther, typename boost::enable_if_c<boost::is_base_of<U, T>::value>::type * t = 0): */
64  /* ptr_(iOther.ptr_,t), backPtr_(iOther.backPtr_,t){} */
65 
67  ~FwdPtr() {}
68 
70  T const& operator*() const { return ptr_.isAvailable() ? ptr_.operator*() : backPtr_.operator*(); }
71 
73  T const* operator->() const { return ptr_.isAvailable() ? ptr_.operator->() : backPtr_.operator->(); }
74 
76  T const* get() const { return ptr_.isAvailable() ? ptr_.get() : backPtr_.get(); }
77 
79  bool isNull() const { return !isNonnull(); }
80 
82  //bool isNonnull() const {return id().isValid(); }
83  bool isNonnull() const { return ptr_.isNonnull() || backPtr_.isNonnull(); }
85  bool operator!() const { return isNull(); }
86 
89  bool isAvailable() const { return ptr_.isAvailable() || backPtr_.isAvailable(); }
90 
92  bool isTransient() const { return ptr_.isTransient(); }
93 
95  ProductID id() const { return ptr_.isNonnull() ? ptr_.id() : backPtr_.id(); }
96 
98  EDProductGetter const* productGetter() const {
99  //another thread might cause productGetter() to change its value
100  EDProductGetter const* getter = ptr_.productGetter();
101  if (getter)
102  return getter;
103  else
104  return backPtr_.productGetter();
105  }
106 
107  key_type key() const { return ptr_.isNonnull() ? ptr_.key() : backPtr_.key(); }
108 
110 
111  RefCore const& refCore() const { return ptr_.isNonnull() ? ptr_.refCore() : backPtr_.refCore(); }
112  // ---------- member functions ---------------------------
113 
114  void const* product() const { return nullptr; }
115 
116  Ptr<value_type> const& ptr() const { return ptr_; }
117  Ptr<value_type> const& backPtr() const { return backPtr_; }
118 
119  //Used by ROOT storage
121 
122  private:
125  };
126 
127  template <typename T>
128  inline bool operator==(FwdPtr<T> const& lhs, FwdPtr<T> const& rhs) {
129  return (lhs.ptr() == rhs.ptr() || lhs.backPtr() == rhs.ptr() || lhs.ptr() == rhs.backPtr() ||
130  lhs.backPtr() == rhs.backPtr());
131  }
132 
133  template <typename T>
134  inline bool operator!=(FwdPtr<T> const& lhs, FwdPtr<T> const& rhs) {
135  return !(lhs == rhs);
136  }
137 
138  template <typename T>
139  inline bool operator<(FwdPtr<T> const& lhs, FwdPtr<T> const& rhs) {
142  return (lhs.ptr() < rhs.ptr());
143  }
144 
145 } // namespace edm
146 #endif
edm::RefCore
Definition: RefCore.h:21
Handle.h
edm::FwdPtr::backPtr_
Ptr< value_type > backPtr_
Definition: FwdPtr.h:124
edm::Ptr::hasProductCache
bool hasProductCache() const
Definition: Ptr.h:165
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
edm::FwdPtr::~FwdPtr
~FwdPtr()
Destructor.
Definition: FwdPtr.h:67
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::Ptr::refCore
RefCore const & refCore() const
Definition: Ptr.h:167
edm::FwdPtr::key
key_type key() const
Definition: FwdPtr.h:107
edm::Ptr::productGetter
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: Ptr.h:161
cms::cuda::assert
assert(be >=bs)
edm::Ptr::get
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:139
edm::FwdPtr::isAvailable
bool isAvailable() const
Definition: FwdPtr.h:89
edm::Ptr::key
key_type key() const
Definition: Ptr.h:163
watchdog.const
const
Definition: watchdog.py:83
GetProduct.h
edm::FwdPtr::ptr
Ptr< value_type > const & ptr() const
Definition: FwdPtr.h:116
Utilities.operator
operator
Definition: Utilities.py:24
EDMException.h
edm::EDProductGetter
Definition: EDProductGetter.h:41
edm::operator!=
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
Definition: debugging_allocator.h:75
edm::FwdPtr::productGetter
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: FwdPtr.h:98
edm::FwdPtr::FwdPtr
FwdPtr()
Definition: FwdPtr.h:53
OrphanHandle.h
edm::FwdPtr::operator!
bool operator!() const
Checks for null.
Definition: FwdPtr.h:85
edm::operator<
bool operator<(DetSet< T > const &x, DetSet< T > const &y)
Definition: DetSet.h:89
edm::FwdPtr::refCore
RefCore const & refCore() const
Definition: FwdPtr.h:111
edm::FwdPtr::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: FwdPtr.h:83
edm::FwdPtr::key_type
unsigned long key_type
Definition: FwdPtr.h:44
edm::FwdPtr::isTransient
bool isTransient() const
Checks if this FwdPtr is transient (i.e. not persistable).
Definition: FwdPtr.h:92
CMS_CLASS_VERSION
#define CMS_CLASS_VERSION(_version_)
Definition: CMS_CLASS_VERSION.h:30
b
double b
Definition: hdecay.h:118
edm::FwdPtr
Definition: FwdPtr.h:40
edm::Ptr::id
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:158
edm::Ptr::isTransient
bool isTransient() const
Checks if this Ptr is transient (i.e. not persistable).
Definition: Ptr.h:155
edm::FwdPtr::FwdPtrVectorBase
friend class FwdPtrVectorBase
Definition: FwdPtr.h:41
Ptr.h
svgfig.template
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
edm::Ptr
Definition: AssociationVector.h:31
edm::FwdPtr::hasProductCache
bool hasProductCache() const
Definition: FwdPtr.h:109
edm::FwdPtr::isNull
bool isNull() const
Checks for null.
Definition: FwdPtr.h:79
edm::FwdPtr::ptr_
Ptr< value_type > ptr_
Definition: FwdPtr.h:123
edm::FwdPtr::operator->
T const * operator->() const
Member dereference operator.
Definition: FwdPtr.h:73
CMS_CLASS_VERSION.h
edm::FwdPtr::id
ProductID id() const
Accessor for product ID.
Definition: FwdPtr.h:95
T
long double T
Definition: Basic3DVectorLD.h:48
edm::FwdPtr::get
T const * get() const
Returns C++ pointer to the item.
Definition: FwdPtr.h:76
edm::Ptr::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:146
edm::FwdPtr::backPtr
Ptr< value_type > const & backPtr() const
Definition: FwdPtr.h:117
EDProductGetter.h
edm::FwdPtr::operator*
T const & operator*() const
Dereference operator.
Definition: FwdPtr.h:70
edm::Ptr::isAvailable
bool isAvailable() const
Definition: Ptr.h:230
traits.h
RefCore.h
edm::FwdPtr::FwdPtr
FwdPtr(const Ptr< C > &f, const Ptr< C > &b)
Definition: FwdPtr.h:49
TestHandle.h
edm::ProductID
Definition: ProductID.h:27
edm::FwdPtr::product
void const * product() const
Definition: FwdPtr.h:114
edm::FwdPtr::value_type
T value_type
Definition: FwdPtr.h:45