ATLAS Offline Software
Loading...
Searching...
No Matches
AuxDataSpan.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*/
22
23
24#ifndef ATHCONTAINERSINTERFACES_AUXDATASPAN_H
25#define ATHCONTAINERSINTERFACES_AUXDATASPAN_H
26
27
29#include <cstddef>
30#include <stdexcept>
31
32
33namespace SG {
34
35
40{
46 // cppcheck-suppress uninitMemberVar; false positive
47 AuxDataSpanBase (void* the_beg = 0, size_t the_size = 0)
48 : beg(the_beg), size(the_size)
49 {
50 }
51
52
54 void* beg;
55
57 size_t size;
58};
59
60
61namespace detail {
62
63
71template <class T>
73{
74public:
79 AuxDataSpan (const AuxDataSpanBase& span) : m_span (span) {}
80
81
85 size_t size() const { return m_span.size; }
86
87
91 bool empty() const { return m_span.size == 0; }
92
93
97 T* data() { return reinterpret_cast<T*> (m_span.beg); }
98
99
103 const T* data() const { return reinterpret_cast<T*> (m_span.beg); }
104
105
111 {
112 return data()[index];
113 }
114
115
120 const T& operator[] (size_t index) const
121 {
122 return data()[index];
123 }
124
125
130 T& at (size_t index)
131 {
132 if (index >= m_span.size) {
133 CxxUtils::throw_out_of_range (__PRETTY_FUNCTION__, index, m_span.size, this);
134 }
135 return data()[index];
136 }
137
138
143 const T& at (size_t index) const
144 {
145 if (index >= m_span.size) {
146 CxxUtils::throw_out_of_range (__PRETTY_FUNCTION__, index, m_span.size, this);
147 }
148 return data()[index];
149 }
150
151
155 T& front() { return data()[0]; }
156
157
161 const T& front() const { return data()[0]; }
162
163
167 T& back() { return data()[m_span.size-1]; }
168
169
173 const T& back() const { return data()[m_span.size-1]; }
174
175
176private:
179};
180
181
189template <class T>
191{
192public:
198 : m_span (span) {}
199
200
204 size_t size() const { return m_span.size; }
205
206
210 bool empty() const { return m_span.size == 0; }
211
212
216 const T* data() const { return reinterpret_cast<const T*> (m_span.beg); }
217
218
223 const T& operator[] (size_t index) const
224 {
225 return data()[index];
226 }
227
228
233 const T& at (size_t index) const
234 {
235 if (index >= m_span.size) {
236 CxxUtils::throw_out_of_range (__PRETTY_FUNCTION__, index, m_span.size, this);
237 }
238 return data()[index];
239 }
240
241
245 const T& front() const { return data()[0]; }
246
247
251 const T& back() const { return data()[m_span.size-1]; }
252
253
254private:
257};
258
259
260} } // namespace SG::detail
261
262
263#endif // not ATHCONTAINERSINTERFACES_AUXDATASPAN_H
const T & at(size_t index) const
Bounds-checked element access.
const T * data() const
Return the start of the span.
bool empty() const
Test to see if the span is empty.
size_t size() const
Return the size of the span.
const T & back() const
Return the last element in the range.
const T & operator[](size_t index) const
Element access.
AuxDataConstSpan(const AuxDataSpanBase &span)
Constructor.
const T & front() const
Return the first element in the range.
size_t size() const
Return the size of the span.
Definition AuxDataSpan.h:85
T & at(size_t index)
Bounds-checked element access.
const T & at(size_t index) const
Bounds-checked element access (const).
AuxDataSpan(const AuxDataSpanBase &span)
Constructor.
Definition AuxDataSpan.h:79
bool empty() const
Test to see if the span is empty.
Definition AuxDataSpan.h:91
T & front()
Return the first element in the range.
T & operator[](size_t index)
Element access.
const T & front() const
Return the first element in the range (const).
T * data()
Return the start of the span.
Definition AuxDataSpan.h:97
T & back()
Return the last element in the range.
const T & back() const
Return the last element in the range (const).
const T * data() const
Return the start of the span (const).
const AuxDataSpanBase & m_span
void throw_out_of_range(const std::string &what, size_t index, size_t size, const void *obj)
Throw an out_of_range exception.
Forward declaration.
Definition index.py:1
Minimal span-like object describing the range of an auxiliary variable.
Definition AuxDataSpan.h:40
void * beg
Pointer to the start of the variable's vector.
Definition AuxDataSpan.h:54
size_t size
The length of the variable's vector.
Definition AuxDataSpan.h:57
AuxDataSpanBase(void *the_beg=0, size_t the_size=0)
Constructor.
Definition AuxDataSpan.h:47
Helpers for throwing out_of_range exceptions.