ATLAS Offline Software
Loading...
Searching...
No Matches
DataVectorWithAlloc.h
Go to the documentation of this file.
1// This file's extension implies that it's C, but it's really -*- C++ -*-.
2/*
3 * Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration.
4 */
46
47
48#ifndef ATHCONTAINERS_DATAVECTORWITHALLOC_H
49#define ATHCONTAINERS_DATAVECTORWITHALLOC_H
50
51
56#include <type_traits>
57
64template <class DV, class ALLOC>
66 : private DV
67{
68public:
70 typedef typename DV::size_type size_type;
71 typedef typename DV::difference_type difference_type;
72 typedef typename DV::allocator_type allocator_type;
73 typedef typename DV::base_value_type base_value_type;
74 typedef typename DV::BaseContainer BaseContainer;
75 typedef typename DV::DVL_BASE DVL_BASE;
76 typedef typename DV::const_iterator const_iterator;
77 typedef typename DV::const_reverse_iterator const_reverse_iterator;
78 typedef typename DV::value_type value_type;
79 typedef typename DV::const_value_type const_value_type;
80 typedef typename DV::reference reference;
81 typedef typename DV::const_reference const_reference;
82 typedef typename DV::pointer pointer;
83 typedef typename DV::const_pointer const_pointer;
84
86 typedef ALLOC elt_allocator_type;
87
88 // Not necessarily DV; DV may be an intermediate class.
90
92 // cppcheck-suppress duplInheritedMember
93 static const bool has_virtual = DV::has_virtual;
94
98
101
104 typedef typename std::reverse_iterator<iterator>
106
107 typedef std::true_type isSequence;
108
110 static constexpr bool must_own = true;
111
114 using DV::size;
115 using DV::max_size;
116 using DV::resize;
117 using DV::capacity;
118 using DV::empty;
119 using DV::pop_back;
120 using DV::sort;
121 using DV::ownPolicy;
122 using DV::trackIndices;
123 using DV::testInsert;
124 using DV::getConstStore;
125 using DV::setStore;
126 using DV::setConstStore;
127 using DV::setNonConstStore;
128 using DV::hasNonConstStore;
129 using DV::cbegin;
130 using DV::cend;
131 using DV::crbegin;
132 using DV::crend;
133 using DV::do_cast;
134
135
139 using DV::begin;
140 using DV::end;
141 using DV::rbegin;
142 using DV::rend;
143 using DV::front;
144 using DV::back;
145 using DV::operator[];
146 using DV::at;
147
148
149 //========================================================================
152
153private:
158 {
159 public:
160 UPDeleter() noexcept;
162 void operator() (value_type p);
164 private:
166 };
167
168
169public:
176 class Ptr
177 {
178 using base_ptr = std::unique_ptr<base_value_type, UPDeleter>;
179 public:
180 using pointer = typename base_ptr::pointer;
181 using element_type = typename base_ptr::element_type;
182
183 Ptr() = default;
184 Ptr(std::nullptr_t) noexcept;
185 Ptr(Ptr&&) = default;
186 operator bool() const noexcept;
187 Ptr& operator= (Ptr&&) noexcept = default;
188 Ptr& operator= (std::nullptr_t) noexcept;
189 void swap (Ptr& other) noexcept;
190 pointer get() const noexcept;
191 typename std::add_lvalue_reference<base_value_type>::type operator*() const;
192 pointer operator->() const noexcept;
193 bool operator== (const Ptr& other) const noexcept;
194 bool operator< (const Ptr& other) const noexcept;
195 bool operator== (std::nullptr_t) const noexcept;
196 bool operator!= (std::nullptr_t) const noexcept;
197
198
199 private:
200 // Methods to build a Ptr from a bare pointer or to release a Ptr
201 // to a bare pointer can only be called by the container itself.
203 Ptr (pointer p, UPDeleter&& d) noexcept;
204 pointer release() noexcept;
205 // We're trying to insert this pointer into a container using
206 // heap other_heap. Ensure that that's the same heap we're using;
207 // raise an exception if not.
209
212 };
213
214
216
217
223 {
224 public:
225 using Base = std::unique_ptr<DataVectorWithAlloc>;
226 using Base::Base;
227 operator std::unique_ptr<const DV> () && noexcept
228 {
229 return std::unique_ptr<const DV>(this->release()->asDataVector());
230 }
231 };
232
233
252
253
255 //========================================================================
258
259
265
266
277
278
279 // Don't allow copying.
282
283
294
295
306
307
312
313
318
319
324
325
327 //========================================================================
330
331
339
340
347
348
350 //========================================================================
353
354
365
366
377
378
388
389
399
400
402 //========================================================================
405
406
416 iterator begin() noexcept;
417
418
428 iterator end() noexcept;
429
430
441
442
453
454
456 //========================================================================
459
460
471
472
484
485
498
499
509 iterator insert(iterator position, Ptr pElem);
510
511
524 iterator emplace(iterator position, Ptr pElem);
525
526
528 //========================================================================
531
532
541
542
553
554
560 // cppcheck-suppress duplInheritedMember
561 void clear();
562
563
565 //========================================================================
568
569
581
582
590 static void iter_swap (iterator a, iterator b);
591
592
594 //========================================================================
597
598
599
615 void swapElement (size_type index, Ptr newElem, Ptr& oldElem);
616
617
633 void swapElement (iterator pos, Ptr newElem, Ptr& oldElem);
634
635
640
641
648 static
650
651
658
659
666 const SG::AuxVectorBase& auxbase() const;
667
668
674 template <class... Args>
675 Ptr allocate (Args&&... args);
676
677
679 //========================================================================
682
683
694 bool operator< (const DataVectorWithAlloc& b) const;
695
697 bool operator> (const DataVectorWithAlloc& b) const;
698
700 bool operator<= (const DataVectorWithAlloc& b) const;
701
703 bool operator>= (const DataVectorWithAlloc& b) const;
704
705
715 bool operator== (const DataVectorWithAlloc& b) const;
716
718 bool operator!= (const DataVectorWithAlloc& b) const;
719
720
721
722private:
724 //========================================================================
727
728
731
732
740 void assignElement (typename BaseContainer::iterator pos, Ptr newElem);
741
742
748 static
750
751
758
759
766
767
772 : public DV::Deleter
773 {
774 public:
775 using Base = typename DV::Deleter;
776 using value_type = typename Base::value_type;
777 using PtrVector = typename Base::PtrVector;
780 virtual void doDelete (value_type p) override;
781 virtual void doDelete (typename PtrVector::iterator first,
782 typename PtrVector::iterator last) override;
783
784
785 private:
787 };
788
789
792};
793
794
796template <class DV, class ALLOC>
797void swap (DataVectorWithAlloc<DV, ALLOC>& a, DataVectorWithAlloc<DV, ALLOC>& b)
798{
799 a.swap (b);
800}
801
802
803
804#ifndef XAOD_STANDALONE
805
807
812template <class DV, class ALLOC>
814 : public ClassID_traits<DV>
815{
816public:
817 static constexpr bool s_isConst = true;
818};
819
820
821namespace SG {
822
823
833template <class DV, class ALLOC>
851
852
860template <class DV, class ALLOC, class U>
862{
864 static void init() { DV::dvlinfo(); }
865};
866
867
872template <class DV, class ALLOC>
874 : public BaseInfo<DV>
875{
876};
877
878
879} // namespace SG
880
881
882#endif // not XAOD_STANDALONE
883
884
886
887
888#endif // not ATHCONTAINERS_DATAVECTORWITHALLOC_H
STL-style allocator wrapper for ArenaHeapAllocator.
a traits class that associates a CLID to a type T It also detects whether T inherits from Gaudi DataO...
An STL vector of pointers that by default owns its pointed-to elements.
void swap(DataVector< T > &a, DataVector< T > &b)
See DataVector<T, BASE>::swap().
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
static Double_t a
Proxy for lvalue access to DataVector/DataList elements.
(Non-const) Iterator class for DataVector/DataList.
Helper for unique_ptr conversions.
std::unique_ptr< DataVectorWithAlloc > Base
virtual void doDelete(value_type p) override
elt_allocator_type & heap() noexcept
HeapDeleter(elt_allocator_type &&heap)
typename Base::value_type value_type
unique_ptr holding an element for this vector.
std::unique_ptr< base_value_type, UPDeleter > base_ptr
base_ptr m_ptr
Underlying unique_ptr.
void swap(Ptr &other) noexcept
typename base_ptr::element_type element_type
void checkHeap(const elt_allocator_type *other_heap) const
typename base_ptr::pointer pointer
pointer release() noexcept
Ptr(std::nullptr_t) noexcept
pointer get() const noexcept
Internal helper to serve as a deleter for our unique_ptr class.
const elt_allocator_type * heap() const noexcept
DataVector using a custom allocator for the elements.
const SG::AuxVectorBase & auxbase() const
Convert to AuxVectorBase.
ElementProxy operator[](size_type n)
Access an element, as an lvalue.
DV::size_type size_type
Basic types, forwarded from the base.
friend void test2_assignelement1a()
DV::base_value_type base_value_type
elt_allocator_type * m_heap
Non-owning pointer to the heap.
static constexpr bool must_own
If true, then this type must own its contents.
ElementProxy at(size_type n)
Access an element, as an lvalue.
static ContainerUniquePtr make_unique()
Helper for unique_ptr conversions.
DataModel_detail::ElementProxy< DataVectorWithAlloc > ElementProxy
This type is used to proxy lvalue accesses to DataVector elements, in order to handle ownership.
ElementProxy to_element_proxy(typename BaseContainer::iterator i)
Convert an iterator of the base vector to an ElementProxy for the DataVectorWithAlloc.
size_type push_new(size_type n)
Create and add a number of new elements to the end of the container.
DataVectorWithAlloc(DataVectorWithAlloc &&rhs)
Move constructor.
iterator emplace(iterator position, Ptr pElem)
Add a new element to the collection.
DV::const_iterator const_iterator
iterator end() noexcept
Return an iterator pointing past the end of the collection.
DataVectorWithAlloc(const DataVectorWithAlloc &)=delete
static const bool has_virtual
This needs to be forwarded from the base as well.
reverse_iterator rend() noexcept
Return a reverse_iterator pointing at the beginning of the collection.
DV::const_pointer const_pointer
value_type emplace_back(Ptr pElem)
Add an element to the end of the collection.
DV::const_reverse_iterator const_reverse_iterator
DataVectorWithAlloc & operator=(const DataVectorWithAlloc &rhs)=delete
iterator insert(iterator position, Ptr pElem)
Add a new element to the collection.
void swapElement(size_type index, Ptr newElem, Ptr &oldElem)
Swap one element out of the container.
value_type push_back(Ptr pElem)
Add an element to the end of the collection.
void shrink_to_fit()
Change the vector capacity to match the current size.
static DV::iterator to_base_iterator(iterator it)
Convert a DataVectorWithAlloc::iterator to an iterator of the base DataVector.
void swap(DataVectorWithAlloc &rhs)
Swap this collection with another.
void assignElement(typename BaseContainer::iterator pos, Ptr newElem)
Handle element assignment.
DV::const_value_type const_value_type
std::reverse_iterator< iterator > reverse_iterator
Standard reverse_iterator.
ElementProxy front()
Access the first element in the collection as an lvalue.
ElementProxy back()
Access the last element in the collection as an lvalue.
iterator begin() noexcept
Return an iterator pointing at the beginning of the collection.
DV::difference_type difference_type
static void iter_swap(iterator a, iterator b)
Swap the referents of two DataVector iterators.
Ptr allocate(Args &&... args)
Allocate a new vector element.
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
ALLOC elt_allocator_type
Type of the allocator use for vector elements.
iterator erase(iterator position)
Remove element at a given position.
DataModel_detail::iterator< DataVectorWithAlloc > iterator
The iterator for this type.
reverse_iterator rbegin() noexcept
Return a reverse_iterator pointing past the end of the collection.
static const DataVectorWithAlloc * fromDataVector(const DV *dv)
Cast from a DataVector to a DataVectorWithAlloc.
DV::allocator_type allocator_type
elt_allocator_type & elt_allocator()
Return the underlying allocator.
void resortAux(iterator beg, iterator end)
Reset indices / reorder aux data after elements have been permuted.
const elt_allocator_type & elt_allocator() const
Return the underlying allocator.
DataVectorWithAlloc(elt_allocator_type &&eltAlloc=elt_allocator_type())
Default constructor.
void clear()
Erase all the elements in the collection.
iterator to_my_iterator(typename DV::iterator it)
Convert an iterator of the base DataVector to a DataVectorWithAlloc::iterator.
DataVectorWithAlloc(size_type n, elt_allocator_type &&eltAlloc=elt_allocator_type())
Sized constructor.
const DV * asDataVector() const
Return a pointer to this object, as a const DataVector.
DV::const_reference const_reference
virtual ~DataVectorWithAlloc()
Destructor.
DV::BaseContainer BaseContainer
DataVector< base_value_type > base_data_vector
Derived DataVector<T>.
Definition DataVector.h:795
Provide an interface for finding inheritance information at run time.
DataBucket class for DataVectorWithAlloc.
DVLDataVectorWithAllocBucket(DataVectorWithAlloc< DV, ALLOC > *data)
Constructor from a payload object.
DVLDataVectorWithAllocBucket(std::unique_ptr< DataVectorWithAlloc< DV, ALLOC > > data)
Constructor from a payload object.
STL class.
static std::string release
Definition computils.h:50
Hook for unprotecting an arena.
Forward declaration.
Definition index.py:1
STL namespace.
Default, invalid implementation of ClassID_traits.
SG::DVLDataVectorWithAllocBucket< DV, ALLOC > type
Metafunction to find the proper DataBucket class for T.
#define private