CMS 3D CMS Logo

FwdRef.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_FwdRef_h
2 #define DataFormats_Common_FwdRef_h
3 
4 /*----------------------------------------------------------------------
5 
6 FwdRef: A template for a interproduct reference to a member of a product.
7 
8 ----------------------------------------------------------------------*/
84 /*----------------------------------------------------------------------
85 // This defines the public interface to the class FwdRef<C, T, F>.
86 // C is the collection type.
87 // T (default C::value_type) is the type of an element in the collection.
88 //
89 // ProductID productID is the product ID of the collection.
90 // key_type itemKey is the key of the element in the collection.
91 // C::value_type *itemPtr is a C++ pointer to the element
92 // FwdRef<C, T, F> const& ref is another FwdRef<C, T, F>
93 
94 // Constructors
95  FwdRef(); // Default constructor
96  FwdRef(FwdRef<C, T> const& ref); // Copy constructor (default, not explicitly specified)
97 
98  FwdRef(Ref<C,T,F> const & fwdRef, Ref<C,T,F> const & backRef);
99 
100 // Destructor
101  virtual ~FwdRef() {}
102 
103  // Operators and methods
104  FwdRef<C, T>& operator=(FwdRef<C, T> const&); // assignment (default, not explicitly specified)
105  T const& operator*() const; // dereference
106  T const* const operator->() const; // member dereference
107  bool operator==(FwdRef<C, T> const& ref) const; // equality
108  bool operator!=(FwdRef<C, T> const& ref) const; // inequality
109  bool operator<(FwdRef<C, T> const& ref) const; // ordering
110  bool isNonnull() const; // true if an object is referenced
111  bool isNull() const; // equivalent to !isNonnull()
112  bool operator!() const; // equivalent to !isNonnull()
113  ----------------------------------------------------------------------*/
114 
117 
118 namespace edm {
119 
120  template <typename C,
121  typename T = typename refhelper::ValueTrait<C>::value,
122  typename F = typename refhelper::FindTrait<C, T>::value>
123  class FwdRef {
124 
125 
126  public:
128  typedef C product_type;
129  typedef T value_type;
130  typedef T const element_type; //used for generic programming
131  typedef F finder_type;
132  typedef typename boost::binary_traits<F>::second_argument_type argument_type;
136 
138  FwdRef() : ref_(), backRef_() {}
139 
142  Ref<C,T,F> const & backRef) :
143  ref_(ref), backRef_(backRef) { assert(ref.isNull() == backRef.isNull()); }
144 
146  ~FwdRef() {}
147 
149  T const&
150  operator*() const;
151 
153  T const*
154  operator->() const;
155 
157  T const* get() const {
158  if ( ref_.isAvailable() ) {
159  return ref_.get();
160  } else {
161  return backRef_.get();
162  }
163  }
164 
166  bool isNull() const {return !isNonnull(); }
167 
169  //bool isNonnull() const {return id().isValid(); }
170  bool isNonnull() const { return ref_.isNonnull() || backRef_.isNonnull(); }
171 
173  bool operator!() const {return isNull();}
174 
175  Ref<C,T,F> const & ref() const { return ref_; }
176  Ref<C,T,F> const & backRef() const { return backRef_; }
177 
180  //another thread might cause productGetter() to change its value
181  EDProductGetter const* getter = ref_.productGetter();
182  if ( getter ) return getter;
183  else return backRef_.productGetter();
184  }
185 
187  ProductID id() const {return ref_.isNonnull() ? ref_.id() : backRef_.id();}
188 
189 
191  key_type key() const {return ref_.isNonnull() ? ref_.key() : backRef_.key() ;}
192 
193  bool hasProductCache() const {return ref_.hasProductCache() || backRef_.hasProductCache();}
194 
197  bool isAvailable() const {return ref_.isAvailable() || backRef_.isAvailable();}
198 
200  bool isTransient() const {return ref_.isTransient();}
201 
202  //Used by ROOT storage
204 
205  private:
206  Ref<C,T,F> ref_;
207  Ref<C,T,F> backRef_;
208  };
209 }
210 
211 #include "DataFormats/Common/interface/RefProd.h"
212 
213 namespace edm {
214 
216  template <typename C, typename T, typename F>
217  inline
218  T const&
220  return ref_.isNonnull() && ref_.isAvailable() ?
221  ref_.operator*() :
222  backRef_.operator*();
223  }
224 
226  template <typename C, typename T, typename F>
227  inline
228  T const*
230  return ref_.isNonnull() && ref_.isAvailable() ?
231  ref_.operator->() :
232  backRef_.operator->();
233  }
234 
235 
238  template <typename C, typename T, typename F>
239  inline
240  bool
241  operator==(FwdRef<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
242  return
243  (lhs.ref() == rhs.ref() ) &&
244  (lhs.backRef() == rhs.backRef() )
245  ;
246  }
247 
250  template <typename C, typename T, typename F>
251  inline
252  bool
253  operator==(Ref<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
254  return
255  (lhs == rhs.ref() ) ||
256  (lhs == rhs.backRef() )
257  ;
258  }
259 
262  template <typename C, typename T, typename F>
263  inline
264  bool
265  operator==(FwdRef<C, T, F> const& lhs, Ref<C, T, F> const& rhs) {
266  return
267  (lhs.ref() == rhs ) ||
268  (lhs.backRef() == rhs )
269  ;
270  }
271 
272 
273 
274  template <typename C, typename T, typename F>
275  inline
276  bool
277  operator!=(FwdRef<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
278  return !(lhs == rhs);
279  }
280 
281  template <typename C, typename T, typename F>
282  inline
283  bool
284  operator!=(Ref<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
285  return !(lhs == rhs);
286  }
287 
288  template <typename C, typename T, typename F>
289  inline
290  bool
291  operator!=(FwdRef<C, T, F> const& lhs, Ref<C, T, F> const& rhs) {
292  return !(lhs == rhs);
293  }
294 
297  template <typename C, typename T, typename F>
298  inline
299  bool
300  operator<(FwdRef<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
301  return (lhs.ref() < rhs.ref() );
302  }
303 
304  template <typename C, typename T, typename F>
305  inline
306  bool
307  operator<(Ref<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
308  return (lhs < rhs.ref() );
309  }
310 
311  template <typename C, typename T, typename F>
312  inline
313  bool
314  operator<(FwdRef<C, T, F> const& lhs, Ref<C, T, F> const& rhs) {
315  return (lhs.ref() < rhs );
316  }
317 
318 }
319 
320 
321 #endif
type
Definition: HCALResponse.h:21
C product_type
for export
Definition: FwdRef.h:128
#define CMS_CLASS_VERSION(_version_)
Definition: classes.h:31
bool operator!() const
Checks for null.
Definition: FwdRef.h:173
T const element_type
Definition: FwdRef.h:130
bool operator==(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
key_type key() const
Accessor for product key.
Definition: FwdRef.h:191
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: FwdRef.h:179
bool isNull() const
Checks for null.
Definition: FwdRef.h:166
T const * operator->() const
Member dereference operator.
Definition: FwdRef.h:229
~FwdRef()
Destructor.
Definition: FwdRef.h:146
bool hasProductCache() const
Definition: FwdRef.h:193
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
bool isNull() const
Checks for null.
Definition: Ref.h:250
bool isNonnull() const
Checks for non-null.
Definition: FwdRef.h:170
FwdRef()
Default constructor needed for reading from persistent store. Not for direct use. ...
Definition: FwdRef.h:138
T value_type
Definition: FwdRef.h:129
Ref< C, T, F > backRef_
Definition: FwdRef.h:207
Ref< C, T, F > ref_
Definition: FwdRef.h:206
FwdRef(Ref< C, T, F > const &ref, Ref< C, T, F > const &backRef)
General purpose constructor from 2 refs (forward and backward.
Definition: FwdRef.h:141
bool isTransient() const
Checks if this ref is transient (i.e. not persistable).
Definition: FwdRef.h:200
Ref< C, T, F > const & backRef() const
Definition: FwdRef.h:176
HLT enums.
Ref< C, T, F > const & ref() const
Definition: FwdRef.h:175
FindUsingAdvance< C, T > value
Definition: RefTraits.h:41
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
long double T
F finder_type
Definition: FwdRef.h:131
boost::remove_cv< typename boost::remove_reference< argument_type >::type >::type key_type
Definition: FwdRef.h:133
bool isAvailable() const
Definition: FwdRef.h:197
boost::binary_traits< F >::second_argument_type argument_type
Definition: FwdRef.h:132
ProductID id() const
Accessor for product ID.
Definition: FwdRef.h:187
T const & operator*() const
Dereference operator.
Definition: FwdRef.h:219