CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  if ( ref_.productGetter() ) return ref_.productGetter();
181  else return backRef_.productGetter();
182  }
183 
185  // Accessor must get the product if necessary
186  C const* product() const;
187 
189  ProductID id() const {return ref_.isNonnull() ? ref_.id() : backRef_.id();}
190 
191 
193  key_type key() const {return ref_.isNonnull() ? ref_.key() : backRef_.key() ;}
194 
195  bool hasProductCache() const {return ref_.hasProductCache() || backRef_.hasProductCache();}
196 
199  bool isAvailable() const {return ref_.isAvailable() || backRef_.isAvailable();}
200 
202  bool isTransient() const {return ref_.isTransient();}
203 
204  //Used by ROOT storage
206 
207  private:
209  Ref<C,T,F> backRef_;
210  };
211 }
212 
213 #include "DataFormats/Common/interface/RefProd.h"
214 
215 namespace edm {
216 
217 
219  // Accessor must get the product if necessary
220  template <typename C, typename T, typename F>
221  inline
222  C const*
224  return ref_.isNonnull() && ref_.isAvailable() ?
225  ref_.product() :
226  backRef_.product();
227  }
228 
230  template <typename C, typename T, typename F>
231  inline
232  T const&
234  return ref_.isNonnull() && ref_.isAvailable() ?
235  ref_.operator*() :
236  backRef_.operator*();
237  }
238 
240  template <typename C, typename T, typename F>
241  inline
242  T const*
244  return ref_.isNonnull() && ref_.isAvailable() ?
245  ref_.operator->() :
246  backRef_.operator->();
247  }
248 
249 
252  template <typename C, typename T, typename F>
253  inline
254  bool
255  operator==(FwdRef<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
256  return
257  (lhs.ref() == rhs.ref() ) &&
258  (lhs.backRef() == rhs.backRef() )
259  ;
260  }
261 
264  template <typename C, typename T, typename F>
265  inline
266  bool
267  operator==(Ref<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
268  return
269  (lhs == rhs.ref() ) ||
270  (lhs == rhs.backRef() )
271  ;
272  }
273 
276  template <typename C, typename T, typename F>
277  inline
278  bool
279  operator==(FwdRef<C, T, F> const& lhs, Ref<C, T, F> const& rhs) {
280  return
281  (lhs.ref() == rhs ) ||
282  (lhs.backRef() == rhs )
283  ;
284  }
285 
286 
287 
288  template <typename C, typename T, typename F>
289  inline
290  bool
291  operator!=(FwdRef<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
292  return !(lhs == rhs);
293  }
294 
295  template <typename C, typename T, typename F>
296  inline
297  bool
298  operator!=(Ref<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
299  return !(lhs == rhs);
300  }
301 
302  template <typename C, typename T, typename F>
303  inline
304  bool
305  operator!=(FwdRef<C, T, F> const& lhs, Ref<C, T, F> const& rhs) {
306  return !(lhs == rhs);
307  }
308 
311  template <typename C, typename T, typename F>
312  inline
313  bool
314  operator<(FwdRef<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
315  return (lhs.ref() < rhs.ref() );
316  }
317 
318  template <typename C, typename T, typename F>
319  inline
320  bool
321  operator<(Ref<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
322  return (lhs < rhs.ref() );
323  }
324 
325  template <typename C, typename T, typename F>
326  inline
327  bool
328  operator<(FwdRef<C, T, F> const& lhs, Ref<C, T, F> const& rhs) {
329  return (lhs.ref() < rhs );
330  }
331 
332 }
333 
334 
335 #endif
type
Definition: HCALResponse.h:21
C product_type
for export
Definition: FwdRef.h:128
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
#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 isNull() const
Checks for null.
Definition: Ref.h:247
bool operator==(debugging_allocator< X > const &, debugging_allocator< Y > const &)
key_type key() const
Accessor for product key.
Definition: FwdRef.h:193
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:243
~FwdRef()
Destructor.
Definition: FwdRef.h:146
bool hasProductCache() const
Definition: FwdRef.h:195
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:209
Ref< C, T, F > ref_
Definition: FwdRef.h:208
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
#define private
Definition: FWFileEntry.h:17
bool isTransient() const
Checks if this ref is transient (i.e. not persistable).
Definition: FwdRef.h:202
Ref< C, T, F > const & backRef() const
Definition: FwdRef.h:176
Ref< C, T, F > const & ref() const
Definition: FwdRef.h:175
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
long double T
F finder_type
Definition: FwdRef.h:131
C const * product() const
Accessor for product collection.
Definition: FwdRef.h:223
boost::remove_cv< typename boost::remove_reference< argument_type >::type >::type key_type
Definition: FwdRef.h:133
bool isAvailable() const
Definition: FwdRef.h:199
boost::binary_traits< F >::second_argument_type argument_type
Definition: FwdRef.h:132
ProductID id() const
Accessor for product ID.
Definition: FwdRef.h:189
T const & operator*() const
Dereference operator.
Definition: FwdRef.h:233