LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
RefCore.h
Go to the documentation of this file.
1 #ifndef canvas_Persistency_Common_RefCore_h
2 #define canvas_Persistency_Common_RefCore_h
3 
4 // ======================================================================
5 //
6 // RefCore: The component of art::Ptr containing
7 // - the product ID and
8 // - the product getter.
9 //
10 // ======================================================================
11 
14 
15 #include <algorithm>
16 
17 namespace art {
18  class EDProduct;
19  class RefCore;
20 
21  bool operator==(RefCore const&, RefCore const&);
22  bool operator!=(RefCore const&, RefCore const&);
23  bool operator<(RefCore const&, RefCore const&);
24 
26 }
27 
28 class art::RefCore {
29 public:
30  RefCore() = default;
31  RefCore(ProductID const theId,
32  void const* prodPtr,
33  EDProductGetter const* prodGetter);
34 
35  // Observers.
36  bool isNonnull() const;
37  bool isNull() const;
38  bool operator!() const;
39 
40  // Checks if collection is in memory or available
41  // in the Event; no type checking is done.
42  bool isAvailable() const;
43 
44  ProductID id() const;
45  void const* productPtr() const;
46  EDProductGetter const* productGetter() const;
47 
48  // Modifiers.
49  void setProductPtr(void const* prodPtr) const;
50  void setProductGetter(EDProductGetter const* prodGetter) const;
51  void swap(RefCore& other);
52 
54  // itemPtr_ is the address of the item for which the Ptr in which
55  // this RefCoreTransients object resides is a pointer.
56  mutable void const* itemPtr_{nullptr}; // transient
57  mutable EDProductGetter const* prodGetter_{nullptr}; // transient
58 
59  RefCoreTransients() = default;
60  explicit RefCoreTransients(void const* prodPtr,
61  EDProductGetter const* prodGetter);
62  }; // RefCoreTransients
63 
64 private:
67 };
68 
70  void const* prodPtr,
71  EDProductGetter const* prodGetter)
72  : id_{id}, transients_{prodPtr, prodGetter}
73 {}
74 
75 inline bool
77 {
78  return id_.isValid();
79 }
80 
81 inline bool
83 {
84  return !isNonnull();
85 }
86 
87 inline bool art::RefCore::operator!() const
88 {
89  return isNull();
90 }
91 
92 inline auto
94 {
95  return id_;
96 }
97 
98 inline void const*
100 {
101  return transients_.itemPtr_;
102 }
103 
104 inline auto
106 {
107  return transients_.prodGetter_;
108 }
109 
110 inline void
111 art::RefCore::setProductPtr(void const* prodPtr) const
112 {
113  transients_.itemPtr_ = prodPtr;
114 }
115 
116 inline void
118 {
119  transients_.prodGetter_ = prodGetter;
120 }
121 
122 inline void
124 {
125  using std::swap;
126  swap(id_, other.id_);
127  swap(transients_, other.transients_);
128 }
129 
131  void const* prodPtr,
132  EDProductGetter const* prodGetter)
133  : itemPtr_{prodPtr}, prodGetter_{prodGetter}
134 {}
135 
136 inline bool
137 art::operator==(RefCore const& lhs, RefCore const& rhs)
138 {
139  return lhs.id() == rhs.id();
140 }
141 
142 inline bool
143 art::operator!=(RefCore const& lhs, RefCore const& rhs)
144 {
145  return !(lhs == rhs);
146 }
147 
148 inline bool
149 art::operator<(RefCore const& lhs, RefCore const& rhs)
150 {
151  return lhs.id() < rhs.id();
152 }
153 
154 inline void
156 {
157  lhs.swap(rhs);
158 }
159 
160 #endif /* canvas_Persistency_Common_RefCore_h */
161 
162 // Local Variables:
163 // mode: c++
164 // End:
bool operator!() const
Definition: RefCore.h:87
bool isAvailable() const
Definition: RefCore.cc:15
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
RefCore()=default
void swap(art::RefCore &, art::RefCore &)
Definition: RefCore.h:155
bool operator<(ProductInfo const &a, ProductInfo const &b)
Definition: ProductInfo.h:44
EDProductGetter const * productGetter() const
Definition: RefCore.h:105
bool isValid() const
Definition: ProductID.h:33
void swap(Handle< T > &a, Handle< T > &b)
void swap(RefCore &other)
Definition: RefCore.h:123
RefCoreTransients transients_
Definition: RefCore.h:66
bool isNonnull() const
Definition: RefCore.h:76
ProductID id_
Definition: RefCore.h:65
void setProductGetter(EDProductGetter const *prodGetter) const
Definition: RefCore.h:117
void const * productPtr() const
Definition: RefCore.h:99
ProductID id() const
Definition: RefCore.h:93
bool isNull() const
Definition: RefCore.h:82
HLT enums.
EDProductGetter const * prodGetter_
Definition: RefCore.h:57
bool operator==(Provenance const &a, Provenance const &b)
Definition: Provenance.h:168
void setProductPtr(void const *prodPtr) const
Definition: RefCore.h:111