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
bool hasProductCache() const
Definition: FwdPtr.h:109
bool isNonnull() const
Checks for non-null.
Definition: FwdPtr.h:83
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:162
RefCore const & refCore() const
Definition: FwdPtr.h:111
T const * operator->() const
Member dereference operator.
Definition: FwdPtr.h:73
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: FwdPtr.h:98
unsigned long key_type
Definition: FwdPtr.h:44
#define CMS_CLASS_VERSION(_version_)
assert(be >=bs)
bool isAvailable() const
Definition: Ptr.h:234
FwdPtr()
Definition: FwdPtr.h:53
bool isTransient() const
Checks if this FwdPtr is transient (i.e. not persistable).
Definition: FwdPtr.h:92
~FwdPtr()
Destructor.
Definition: FwdPtr.h:67
bool operator!() const
Checks for null.
Definition: FwdPtr.h:85
T const & operator*() const
Dereference operator.
Definition: FwdPtr.h:70
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:148
bool isNull() const
Checks for null.
Definition: FwdPtr.h:79
double f[11][100]
void const * product() const
Definition: FwdPtr.h:114
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
Ptr< value_type > const & backPtr() const
Definition: FwdPtr.h:117
constexpr bool operator!=(ELseverityLevel const &e1, ELseverityLevel const &e2) noexcept
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:141
T value_type
Definition: FwdPtr.h:45
bool hasProductCache() const
Definition: Ptr.h:169
double b
Definition: hdecay.h:120
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: Ptr.h:165
FwdPtr(const Ptr< C > &f, const Ptr< C > &b)
Definition: FwdPtr.h:49
RefCore const & refCore() const
Definition: Ptr.h:171
HLT enums.
ProductID id() const
Accessor for product ID.
Definition: FwdPtr.h:95
key_type key() const
Definition: Ptr.h:167
bool isAvailable() const
Definition: FwdPtr.h:89
key_type key() const
Definition: FwdPtr.h:107
Ptr< value_type > ptr_
Definition: FwdPtr.h:123
Ptr< value_type > const & ptr() const
Definition: FwdPtr.h:116
long double T
friend class FwdPtrVectorBase
Definition: FwdPtr.h:41
Ptr< value_type > backPtr_
Definition: FwdPtr.h:124
bool isTransient() const
Checks if this Ptr is transient (i.e. not persistable).
Definition: Ptr.h:159