CMS 3D CMS Logo

OrphanHandleBase.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_OrphanHandleBase_h
2 #define DataFormats_Common_OrphanHandleBase_h
3 
4 /*----------------------------------------------------------------------
5 
6 OrphanHandle: Non-owning "smart pointer" for reference to EDProducts.
7 
8 This is a very preliminary version, and lacks safety features and
9 elegance.
10 
11 If the pointed-to WrapperBase is destroyed, use of the OrphanHandle
12 becomes undefined. There is no way to query the OrphanHandle to
13 discover if this has happened.
14 
15 OrphanHandles can have:
16  -- Product pointer null and id == 0;
17  -- Product pointer valid and id != 0;
18 
19 To check validity, one can use the isValid() function.
20 
21 ----------------------------------------------------------------------*/
22 
24 #include <cassert>
25 #include <algorithm>
26 
27 namespace edm {
29  public:
31 
32  OrphanHandleBase(void const* iProd, ProductID const& iId) : product_(iProd), id_(iId) { assert(iProd); }
33 
34  void clear() {
35  product_ = nullptr;
36  id_ = ProductID();
37  }
38 
40  using std::swap;
41  swap(product_, other.product_);
42  std::swap(id_, other.id_);
43  }
44 
45  bool isValid() const { return product_ && id_ != ProductID(); }
46 
47  ProductID id() const;
48 
49  protected:
50  void const* productStorage() const;
51 
52  private:
53  void const* product_;
55  };
56 
57  // Free swap function
58  inline void swap(OrphanHandleBase& a, OrphanHandleBase& b) { a.swap(b); }
59 } // namespace edm
60 
61 #endif
void swap(OrphanHandleBase &other)
assert(be >=bs)
void swap(OrphanHandleBase &a, OrphanHandleBase &b)
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:112
OrphanHandleBase(void const *iProd, ProductID const &iId)
ProductID id() const
double b
Definition: hdecay.h:120
HLT enums.
double a
Definition: hdecay.h:121
void const * productStorage() const