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 ----------------------------------------------------------------------*/
82 /*----------------------------------------------------------------------
83 // This defines the public interface to the class FwdRef<C, T, F>.
84 // C is the collection type.
85 // T (default C::value_type) is the type of an element in the collection.
86 //
87 // ProductID productID is the product ID of the collection.
88 // key_type itemKey is the key of the element in the collection.
89 // C::value_type *itemPtr is a C++ pointer to the element
90 // FwdRef<C, T, F> const& ref is another FwdRef<C, T, F>
91 
92 // Constructors
93  FwdRef(); // Default constructor
94  FwdRef(FwdRef<C, T> const& ref); // Copy constructor (default, not explicitly specified)
95 
96  FwdRef(Ref<C,T,F> const & fwdRef, Ref<C,T,F> const & backRef);
97 
98 // Destructor
99  virtual ~FwdRef() {}
100 
101  // Operators and methods
102  FwdRef<C, T>& operator=(FwdRef<C, T> const&); // assignment (default, not explicitly specified)
103  T const& operator*() const; // dereference
104  T const* const operator->() const; // member dereference
105  bool operator==(FwdRef<C, T> const& ref) const; // equality
106  bool operator!=(FwdRef<C, T> const& ref) const; // inequality
107  bool operator<(FwdRef<C, T> const& ref) const; // ordering
108  bool isNonnull() const; // true if an object is referenced
109  bool isNull() const; // equivalent to !isNonnull()
110  bool operator!() const; // equivalent to !isNonnull()
111  ----------------------------------------------------------------------*/
112 
115 
116 namespace edm {
117 
118  template <typename C,
119  typename T = typename refhelper::ValueTrait<C>::value,
120  typename F = typename refhelper::FindTrait<C, T>::value>
121  class FwdRef {
122 
123 
124  public:
126  typedef C product_type;
127  typedef T value_type;
128  typedef T const element_type; //used for generic programming
129  typedef F finder_type;
130  typedef typename boost::binary_traits<F>::second_argument_type argument_type;
134 
136  FwdRef() : ref_(), backRef_() {}
137 
140  Ref<C,T,F> const & backRef) :
141  ref_(ref), backRef_(backRef) { assert(ref.isNull() == backRef.isNull()); }
142 
144  ~FwdRef() {}
145 
147  T const&
148  operator*() const;
149 
151  T const*
152  operator->() const;
153 
155  T const* get() const {
156  if ( ref_.isAvailable() ) {
157  return ref_.get();
158  } else {
159  return backRef_.get();
160  }
161  }
162 
164  bool isNull() const {return !isNonnull(); }
165 
167  //bool isNonnull() const {return id().isValid(); }
168  bool isNonnull() const { return ref_.isNonnull() || backRef_.isNonnull(); }
169 
171  bool operator!() const {return isNull();}
172 
173  Ref<C,T,F> const & ref() const { return ref_; }
174  Ref<C,T,F> const & backRef() const { return backRef_; }
175 
178  //another thread might cause productGetter() to change its value
179  EDProductGetter const* getter = ref_.productGetter();
180  if ( getter ) return getter;
181  else return backRef_.productGetter();
182  }
183 
185  ProductID id() const {return ref_.isNonnull() ? ref_.id() : backRef_.id();}
186 
187 
189  key_type key() const {return ref_.isNonnull() ? ref_.key() : backRef_.key() ;}
190 
191  bool hasProductCache() const {return ref_.hasProductCache() || backRef_.hasProductCache();}
192 
195  bool isAvailable() const {return ref_.isAvailable() || backRef_.isAvailable();}
196 
198  bool isTransient() const {return ref_.isTransient();}
199 
200  //Used by ROOT storage
202 
203  private:
204  Ref<C,T,F> ref_;
205  Ref<C,T,F> backRef_;
206  };
207 }
208 
209 #include "DataFormats/Common/interface/RefProd.h"
210 
211 namespace edm {
212 
214  template <typename C, typename T, typename F>
215  inline
216  T const&
218  return ref_.isNonnull() && ref_.isAvailable() ?
219  ref_.operator*() :
220  backRef_.operator*();
221  }
222 
224  template <typename C, typename T, typename F>
225  inline
226  T const*
228  return ref_.isNonnull() && ref_.isAvailable() ?
229  ref_.operator->() :
230  backRef_.operator->();
231  }
232 
233 
236  template <typename C, typename T, typename F>
237  inline
238  bool
239  operator==(FwdRef<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
240  return
241  (lhs.ref() == rhs.ref() ) &&
242  (lhs.backRef() == rhs.backRef() )
243  ;
244  }
245 
248  template <typename C, typename T, typename F>
249  inline
250  bool
251  operator==(Ref<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
252  return
253  (lhs == rhs.ref() ) ||
254  (lhs == rhs.backRef() )
255  ;
256  }
257 
260  template <typename C, typename T, typename F>
261  inline
262  bool
263  operator==(FwdRef<C, T, F> const& lhs, Ref<C, T, F> const& rhs) {
264  return
265  (lhs.ref() == rhs ) ||
266  (lhs.backRef() == rhs )
267  ;
268  }
269 
270 
271 
272  template <typename C, typename T, typename F>
273  inline
274  bool
275  operator!=(FwdRef<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
276  return !(lhs == rhs);
277  }
278 
279  template <typename C, typename T, typename F>
280  inline
281  bool
282  operator!=(Ref<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
283  return !(lhs == rhs);
284  }
285 
286  template <typename C, typename T, typename F>
287  inline
288  bool
289  operator!=(FwdRef<C, T, F> const& lhs, Ref<C, T, F> const& rhs) {
290  return !(lhs == rhs);
291  }
292 
295  template <typename C, typename T, typename F>
296  inline
297  bool
298  operator<(FwdRef<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
299  return (lhs.ref() < rhs.ref() );
300  }
301 
302  template <typename C, typename T, typename F>
303  inline
304  bool
305  operator<(Ref<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
306  return (lhs < rhs.ref() );
307  }
308 
309  template <typename C, typename T, typename F>
310  inline
311  bool
312  operator<(FwdRef<C, T, F> const& lhs, Ref<C, T, F> const& rhs) {
313  return (lhs.ref() < rhs );
314  }
315 
316 }
317 
318 
319 #endif
type
Definition: HCALResponse.h:21
C product_type
for export
Definition: FwdRef.h:126
#define CMS_CLASS_VERSION(_version_)
bool operator!() const
Checks for null.
Definition: FwdRef.h:171
T const element_type
Definition: FwdRef.h:128
bool operator==(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
key_type key() const
Accessor for product key.
Definition: FwdRef.h:189
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: FwdRef.h:177
bool isNull() const
Checks for null.
Definition: FwdRef.h:164
T const * operator->() const
Member dereference operator.
Definition: FwdRef.h:227
~FwdRef()
Destructor.
Definition: FwdRef.h:144
bool hasProductCache() const
Definition: FwdRef.h:191
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
bool isNull() const
Checks for null.
Definition: Ref.h:248
bool isNonnull() const
Checks for non-null.
Definition: FwdRef.h:168
FwdRef()
Default constructor needed for reading from persistent store. Not for direct use. ...
Definition: FwdRef.h:136
T value_type
Definition: FwdRef.h:127
Ref< C, T, F > backRef_
Definition: FwdRef.h:205
Ref< C, T, F > ref_
Definition: FwdRef.h:204
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:139
bool isTransient() const
Checks if this ref is transient (i.e. not persistable).
Definition: FwdRef.h:198
Ref< C, T, F > const & backRef() const
Definition: FwdRef.h:174
HLT enums.
Ref< C, T, F > const & ref() const
Definition: FwdRef.h:173
FindUsingAdvance< C, T > value
Definition: RefTraits.h:40
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
long double T
F finder_type
Definition: FwdRef.h:129
boost::remove_cv< typename boost::remove_reference< argument_type >::type >::type key_type
Definition: FwdRef.h:131
bool isAvailable() const
Definition: FwdRef.h:195
boost::binary_traits< F >::second_argument_type argument_type
Definition: FwdRef.h:130
ProductID id() const
Accessor for product ID.
Definition: FwdRef.h:185
T const & operator*() const
Dereference operator.
Definition: FwdRef.h:217