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
edm::OrphanHandleBase::id_
ProductID id_
Definition: OrphanHandleBase.h:62
edm::OrphanHandleBase::productStorage
void const * productStorage() const
Definition: OrphanHandleBase.cc:4
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::swap
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:117
edm::OrphanHandleBase::swap
void swap(OrphanHandleBase &other)
Definition: OrphanHandleBase.h:41
cms::cuda::assert
assert(be >=bs)
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::OrphanHandleBase::clear
void clear()
Definition: OrphanHandleBase.h:36
edm::OrphanHandleBase::OrphanHandleBase
OrphanHandleBase(void const *iProd, ProductID const &iId)
Definition: OrphanHandleBase.h:32
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
ProductID.h
trackingPlots.other
other
Definition: trackingPlots.py:1465
b
double b
Definition: hdecay.h:118
a
double a
Definition: hdecay.h:119
edm::OrphanHandleBase::isValid
bool isValid() const
Definition: OrphanHandleBase.h:53
edm::OrphanHandleBase::~OrphanHandleBase
~OrphanHandleBase()
Definition: OrphanHandleBase.h:34
edm::OrphanHandleBase::id
ProductID id() const
Definition: OrphanHandleBase.cc:6
edm::OrphanHandleBase::product_
void const * product_
Definition: OrphanHandleBase.h:61
edm::OrphanHandleBase::OrphanHandleBase
OrphanHandleBase()
Definition: OrphanHandleBase.h:30
edm::OrphanHandleBase
Definition: OrphanHandleBase.h:28
edm::OrphanHandleBase::operator=
OrphanHandleBase & operator=(OrphanHandleBase const &rhs)
Definition: OrphanHandleBase.h:47
edm::ProductID
Definition: ProductID.h:27