CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
Ptr< value_type > const & ptr() const
Definition: FwdPtr.h:116
T const & operator*() const
Dereference operator.
Definition: FwdPtr.h:70
key_type key() const
Definition: Ptr.h:163
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:139
bool isAvailable() const
Definition: Ptr.h:230
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: Ptr.h:161
unsigned long key_type
Definition: FwdPtr.h:44
#define CMS_CLASS_VERSION(_version_)
assert(be >=bs)
FwdPtr()
Definition: FwdPtr.h:53
Ptr< value_type > const & backPtr() const
Definition: FwdPtr.h:117
bool hasProductCache() const
Definition: FwdPtr.h:109
~FwdPtr()
Destructor.
Definition: FwdPtr.h:67
RefCore const & refCore() const
Definition: FwdPtr.h:111
bool isTransient() const
Checks if this Ptr is transient (i.e. not persistable).
Definition: Ptr.h:155
bool isAvailable() const
Definition: FwdPtr.h:89
bool isNull() const
Checks for null.
Definition: FwdPtr.h:79
bool isNull() const
Checks for null.
Definition: Ptr.h:142
RefCore const & refCore() const
Definition: Ptr.h:167
constexpr bool operator!=(ELseverityLevel const &e1, ELseverityLevel const &e2) noexcept
void const * product() const
Definition: FwdPtr.h:114
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:146
bool isTransient() const
Checks if this FwdPtr is transient (i.e. not persistable).
Definition: FwdPtr.h:92
T value_type
Definition: FwdPtr.h:45
bool operator!() const
Checks for null.
Definition: FwdPtr.h:85
bool hasProductCache() const
Definition: Ptr.h:165
double b
Definition: hdecay.h:118
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:158
FwdPtr(const Ptr< C > &f, const Ptr< C > &b)
Definition: FwdPtr.h:49
ProductID id() const
Accessor for product ID.
Definition: FwdPtr.h:95
Ptr< value_type > ptr_
Definition: FwdPtr.h:123
long double T
bool isNonnull() const
Checks for non-null.
Definition: FwdPtr.h:83
friend class FwdPtrVectorBase
Definition: FwdPtr.h:41
T const * operator->() const
Member dereference operator.
Definition: FwdPtr.h:73
key_type key() const
Definition: FwdPtr.h:107
def template
Definition: svgfig.py:521
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: FwdPtr.h:98
Ptr< value_type > backPtr_
Definition: FwdPtr.h:124