ATLAS Offline Software
Loading...
Searching...
No Matches
JaggedVecConversions.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 */
11
12
13#ifndef ATHCONTAINERS_JAGGEDVECCONVERSIONS_H
14#define ATHCONTAINERS_JAGGEDVECCONVERSIONS_H
15
16
24#include "CxxUtils/ranges.h"
25#include <variant>
26#include <cassert>
27#include <stdexcept>
28
29
30// For unit testing.
33
34
35namespace SG { namespace detail {
36
37
46template <class PAYLOAD_T>
83
84
85//****************************************************************************
86
87
95{
96public:
99
101 using Elt_span = std::span<Elt_t>;
102
105
106
115 SG::auxid_t auxid);
116
117
122 Elt_t& elt (size_t elt_index) noexcept;
123
124
129 const Elt_t& elt (size_t elt_index) const noexcept;
130
131
139 void resize1 (size_t elt_index, index_type n_new);
140
141
151 void adjust1 (size_t elt_index, index_type index, int n_add);
152
153
154private:
157
160
161 // Holds either a pointer to the @c IAuxTypeVector the variable ID.
162 std::variant<IAuxTypeVector*, SG::auxid_t> m_linkedVec;
163};
164
165
166//****************************************************************************
167
168
175 : public std::ranges::view_base
176{
177public:
186 SG::auxid_t auxid);
187
188
189protected:
190 friend void ::test_JaggedVecProxyValBase(); // For unit testing.
191
194};
195
196
203 : public std::ranges::view_base
204{
205public:
211
212
213protected:
214 friend void ::test_JaggedVecProxyRefBase(); // For unit testing.
215
218};
219
220
221//****************************************************************************
222
223
247template <class PAYLOAD_T, class BASE>
249 : public BASE
250{
251public:
253 using Payload_t = PAYLOAD_T;
255
260 static_assert (sizeof (Elt_t) == sizeof (SG::JaggedVecElt<Payload_t>));
261
264 using value_type = std::remove_cv_t<element_type>;
265 using size_type = std::size_t;
266 using difference_type = std::ptrdiff_t;
271
275 using reverse_iterator = std::reverse_iterator<iterator>;
276 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
277
278
291 {
293 nonnull_iterator (std::nullptr_t) = delete;
294 nonnull_iterator (int) = delete;
295 operator iterator() { return m_it; }
297 };
298
299
308 JaggedVecProxyT (size_t elt_index,
309 Payload_span payload,
310 const AuxDataSpanBase& elts,
312 SG::auxid_t auxid);
313
314
321 JaggedVecProxyT (size_t elt_index,
322 Payload_span payload,
324
328 size_t size() const noexcept;
329
330
334 bool empty() const noexcept;
335
336
341 reference operator[] (size_t i) noexcept;
342
343
348 const_reference operator[] (size_t i) const noexcept;
349
350
355 reference at (size_t i);
356
357
363
364
368 reference front() noexcept;
369
370
375
376
380 reference back() noexcept;
381
382
387
388
392 iterator begin() noexcept;
393
394
398 iterator end() noexcept;
399
400
405
406
411
412
417
418
423
424
429
430
435
436
441
442
447
448
453
454
459
460
465 template <CxxUtils::InputRangeOverT<PAYLOAD_T> RANGE>
466 JaggedVecProxyT& operator= (const RANGE& range);
467
468
473
474
478 template <class VALLOC>
479 operator std::vector<Payload_t, VALLOC>() const;
480
481
487
488
492 void clear();
493
494
501 void resize (size_t n, const Payload_t& x = Payload_t());
502
503
508 void erase (nonnull_iterator pos);
509
510
515 void erase (index_type pos);
516
517
523 void erase (nonnull_iterator first, nonnull_iterator last);
524
525
531 void erase (index_type first, index_type last);
532
533
539 void insert (nonnull_iterator pos, const Payload_t& x);
540
541
548
549
556 void insert (nonnull_iterator pos, size_t n, const Payload_t& x);
557
558
565 void insert (index_type pos, size_t n, const Payload_t& x);
566
567
574 template <CxxUtils::detail::InputValIterator<PAYLOAD_T> ITERATOR>
575 void insert (nonnull_iterator pos, ITERATOR first, ITERATOR last);
576
577
584 template <CxxUtils::detail::InputValIterator<PAYLOAD_T> ITERATOR>
585 void insert (index_type pos, ITERATOR first, ITERATOR last);
586
587
593 template <CxxUtils::InputRangeOverT<PAYLOAD_T> RANGE>
594 void insert_range (nonnull_iterator pos, const RANGE& range);
595
596
602 template <CxxUtils::InputRangeOverT<PAYLOAD_T> RANGE>
603 void insert_range (index_type pos, const RANGE& range);
604
605
610 template <CxxUtils::InputRangeOverT<PAYLOAD_T> RANGE>
611 void append_range (const RANGE& range);
612
613
617 void pop_back();
618
619
625 void assign (size_t n, const Payload_t& x);
626
627
633 template <CxxUtils::detail::InputValIterator<PAYLOAD_T> ITERATOR>
634 void assign (ITERATOR first, ITERATOR last);
635
636
641 template <CxxUtils::InputRangeOverT<PAYLOAD_T> RANGE>
642 void assign_range (const RANGE& range);
643
644
645private:
649 Elt_t& elt() noexcept;
650
651
655 const Elt_t& elt() const noexcept;
656
657
661 size_t elt_begin() const noexcept;
662
663
667 size_t elt_end() const noexcept;
668
669
671 size_t m_index;
672
675};
676
677
678//****************************************************************************
679
680
690template <class PAYLOAD_T>
741
742
743} } // namespace SG::detail
744
745
747
748
749#endif // not ATHCONTAINERS_JAGGEDVECCONVERSIONS_H
Describe a range over an auxiliary variable, for low-overhead access.
Allow customizing how aux data types are treated.
Basic definitions for auxiliary types.
Manage lookup of vectors of auxiliary data.
Abstract interface for manipulating vectors of arbitrary types.
void test_JaggedVecProxyValBase()
void test_JaggedVecProxyRefBase()
Definition of JaggedVecElt.
#define x
Add to a range class conversions to containers.
Manage lookup of vectors of auxiliary data.
Describe one element of a jagged vector (base class).
uint32_t index_type
Type for the indices.
Describe one element of a jagged vector.
Auxiliary variable span wrapper (const).
Auxiliary variable span wrapper.
Definition AuxDataSpan.h:73
JaggedVecConstConverter(const JaggedVecEltBase *elts, const_Payload_span payload)
Constructor.
const element_type operator()(const JaggedVecEltBase &elt) const
Convert to a span.
detail::AuxDataConstSpan< Payload_t > const_Payload_span
CxxUtils::range_with_conv< typename AuxDataTraits< Payload_t >::const_span > element_type
JaggedVecConverter(AuxVectorData &container, auxid_t auxid, auxid_t linked_auxid)
Constructor.
CxxUtils::range_with_conv< typename AuxDataTraits< Payload_t >::const_span > element_type
JaggedVecProxyT< Payload_t, JaggedVecProxyRefBase > JVecProxyInSpan
detail::AuxDataSpan< Payload_t > Payload_span
Base class for jagged vector proxies.
typename Elt_t::index_type index_type
Type used for indexing into a jagged vector.
std::span< Elt_t > Elt_span
A span of elements.
SG::JaggedVecEltBase Elt_t
Type of a jagged vector element.
JaggedVecProxyBase(const AuxDataSpanBase &elts, AuxVectorData &container, SG::auxid_t auxid)
Constructor.
const Elt_t & elt(size_t elt_index) const noexcept
Return one jagged vector element (const).
Elt_t & elt(size_t elt_index) noexcept
Return one jagged vector element (non-const).
void adjust1(size_t elt_index, index_type index, int n_add)
Add or remove payload items from one jagged vector element.
std::variant< IAuxTypeVector *, SG::auxid_t > m_linkedVec
Elt_span m_elts
The elements of the jagged vector.
void resize1(size_t elt_index, index_type n_new)
Resize one jagged vector element.
AuxVectorData & m_container
The container holding the variable.
JaggedVecProxyBase & m_base
The proxy base information.
JaggedVecProxyRefBase(JaggedVecProxyBase &base)
Constructor.
Proxy for jagged vectors.
JaggedVecProxyT(size_t elt_index, Payload_span payload, JaggedVecProxyBase &base)
Constructor.
void resize(size_t n, const Payload_t &x=Payload_t())
void insert_range(nonnull_iterator pos, const RANGE &range)
size_t size() const noexcept
Return the size of this jagged vector element.
void insert(nonnull_iterator pos, const Payload_t &x)
JaggedVecProxyT(size_t elt_index, Payload_span payload, const AuxDataSpanBase &elts, AuxVectorData &container, SG::auxid_t auxid)
Constructor.
JaggedVecProxyBase m_base
The proxy base information.
JaggedVecProxyValBase(const AuxDataSpanBase &elts, AuxVectorData &container, SG::auxid_t auxid)
Constructor.
std::string base
Definition hcg.cxx:81
Forward declaration.
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
Definition index.py:1
STL namespace.
Add to a range class conversions to containers.
C++20 range helpers.
Minimal span-like object describing the range of an auxiliary variable.
Definition AuxDataSpan.h:40
#define private