CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 EDProduct 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  product_(), id_(ProductID()) {
32  }
33 
34  OrphanHandleBase(void const* iProd, ProductID const& iId) :
35  product_(iProd), id_(iId) {
36  assert(iProd);
37  }
38 
40 
41  void clear() {
42  product_ = 0;
43  id_ = ProductID();
44  }
45 
46  void swap(OrphanHandleBase& other) {
47  using std::swap;
48  swap(product_, other.product_);
49  std::swap(id_, other.id_);
50  }
51 
54  this->swap(temp);
55  return *this;
56  }
57 
58  bool isValid() const {
59  return product_ && id_ != ProductID();
60  }
61 
62  ProductID id() const;
63 
64  protected:
65  void const* productStorage() const;
66 
67  private:
68  void const* product_;
70  };
71 
72  // Free swap function
73  inline
74  void
76  a.swap(b);
77  }
78 }
79 
80 #endif
OrphanHandleBase & operator=(OrphanHandleBase const &rhs)
void swap(OrphanHandleBase &other)
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:117
ProductID id() const
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
OrphanHandleBase(void const *iProd, ProductID const &iId)
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
void const * productStorage() const