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