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  public:
43 
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):
50  ptr_(f), backPtr_(b)
51  { assert(f.isNull() == b.isNull()); }
52 
53  FwdPtr() :
54  ptr_(), backPtr_()
55  {}
56 
57  /* template<typename U> */
58  /* FwdPtr(FwdPtr<U> const& iOther, typename boost::enable_if_c<boost::is_base_of<T, U>::value>::type * t = 0): */
59  /* ptr_(iOther.ptr_, t), backPtr_(iOther.backPtr_,t) */
60  /* { */
61  /* } */
62 
63  /* template<typename U> */
64  /* explicit */
65  /* FwdPtr(FwdPtr<U> const& iOther, typename boost::enable_if_c<boost::is_base_of<U, T>::value>::type * t = 0): */
66  /* ptr_(iOther.ptr_,t), backPtr_(iOther.backPtr_,t){} */
67 
68 
70  ~FwdPtr() {}
71 
73  T const&
74  operator*() const { return ptr_.isAvailable() ? ptr_.operator*() : backPtr_.operator*();}
75 
77  T const*
78  operator->() const{ return ptr_.isAvailable() ? ptr_.operator->() : backPtr_.operator->();}
79 
81  T const* get() const { return ptr_.isAvailable() ? ptr_.get() : backPtr_.get();}
82 
83 
85  bool isNull() const {return !isNonnull(); }
86 
88  //bool isNonnull() const {return id().isValid(); }
89  bool isNonnull() const {return ptr_.isNonnull() || backPtr_.isNonnull(); }
91  bool operator!() const {return isNull();}
92 
95  bool isAvailable() const {return ptr_.isAvailable() || backPtr_.isAvailable();}
96 
98  bool isTransient() const {return ptr_.isTransient();}
99 
101  ProductID id() const {return ptr_.isNonnull() ? ptr_.id() : backPtr_.id();}
102 
105  //another thread might cause productGetter() to change its value
106  EDProductGetter const* getter = ptr_.productGetter();
107  if (getter) return getter;
108  else return backPtr_.productGetter();
109  }
110 
111  key_type key() const {return ptr_.isNonnull() ? ptr_.key() : backPtr_.key() ;}
112 
114 
115  RefCore const& refCore() const {return ptr_.isNonnull() ? ptr_.refCore() : backPtr_.refCore() ;}
116  // ---------- member functions ---------------------------
117 
118  void const* product() const {return nullptr;}
119 
120  Ptr<value_type> const& ptr() const { return ptr_;}
121  Ptr<value_type> const& backPtr() const { return backPtr_;}
122 
123  //Used by ROOT storage
125 
126  private:
127  Ptr<value_type> ptr_;
128  Ptr<value_type> backPtr_;
129  };
130 
131 
132  template<typename T>
133  inline
134  bool
135  operator==(FwdPtr<T> const& lhs, FwdPtr<T> const& rhs) {
136  return (lhs.ptr() == rhs.ptr() ||
137  lhs.backPtr() == rhs.ptr() ||
138  lhs.ptr() == rhs.backPtr() ||
139  lhs.backPtr() == rhs.backPtr());
140  }
141 
142  template<typename T>
143  inline
144  bool
145  operator!=(FwdPtr<T> const& lhs, FwdPtr<T> const& rhs) {
146  return !(lhs == rhs);
147  }
148 
149  template<typename T>
150  inline
151  bool
152  operator<(FwdPtr<T> const& lhs, FwdPtr<T> const& rhs) {
155  return (lhs.ptr() < rhs.ptr());
156  }
157 
158 }
159 #endif
Ptr< value_type > const & ptr() const
Definition: FwdPtr.h:120
T const & operator*() const
Dereference operator.
Definition: FwdPtr.h:74
key_type key() const
Definition: Ptr.h:185
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:159
bool isAvailable() const
Definition: Ptr.h:258
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: Ptr.h:183
unsigned long key_type
Definition: FwdPtr.h:44
#define CMS_CLASS_VERSION(_version_)
Definition: classes.h:31
FwdPtr()
Definition: FwdPtr.h:53
Ptr< value_type > const & backPtr() const
Definition: FwdPtr.h:121
bool hasProductCache() const
Definition: FwdPtr.h:113
~FwdPtr()
Destructor.
Definition: FwdPtr.h:70
RefCore const & refCore() const
Definition: FwdPtr.h:115
bool isTransient() const
Checks if this Ptr is transient (i.e. not persistable).
Definition: Ptr.h:177
bool isAvailable() const
Definition: FwdPtr.h:95
bool isNull() const
Checks for null.
Definition: FwdPtr.h:85
bool isNull() const
Checks for null.
Definition: Ptr.h:164
RefCore const & refCore() const
Definition: Ptr.h:189
double f[11][100]
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:520
void const * product() const
Definition: FwdPtr.h:118
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:168
bool isTransient() const
Checks if this FwdPtr is transient (i.e. not persistable).
Definition: FwdPtr.h:98
T value_type
Definition: FwdPtr.h:45
bool operator!() const
Checks for null.
Definition: FwdPtr.h:91
bool hasProductCache() const
Definition: Ptr.h:187
double b
Definition: hdecay.h:120
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:180
FwdPtr(const Ptr< C > &f, const Ptr< C > &b)
Definition: FwdPtr.h:49
ProductID id() const
Accessor for product ID.
Definition: FwdPtr.h:101
HLT enums.
Ptr< value_type > ptr_
Definition: FwdPtr.h:127
long double T
bool isNonnull() const
Checks for non-null.
Definition: FwdPtr.h:89
friend class FwdPtrVectorBase
Definition: FwdPtr.h:41
T const * operator->() const
Member dereference operator.
Definition: FwdPtr.h:78
key_type key() const
Definition: FwdPtr.h:111
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: FwdPtr.h:104
Ptr< value_type > backPtr_
Definition: FwdPtr.h:128