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 
35 
36  void clear() {
37  product_ = nullptr;
38  id_ = ProductID();
39  }
40 
42  using std::swap;
43  swap(product_, other.product_);
44  std::swap(id_, other.id_);
45  }
46 
49  this->swap(temp);
50  return *this;
51  }
52 
53  bool isValid() const { return product_ && id_ != ProductID(); }
54 
55  ProductID id() const;
56 
57  protected:
58  void const* productStorage() const;
59 
60  private:
61  void const* product_;
63  };
64 
65  // Free swap function
66  inline void swap(OrphanHandleBase& a, OrphanHandleBase& b) { a.swap(b); }
67 } // namespace edm
68 
69 #endif
OrphanHandleBase & operator=(OrphanHandleBase const &rhs)
void swap(OrphanHandleBase &other)
ProductID id() const
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
OrphanHandleBase(void const *iProd, ProductID const &iId)
double b
Definition: hdecay.h:118
HLT enums.
double a
Definition: hdecay.h:119
void const * productStorage() const