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 // system include files
22 #include "boost/type_traits/is_base_of.hpp"
23 #include "boost/utility/enable_if.hpp"
24 
25 // user include files
36 
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>
52  ptr_(f), backPtr_(b)
53  {}
54 
55  FwdPtr():
56  ptr_(), backPtr_()
57  {}
58 
59  FwdPtr(FwdPtr<T> const& iOther):
60  ptr_(iOther.ptr_), backPtr_(iOther.backPtr_)
61  {}
62 
63  /* template<typename U> */
64  /* FwdPtr(FwdPtr<U> const& iOther, typename boost::enable_if_c<boost::is_base_of<T, U>::value>::type * t = 0): */
65  /* ptr_(iOther.ptr_, t), backPtr_(iOther.backPtr_,t) */
66  /* { */
67  /* } */
68 
69  /* template<typename U> */
70  /* explicit */
71  /* FwdPtr(FwdPtr<U> const& iOther, typename boost::enable_if_c<boost::is_base_of<U, T>::value>::type * t = 0): */
72  /* ptr_(iOther.ptr_,t), backPtr_(iOther.backPtr_,t){} */
73 
74 
76  ~FwdPtr() {}
77 
79  T const&
80  operator*() const { return ptr_.isNonnull() ? ptr_.operator*() : backPtr_.operator*();}
81 
83  T const*
84  operator->() const{ return ptr_.isNonnull() ? ptr_.operator->() : backPtr_.operator->();}
85 
87  T const* get() const { return ptr_.isNonnull() ? ptr_.get() : backPtr_.get();}
88 
89 
91  bool isNull() const {return !isNonnull(); }
92 
94  //bool isNonnull() const {return id().isValid(); }
95  bool isNonnull() const {return ptr_.isNonnull() || backPtr_.isNonnull(); }
97  bool operator!() const {return isNull();}
98 
101  bool isAvailable() const {return ptr_.isAvailable() || backPtr_.isAvailable();}
102 
104  bool isTransient() const {return ptr_.isTransient();}
105 
107  ProductID id() const {return ptr_.isNonnull() ? ptr_.id() : backPtr_.id();}
108 
111  if ( ptr_.productGetter() ) return ptr_.productGetter();
112  else return backPtr_.productGetter();
113  }
114 
115  key_type key() const {return ptr_.isNonnull() ? ptr_.key() : backPtr_.key() ;}
116 
118 
119  RefCore const& refCore() const {return ptr_.isNonnull() ? ptr_.refCore() : backPtr_.refCore() ;}
120  // ---------- member functions ---------------------------
121 
122  void const* product() const {return 0;}
123 
124  Ptr<value_type> const & ptr() const { return ptr_;}
125  Ptr<value_type> const & backPtr() const { return backPtr_;}
126 
127  //Used by ROOT storage
129 
130  private:
133  };
134 
135 
136  template <typename T>
137  inline
138  bool
139  operator==(FwdPtr<T> const& lhs, FwdPtr<T> const& rhs) {
140  return ( lhs.ptr() == rhs.ptr() ||
141  lhs.backPtr() == rhs.ptr() ||
142  lhs.ptr() == rhs.backPtr() ||
143  lhs.backPtr() == rhs.backPtr() );
144  }
145 
146  template <typename T>
147  inline
148  bool
149  operator!=(FwdPtr<T> const& lhs, FwdPtr<T> const& rhs) {
150  return !(lhs == rhs);
151  }
152 
153  template <typename T>
154  inline
155  bool
156  operator<(FwdPtr<T> const& lhs, FwdPtr<T> const& rhs) {
159  return ( lhs.ptr() < rhs.ptr() );
160  }
161 
162 }
163 
164 #endif
Ptr< value_type > const & ptr() const
Definition: FwdPtr.h:124
T const & operator*() const
Dereference operator.
Definition: FwdPtr.h:80
FwdPtr(Ptr< C > f, Ptr< C > b)
Definition: FwdPtr.h:51
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
unsigned long key_type
Definition: FwdPtr.h:46
#define CMS_CLASS_VERSION(_version_)
FwdPtr()
Definition: FwdPtr.h:55
Ptr< value_type > const & backPtr() const
Definition: FwdPtr.h:125
bool hasProductCache() const
Definition: FwdPtr.h:117
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:157
~FwdPtr()
Destructor.
Definition: FwdPtr.h:76
RefCore const & refCore() const
Definition: FwdPtr.h:119
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:148
bool isAvailable() const
Definition: FwdPtr.h:101
FwdPtr(FwdPtr< T > const &iOther)
Definition: FwdPtr.h:59
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:169
bool isNull() const
Checks for null.
Definition: FwdPtr.h:91
double f[11][100]
RefCore const & refCore() const
Definition: Ptr.h:178
void const * product() const
Definition: FwdPtr.h:122
bool isTransient() const
Checks if this FwdPtr is transient (i.e. not persistable).
Definition: FwdPtr.h:104
T value_type
Definition: FwdPtr.h:47
bool operator!() const
Checks for null.
Definition: FwdPtr.h:97
key_type key() const
Definition: Ptr.h:174
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:166
ProductID id() const
Accessor for product ID.
Definition: FwdPtr.h:107
bool hasProductCache() const
Definition: Ptr.h:176
bool isAvailable() const
Definition: Ptr.h:163
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: Ptr.h:172
Ptr< value_type > ptr_
Definition: FwdPtr.h:131
long double T
bool isNonnull() const
Checks for non-null.
Definition: FwdPtr.h:95
friend class FwdPtrVectorBase
Definition: FwdPtr.h:43
T const * operator->() const
Member dereference operator.
Definition: FwdPtr.h:84
key_type key() const
Definition: FwdPtr.h:115
def template
Definition: svgfig.py:520
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: FwdPtr.h:110
Ptr< value_type > backPtr_
Definition: FwdPtr.h:132