PtrVectorBase.h
Go to the documentation of this file.
1 #ifndef canvas_Persistency_Common_PtrVectorBase_h
2 #define canvas_Persistency_Common_PtrVectorBase_h
3 
8 
9 #include <vector>
10 
11 namespace art {
12  class PtrVectorBase;
13 
14  namespace detail {
15  class PtrVectorBaseStreamer;
16  }
17 }
18 
20 public:
21  using key_type = unsigned long;
22  using indices_t = std::vector<key_type>;
23  using size_type = indices_t::size_type;
24 
25  virtual ~PtrVectorBase() = default;
26 
27  // Observers
28  bool isNonnull() const noexcept;
29  bool isNull() const noexcept;
30  bool isAvailable() const;
31  ProductID id() const noexcept;
32  EDProductGetter const* productGetter() const noexcept;
33 
34  // Mutators
35  void setProductGetter(EDProductGetter const*) noexcept;
36 
37 protected:
39 
40  void clear();
41  void swap(PtrVectorBase&);
42  void updateCore(RefCore const& core);
43  bool operator==(PtrVectorBase const&) const noexcept;
44 
45 private:
46  void reserve(size_type n);
47  void fillPtrs() const;
48  template <typename T>
49  typename Ptr<T>::key_type key(Ptr<T> const& ptr) const noexcept;
50 
51  RefCore core_;
52  mutable indices_t indicies_; // Will be zeroed-out by fillPtrs();
53 
54  virtual void fill_offsets(indices_t& indices) = 0;
55  virtual void fill_from_offsets(indices_t const& indices) const = 0;
56  virtual void zeroTransients() = 0;
57 
58  friend class art::detail::PtrVectorBaseStreamer;
59 }; // PtrVectorBase
60 
61 inline bool
62 art::PtrVectorBase::isNonnull() const noexcept
63 {
64  return core_.isNonnull();
65 }
66 
67 inline bool
69 {
70  return !isNonnull();
71 }
72 
73 inline bool
75 {
76  return core_.isAvailable();
77 }
78 
79 inline art::ProductID
81 {
82  return core_.id();
83 }
84 
85 inline art::EDProductGetter const*
87 {
88  return core_.productGetter();
89 }
90 
91 inline void
93 {
94  core_.setProductGetter(g);
95 }
96 
97 inline void
99 {
100  core_ = RefCore{};
101  indices_t tmp;
102  indicies_.swap(tmp); // Free up memory
103 }
104 
105 inline void
107 {
108  indicies_.reserve(n);
109 }
110 
111 inline void
113 {
114  core_.swap(other.core_);
115 }
116 
117 template <typename T>
118 inline typename art::Ptr<T>::key_type
119 art::PtrVectorBase::key(Ptr<T> const& ptr) const noexcept
120 {
121  return ptr.key();
122 }
123 
124 inline bool
126 {
127  return core_ == other.core_;
128 }
129 
130 #endif /* canvas_Persistency_Common_PtrVectorBase_h */
131 
132 // Local Variables:
133 // mode: c++
134 // End:
void swap(PtrVectorBase &)
static constexpr double g
Definition: Units.h:144
ProductID id() const noexcept
Definition: PtrVectorBase.h:80
bool isNull() const noexcept
Definition: PtrVectorBase.h:68
unsigned long key_type
Definition: PtrVectorBase.h:21
bool operator==(PtrVectorBase const &) const noexcept
std::size_t key_type
Definition: Ptr.h:79
bool isAvailable() const
Definition: PtrVectorBase.h:74
std::vector< key_type > indices_t
Definition: PtrVectorBase.h:22
void swap(Handle< T > &a, Handle< T > &b)
def key(type, name=None)
Definition: graph.py:13
void setProductGetter(EDProductGetter const *) noexcept
Definition: PtrVectorBase.h:92
std::void_t< T > n
constexpr std::array< std::size_t, geo::vect::dimension< Vector >)> indices()
Returns a sequence of indices valid for a vector of the specified type.
string tmp
Definition: languages.py:63
EDProductGetter const * productGetter() const noexcept
Definition: PtrVectorBase.h:86
void reserve(size_type n)
Ptr< T >::key_type key(Ptr< T > const &ptr) const noexcept
vector< vector< double > > clear
constexpr bool isNonnull() const noexcept
Definition: RefCore.h:28
indices_t::size_type size_type
Definition: PtrVectorBase.h:23
Definition: fwd.h:31