CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 "boost/type_traits/is_base_of.hpp"
36 #include "boost/utility/enable_if.hpp"
37 #include <cassert>
38 
39 // forward declarations
40 namespace edm {
41  template<typename T>
42  class FwdPtr {
43  friend class FwdPtrVectorBase;
44  public:
45 
46  typedef unsigned long key_type;
47  typedef T value_type;
48 
49  // General purpose constructor from two Ptrs.
50  template<typename C>
51  FwdPtr(const Ptr<C>& f, const Ptr<C>& b):
52  ptr_(f), backPtr_(b)
53  { assert(f.isNull() == b.isNull()); }
54 
55  FwdPtr() :
56  ptr_(), backPtr_()
57  {}
58 
59  /* template<typename U> */
60  /* FwdPtr(FwdPtr<U> const& iOther, typename boost::enable_if_c<boost::is_base_of<T, U>::value>::type * t = 0): */
61  /* ptr_(iOther.ptr_, t), backPtr_(iOther.backPtr_,t) */
62  /* { */
63  /* } */
64 
65  /* template<typename U> */
66  /* explicit */
67  /* FwdPtr(FwdPtr<U> const& iOther, typename boost::enable_if_c<boost::is_base_of<U, T>::value>::type * t = 0): */
68  /* ptr_(iOther.ptr_,t), backPtr_(iOther.backPtr_,t){} */
69 
70 
72  ~FwdPtr() {}
73 
75  T const&
76  operator*() const { return ptr_.isAvailable() ? ptr_.operator*() : backPtr_.operator*();}
77 
79  T const*
80  operator->() const{ return ptr_.isAvailable() ? ptr_.operator->() : backPtr_.operator->();}
81 
83  T const* get() const { return ptr_.isAvailable() ? ptr_.get() : backPtr_.get();}
84 
85 
87  bool isNull() const {return !isNonnull(); }
88 
90  //bool isNonnull() const {return id().isValid(); }
91  bool isNonnull() const {return ptr_.isNonnull() || backPtr_.isNonnull(); }
93  bool operator!() const {return isNull();}
94 
97  bool isAvailable() const {return ptr_.isAvailable() || backPtr_.isAvailable();}
98 
100  bool isTransient() const {return ptr_.isTransient();}
101 
103  ProductID id() const {return ptr_.isNonnull() ? ptr_.id() : backPtr_.id();}
104 
107  //another thread might cause productGetter() to change its value
108  EDProductGetter const* getter = ptr_.productGetter();
109  if (getter) return getter;
110  else return backPtr_.productGetter();
111  }
112 
113  key_type key() const {return ptr_.isNonnull() ? ptr_.key() : backPtr_.key() ;}
114 
116 
117  RefCore const& refCore() const {return ptr_.isNonnull() ? ptr_.refCore() : backPtr_.refCore() ;}
118  // ---------- member functions ---------------------------
119 
120  void const* product() const {return 0;}
121 
122  Ptr<value_type> const& ptr() const { return ptr_;}
123  Ptr<value_type> const& backPtr() const { return backPtr_;}
124 
125  //Used by ROOT storage
127 
128  private:
131  };
132 
133 
134  template<typename T>
135  inline
136  bool
137  operator==(FwdPtr<T> const& lhs, FwdPtr<T> const& rhs) {
138  return (lhs.ptr() == rhs.ptr() ||
139  lhs.backPtr() == rhs.ptr() ||
140  lhs.ptr() == rhs.backPtr() ||
141  lhs.backPtr() == rhs.backPtr());
142  }
143 
144  template<typename T>
145  inline
146  bool
147  operator!=(FwdPtr<T> const& lhs, FwdPtr<T> const& rhs) {
148  return !(lhs == rhs);
149  }
150 
151  template<typename T>
152  inline
153  bool
154  operator<(FwdPtr<T> const& lhs, FwdPtr<T> const& rhs) {
157  return (lhs.ptr() < rhs.ptr());
158  }
159 
160 }
161 #endif
Ptr< value_type > const & ptr() const
Definition: FwdPtr.h:122
T const & operator*() const
Dereference operator.
Definition: FwdPtr.h:76
key_type key() const
Definition: Ptr.h:186
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:160
assert(m_qm.get())
bool isAvailable() const
Definition: Ptr.h:259
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: Ptr.h:184
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
unsigned long key_type
Definition: FwdPtr.h:46
#define CMS_CLASS_VERSION(_version_)
Definition: classes.h:31
FwdPtr()
Definition: FwdPtr.h:55
Ptr< value_type > const & backPtr() const
Definition: FwdPtr.h:123
bool hasProductCache() const
Definition: FwdPtr.h:115
~FwdPtr()
Destructor.
Definition: FwdPtr.h:72
RefCore const & refCore() const
Definition: FwdPtr.h:117
bool isTransient() const
Checks if this Ptr is transient (i.e. not persistable).
Definition: Ptr.h:178
bool isAvailable() const
Definition: FwdPtr.h:97
bool isNull() const
Checks for null.
Definition: FwdPtr.h:87
bool isNull() const
Checks for null.
Definition: Ptr.h:165
RefCore const & refCore() const
Definition: Ptr.h:190
#define private
Definition: FWEveView.cc:22
double f[11][100]
void const * product() const
Definition: FwdPtr.h:120
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:169
bool isTransient() const
Checks if this FwdPtr is transient (i.e. not persistable).
Definition: FwdPtr.h:100
T value_type
Definition: FwdPtr.h:47
bool operator!() const
Checks for null.
Definition: FwdPtr.h:93
bool hasProductCache() const
Definition: Ptr.h:188
double b
Definition: hdecay.h:120
string const
Definition: compareJSON.py:14
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:181
FwdPtr(const Ptr< C > &f, const Ptr< C > &b)
Definition: FwdPtr.h:51
ProductID id() const
Accessor for product ID.
Definition: FwdPtr.h:103
Ptr< value_type > ptr_
Definition: FwdPtr.h:129
long double T
bool isNonnull() const
Checks for non-null.
Definition: FwdPtr.h:91
friend class FwdPtrVectorBase
Definition: FwdPtr.h:43
T const * operator->() const
Member dereference operator.
Definition: FwdPtr.h:80
key_type key() const
Definition: FwdPtr.h:113
def template
Definition: svgfig.py:520
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: FwdPtr.h:106
Ptr< value_type > backPtr_
Definition: FwdPtr.h:130