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 
38 // forward declarations
39 namespace edm {
40  template<typename T>
41  class FwdPtr {
42  friend class FwdPtrVectorBase;
43  public:
44 
45  typedef unsigned long key_type;
46  typedef T value_type;
47 
48  // General purpose constructor from two Ptrs.
49  template<typename C>
51  ptr_(f), backPtr_(b)
52  {}
53 
54  FwdPtr() :
55  ptr_(), backPtr_()
56  {}
57 
58  /* template<typename U> */
59  /* FwdPtr(FwdPtr<U> const& iOther, typename boost::enable_if_c<boost::is_base_of<T, U>::value>::type * t = 0): */
60  /* ptr_(iOther.ptr_, t), backPtr_(iOther.backPtr_,t) */
61  /* { */
62  /* } */
63 
64  /* template<typename U> */
65  /* explicit */
66  /* FwdPtr(FwdPtr<U> const& iOther, typename boost::enable_if_c<boost::is_base_of<U, T>::value>::type * t = 0): */
67  /* ptr_(iOther.ptr_,t), backPtr_(iOther.backPtr_,t){} */
68 
69 
71  ~FwdPtr() {}
72 
74  T const&
75  operator*() const { return ptr_.isNonnull() ? ptr_.operator*() : backPtr_.operator*();}
76 
78  T const*
79  operator->() const{ return ptr_.isNonnull() ? ptr_.operator->() : backPtr_.operator->();}
80 
82  T const* get() const { return ptr_.isNonnull() ? ptr_.get() : backPtr_.get();}
83 
84 
86  bool isNull() const {return !isNonnull(); }
87 
89  //bool isNonnull() const {return id().isValid(); }
90  bool isNonnull() const {return ptr_.isNonnull() || backPtr_.isNonnull(); }
92  bool operator!() const {return isNull();}
93 
96  bool isAvailable() const {return ptr_.isAvailable() || backPtr_.isAvailable();}
97 
99  bool isTransient() const {return ptr_.isTransient();}
100 
102  ProductID id() const {return ptr_.isNonnull() ? ptr_.id() : backPtr_.id();}
103 
106  if (ptr_.productGetter()) return ptr_.productGetter();
107  else return backPtr_.productGetter();
108  }
109 
110  key_type key() const {return ptr_.isNonnull() ? ptr_.key() : backPtr_.key() ;}
111 
113 
114  RefCore const& refCore() const {return ptr_.isNonnull() ? ptr_.refCore() : backPtr_.refCore() ;}
115  // ---------- member functions ---------------------------
116 
117  void const* product() const {return 0;}
118 
119  Ptr<value_type> const& ptr() const { return ptr_;}
120  Ptr<value_type> const& backPtr() const { return backPtr_;}
121 
122  //Used by ROOT storage
124 
125  private:
128  };
129 
130 
131  template<typename T>
132  inline
133  bool
134  operator==(FwdPtr<T> const& lhs, FwdPtr<T> const& rhs) {
135  return (lhs.ptr() == rhs.ptr() ||
136  lhs.backPtr() == rhs.ptr() ||
137  lhs.ptr() == rhs.backPtr() ||
138  lhs.backPtr() == rhs.backPtr());
139  }
140 
141  template<typename T>
142  inline
143  bool
144  operator!=(FwdPtr<T> const& lhs, FwdPtr<T> const& rhs) {
145  return !(lhs == rhs);
146  }
147 
148  template<typename T>
149  inline
150  bool
151  operator<(FwdPtr<T> const& lhs, FwdPtr<T> const& rhs) {
154  return (lhs.ptr() < rhs.ptr());
155  }
156 
157 }
158 #endif
Ptr< value_type > const & ptr() const
Definition: FwdPtr.h:119
T const & operator*() const
Dereference operator.
Definition: FwdPtr.h:75
FwdPtr(Ptr< C > f, Ptr< C > b)
Definition: FwdPtr.h:50
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
unsigned long key_type
Definition: FwdPtr.h:45
#define CMS_CLASS_VERSION(_version_)
FwdPtr()
Definition: FwdPtr.h:54
Ptr< value_type > const & backPtr() const
Definition: FwdPtr.h:120
bool hasProductCache() const
Definition: FwdPtr.h:112
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:152
~FwdPtr()
Destructor.
Definition: FwdPtr.h:71
RefCore const & refCore() const
Definition: FwdPtr.h:114
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:143
bool isAvailable() const
Definition: FwdPtr.h:96
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:164
bool isNull() const
Checks for null.
Definition: FwdPtr.h:86
double f[11][100]
RefCore const & refCore() const
Definition: Ptr.h:173
void const * product() const
Definition: FwdPtr.h:117
bool isTransient() const
Checks if this FwdPtr is transient (i.e. not persistable).
Definition: FwdPtr.h:99
T value_type
Definition: FwdPtr.h:46
bool operator!() const
Checks for null.
Definition: FwdPtr.h:92
key_type key() const
Definition: Ptr.h:169
double b
Definition: hdecay.h:120
string const
Definition: compareJSON.py:14
#define private
Definition: FWFileEntry.h:18
bool isTransient() const
Checks if this Ptr is transient (i.e. not persistable).
Definition: Ptr.h:161
ProductID id() const
Accessor for product ID.
Definition: FwdPtr.h:102
bool hasProductCache() const
Definition: Ptr.h:171
bool isAvailable() const
Definition: Ptr.h:158
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: Ptr.h:167
Ptr< value_type > ptr_
Definition: FwdPtr.h:126
long double T
bool isNonnull() const
Checks for non-null.
Definition: FwdPtr.h:90
friend class FwdPtrVectorBase
Definition: FwdPtr.h:42
T const * operator->() const
Member dereference operator.
Definition: FwdPtr.h:79
key_type key() const
Definition: FwdPtr.h:110
def template
Definition: svgfig.py:520
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: FwdPtr.h:105
Ptr< value_type > backPtr_
Definition: FwdPtr.h:127