ATLAS Offline Software
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 */
24 #ifndef ATHCONTAINERSINTERFACES_AUXDATASPAN_H
25 #define ATHCONTAINERSINTERFACES_AUXDATASPAN_H
26 
27 
29 #include <cstddef>
30 #include <stdexcept>
31 
32 
33 namespace 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 
61 namespace detail {
62 
63 
71 template <class T>
73 {
74 public:
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 
110  T& operator[] (size_t index)
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 
176 private:
179 };
180 
181 
189 template <class T>
191 {
192 public:
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 
254 private:
257 };
258 
259 
260 } } // namespace SG::detail
261 
262 
263 #endif // not ATHCONTAINERSINTERFACES_AUXDATASPAN_H
CxxUtils::span
span(T *ptr, std::size_t sz) -> span< T >
A couple needed deduction guides.
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
SG::AuxDataSpanBase::AuxDataSpanBase
AuxDataSpanBase(void *the_beg=0, size_t the_size=0)
Constructor.
Definition: AuxDataSpan.h:47
SG::AuxDataSpanBase::size
size_t size
The length of the variable's vector.
Definition: AuxDataSpan.h:57
index
Definition: index.py:1
SG::detail::AuxDataConstSpan::AuxDataConstSpan
AuxDataConstSpan(const AuxDataSpanBase &span)
Constructor.
Definition: AuxDataSpan.h:197
SG::detail::AuxDataSpan::front
const T & front() const
Return the first element in the range (const).
Definition: AuxDataSpan.h:161
detail
Definition: extract_histogram_tag.cxx:14
SG::detail::AuxDataSpan::m_span
const AuxDataSpanBase & m_span
The wrapped object.
Definition: AuxDataSpan.h:178
SG::detail::AuxDataSpan
Auxiliary variable span wrapper.
Definition: AuxDataSpan.h:73
SG::detail::AuxDataConstSpan::back
const T & back() const
Return the last element in the range.
Definition: AuxDataSpan.h:251
SG::detail::AuxDataConstSpan::empty
bool empty() const
Test to see if the span is empty.
Definition: AuxDataSpan.h:210
SG::detail::AuxDataSpan::at
const T & at(size_t index) const
Bounds-checked element access (const).
Definition: AuxDataSpan.h:143
SG::detail::AuxDataSpan::operator[]
T & operator[](size_t index)
Element access.
Definition: AuxDataSpan.h:110
SG::detail::AuxDataConstSpan::data
const T * data() const
Return the start of the span.
Definition: AuxDataSpan.h:216
CxxUtils::throw_out_of_range
void throw_out_of_range(const std::string &what, size_t index, size_t size, const void *obj)
Throw an out_of_range exception.
Definition: throw_out_of_range.cxx:27
SG::detail::AuxDataConstSpan
Auxiliary variable span wrapper (const).
Definition: AuxDataSpan.h:191
SG::detail::AuxDataConstSpan::operator[]
const T & operator[](size_t index) const
Element access.
Definition: AuxDataSpan.h:223
SG::AuxDataSpanBase::beg
void * beg
Pointer to the start of the variable's vector.
Definition: AuxDataSpan.h:54
throw_out_of_range.h
Helpers for throwing out_of_range exceptions.
SG::detail::AuxDataSpan::AuxDataSpan
AuxDataSpan(const AuxDataSpanBase &span)
Constructor.
Definition: AuxDataSpan.h:79
SG::detail::AuxDataConstSpan::front
const T & front() const
Return the first element in the range.
Definition: AuxDataSpan.h:245
SG::detail::AuxDataSpan::back
T & back()
Return the last element in the range.
Definition: AuxDataSpan.h:167
SG::detail::AuxDataSpan::front
T & front()
Return the first element in the range.
Definition: AuxDataSpan.h:155
SG::detail::AuxDataSpan::at
T & at(size_t index)
Bounds-checked element access.
Definition: AuxDataSpan.h:130
SG::AuxDataSpanBase
Minimal span-like object describing the range of an auxiliary variable.
Definition: AuxDataSpan.h:40
DeMoScan.index
string index
Definition: DeMoScan.py:362
SG::detail::AuxDataSpan::data
const T * data() const
Return the start of the span (const).
Definition: AuxDataSpan.h:103
SG::detail::AuxDataConstSpan::m_span
const AuxDataSpanBase & m_span
The wrapped object.
Definition: AuxDataSpan.h:256
SG::detail::AuxDataSpan::size
size_t size() const
Return the size of the span.
Definition: AuxDataSpan.h:85
SG::detail::AuxDataSpan::empty
bool empty() const
Test to see if the span is empty.
Definition: AuxDataSpan.h:91
SG::detail::AuxDataConstSpan::at
const T & at(size_t index) const
Bounds-checked element access.
Definition: AuxDataSpan.h:233
SG::detail::AuxDataConstSpan::size
size_t size() const
Return the size of the span.
Definition: AuxDataSpan.h:204
SG::detail::AuxDataSpan::data
T * data()
Return the start of the span.
Definition: AuxDataSpan.h:97
SG::detail::AuxDataSpan::back
const T & back() const
Return the last element in the range (const).
Definition: AuxDataSpan.h:173