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  if (ptr_.productGetter()) return ptr_.productGetter();
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 0;}
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:
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:76
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:121
bool hasProductCache() const
Definition: FwdPtr.h:113
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:152
~FwdPtr()
Destructor.
Definition: FwdPtr.h:72
RefCore const & refCore() const
Definition: FwdPtr.h:115
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:143
bool isAvailable() const
Definition: FwdPtr.h:97
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:164
bool isNull() const
Checks for null.
Definition: FwdPtr.h:87
double f[11][100]
RefCore const & refCore() const
Definition: Ptr.h:173
void const * product() const
Definition: FwdPtr.h:118
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
key_type key() const
Definition: Ptr.h:169
double b
Definition: hdecay.h:120
string const
Definition: compareJSON.py:14
FwdPtr(const Ptr< C > &f, const Ptr< C > &b)
Definition: FwdPtr.h:51
#define private
Definition: FWFileEntry.h:17
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:103
bool isNull() const
Checks for null.
Definition: Ptr.h:148
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:127
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:111
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:128