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 {
28  class EDProduct;
29 
31  public:
33  product_(), id_(ProductID()) {
34  }
35 
36  OrphanHandleBase (void const* prod, ProductID const& id) :
37  product_(prod), id_(id) {
38  assert (prod);
39  }
40 
42 
43  void clear() {
44  product_ = 0;
45  id_ = ProductID();
46  }
47 
48  void swap(OrphanHandleBase& other) {
49  using std::swap;
50  swap(product_, other.product_);
51  std::swap(id_, other.id_);
52  }
53 
56  this->swap(temp);
57  return *this;
58  }
59 
60  bool isValid() const {
61  return product_ && id_ != ProductID();
62  }
63 
64  ProductID id() const;
65 
66  protected:
67  void const* productStorage() const;
68 
69  private:
70  void const* product_;
72  };
73 
74  // Free swap function
75  inline
76  void
78  a.swap(b);
79  }
80 }
81 
82 #endif
OrphanHandleBase & operator=(OrphanHandleBase const &rhs)
void swap(OrphanHandleBase &other)
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:112
ProductID id() const
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
tuple prod
Definition: CrabTask.py:87
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
OrphanHandleBase(void const *prod, ProductID const &id)
void const * productStorage() const