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-2024 CERN for the benefit of the ATLAS collaboration
4 */
24 #ifndef ATHCONTAINERSINTERFACES_AUXDATASPAN_H
25 #define ATHCONTAINERSINTERFACES_AUXDATASPAN_H
26 
27 
28 #include <cstddef>
29 #include <stdexcept>
30 
31 
32 namespace SG {
33 
34 
39 {
45  AuxDataSpanBase (void* the_beg = 0, size_t the_size = 0)
46  : beg(the_beg), size(the_size)
47  {
48  }
49 
50 
52  void* beg;
53 
55  size_t size;
56 };
57 
58 
59 namespace detail {
60 
61 
69 template <class T>
71 {
72 public:
78 
79 
83  size_t size() const { return m_span.size; }
84 
85 
89  bool empty() const { return m_span.size == 0; }
90 
91 
95  T* data() { return reinterpret_cast<T*> (m_span.beg); }
96 
97 
101  const T* data() const { return reinterpret_cast<T*> (m_span.beg); }
102 
103 
108  T& operator[] (size_t index)
109  {
110  return data()[index];
111  }
112 
113 
118  const T& operator[] (size_t index) const
119  {
120  return data()[index];
121  }
122 
123 
128  T& at (size_t index)
129  {
130  if (index >= m_span.size) throw std::out_of_range ("AuxDataSpan");
131  return data()[index];
132  }
133 
134 
139  const T& at (size_t index) const
140  {
141  if (index >= m_span.size) throw std::out_of_range ("AuxDataSpan");
142  return data()[index];
143  }
144 
145 
149  T& front() { return data()[0]; }
150 
151 
155  const T& front() const { return data()[0]; }
156 
157 
161  T& back() { return data()[m_span.size-1]; }
162 
163 
167  const T& back() const { return data()[m_span.size-1]; }
168 
169 
170 private:
173 };
174 
175 
183 template <class T>
185 {
186 public:
192  : m_span (span) {}
193 
194 
198  size_t size() const { return m_span.size; }
199 
200 
204  bool empty() const { return m_span.size == 0; }
205 
206 
210  const T* data() const { return reinterpret_cast<const T*> (m_span.beg); }
211 
212 
217  const T& operator[] (size_t index) const
218  {
219  return data()[index];
220  }
221 
222 
227  const T& at (size_t index) const
228  {
229  if (index >= m_span.size) throw std::out_of_range ("AuxDataSpan");
230  return data()[index];
231  }
232 
233 
237  const T& front() const { return data()[0]; }
238 
239 
243  const T& back() const { return data()[m_span.size-1]; }
244 
245 
246 private:
249 };
250 
251 
252 } } // namespace SG::detail
253 
254 
255 #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:45
SG::AuxDataSpanBase::size
size_t size
The length of the variable's vector.
Definition: AuxDataSpan.h:55
index
Definition: index.py:1
SG::detail::AuxDataConstSpan::AuxDataConstSpan
AuxDataConstSpan(const AuxDataSpanBase &span)
Constructor.
Definition: AuxDataSpan.h:191
SG::detail::AuxDataSpan::front
const T & front() const
Return the first element in the range (const).
Definition: AuxDataSpan.h:155
detail
Definition: extract_histogram_tag.cxx:14
SG::detail::AuxDataSpan::m_span
const AuxDataSpanBase & m_span
The wrapped object.
Definition: AuxDataSpan.h:172
SG::detail::AuxDataSpan
Auxiliary variable span wrapper.
Definition: AuxDataSpan.h:71
SG::detail::AuxDataConstSpan::back
const T & back() const
Return the last element in the range.
Definition: AuxDataSpan.h:243
SG::detail::AuxDataConstSpan::empty
bool empty() const
Test to see if the span is empty.
Definition: AuxDataSpan.h:204
SG::detail::AuxDataSpan::at
const T & at(size_t index) const
Bounds-checked element access (const).
Definition: AuxDataSpan.h:139
SG::detail::AuxDataSpan::operator[]
T & operator[](size_t index)
Element access.
Definition: AuxDataSpan.h:108
SG::detail::AuxDataConstSpan::data
const T * data() const
Return the start of the span.
Definition: AuxDataSpan.h:210
SG::detail::AuxDataConstSpan
Auxiliary variable span wrapper (const).
Definition: AuxDataSpan.h:185
SG::detail::AuxDataConstSpan::operator[]
const T & operator[](size_t index) const
Element access.
Definition: AuxDataSpan.h:217
SG::AuxDataSpanBase::beg
void * beg
Pointer to the start of the variable's vector.
Definition: AuxDataSpan.h:52
SG::detail::AuxDataSpan::AuxDataSpan
AuxDataSpan(const AuxDataSpanBase &span)
Constructor.
Definition: AuxDataSpan.h:77
SG::detail::AuxDataConstSpan::front
const T & front() const
Return the first element in the range.
Definition: AuxDataSpan.h:237
SG::detail::AuxDataSpan::back
T & back()
Return the last element in the range.
Definition: AuxDataSpan.h:161
SG::detail::AuxDataSpan::front
T & front()
Return the first element in the range.
Definition: AuxDataSpan.h:149
SG::detail::AuxDataSpan::at
T & at(size_t index)
Bounds-checked element access.
Definition: AuxDataSpan.h:128
SG::AuxDataSpanBase
Minimal span-like object describing the range of an auxiliary variable.
Definition: AuxDataSpan.h:39
DeMoScan.index
string index
Definition: DeMoScan.py:364
SG::detail::AuxDataSpan::data
const T * data() const
Return the start of the span (const).
Definition: AuxDataSpan.h:101
SG::detail::AuxDataConstSpan::m_span
const AuxDataSpanBase & m_span
The wrapped object.
Definition: AuxDataSpan.h:248
SG::detail::AuxDataSpan::size
size_t size() const
Return the size of the span.
Definition: AuxDataSpan.h:83
SG::detail::AuxDataSpan::empty
bool empty() const
Test to see if the span is empty.
Definition: AuxDataSpan.h:89
SG::detail::AuxDataConstSpan::at
const T & at(size_t index) const
Bounds-checked element access.
Definition: AuxDataSpan.h:227
SG::detail::AuxDataConstSpan::size
size_t size() const
Return the size of the span.
Definition: AuxDataSpan.h:198
SG::detail::AuxDataSpan::data
T * data()
Return the start of the span.
Definition: AuxDataSpan.h:95
SG::detail::AuxDataSpan::back
const T & back() const
Return the last element in the range (const).
Definition: AuxDataSpan.h:167