Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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  // cppcheck-suppress uninitMemberVar; false positive
46  AuxDataSpanBase (void* the_beg = 0, size_t the_size = 0)
47  : beg(the_beg), size(the_size)
48  {
49  }
50 
51 
53  void* beg;
54 
56  size_t size;
57 };
58 
59 
60 namespace detail {
61 
62 
70 template <class T>
72 {
73 public:
79 
80 
84  size_t size() const { return m_span.size; }
85 
86 
90  bool empty() const { return m_span.size == 0; }
91 
92 
96  T* data() { return reinterpret_cast<T*> (m_span.beg); }
97 
98 
102  const T* data() const { return reinterpret_cast<T*> (m_span.beg); }
103 
104 
109  T& operator[] (size_t index)
110  {
111  return data()[index];
112  }
113 
114 
119  const T& operator[] (size_t index) const
120  {
121  return data()[index];
122  }
123 
124 
129  T& at (size_t index)
130  {
131  if (index >= m_span.size) throw std::out_of_range ("AuxDataSpan");
132  return data()[index];
133  }
134 
135 
140  const T& at (size_t index) const
141  {
142  if (index >= m_span.size) throw std::out_of_range ("AuxDataSpan");
143  return data()[index];
144  }
145 
146 
150  T& front() { return data()[0]; }
151 
152 
156  const T& front() const { return data()[0]; }
157 
158 
162  T& back() { return data()[m_span.size-1]; }
163 
164 
168  const T& back() const { return data()[m_span.size-1]; }
169 
170 
171 private:
174 };
175 
176 
184 template <class T>
186 {
187 public:
193  : m_span (span) {}
194 
195 
199  size_t size() const { return m_span.size; }
200 
201 
205  bool empty() const { return m_span.size == 0; }
206 
207 
211  const T* data() const { return reinterpret_cast<const T*> (m_span.beg); }
212 
213 
218  const T& operator[] (size_t index) const
219  {
220  return data()[index];
221  }
222 
223 
228  const T& at (size_t index) const
229  {
230  if (index >= m_span.size) throw std::out_of_range ("AuxDataSpan");
231  return data()[index];
232  }
233 
234 
238  const T& front() const { return data()[0]; }
239 
240 
244  const T& back() const { return data()[m_span.size-1]; }
245 
246 
247 private:
250 };
251 
252 
253 } } // namespace SG::detail
254 
255 
256 #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:46
SG::AuxDataSpanBase::size
size_t size
The length of the variable's vector.
Definition: AuxDataSpan.h:56
index
Definition: index.py:1
SG::detail::AuxDataConstSpan::AuxDataConstSpan
AuxDataConstSpan(const AuxDataSpanBase &span)
Constructor.
Definition: AuxDataSpan.h:192
SG::detail::AuxDataSpan::front
const T & front() const
Return the first element in the range (const).
Definition: AuxDataSpan.h:156
detail
Definition: extract_histogram_tag.cxx:14
SG::detail::AuxDataSpan::m_span
const AuxDataSpanBase & m_span
The wrapped object.
Definition: AuxDataSpan.h:173
SG::detail::AuxDataSpan
Auxiliary variable span wrapper.
Definition: AuxDataSpan.h:72
SG::detail::AuxDataConstSpan::back
const T & back() const
Return the last element in the range.
Definition: AuxDataSpan.h:244
SG::detail::AuxDataConstSpan::empty
bool empty() const
Test to see if the span is empty.
Definition: AuxDataSpan.h:205
SG::detail::AuxDataSpan::at
const T & at(size_t index) const
Bounds-checked element access (const).
Definition: AuxDataSpan.h:140
SG::detail::AuxDataSpan::operator[]
T & operator[](size_t index)
Element access.
Definition: AuxDataSpan.h:109
SG::detail::AuxDataConstSpan::data
const T * data() const
Return the start of the span.
Definition: AuxDataSpan.h:211
SG::detail::AuxDataConstSpan
Auxiliary variable span wrapper (const).
Definition: AuxDataSpan.h:186
SG::detail::AuxDataConstSpan::operator[]
const T & operator[](size_t index) const
Element access.
Definition: AuxDataSpan.h:218
SG::AuxDataSpanBase::beg
void * beg
Pointer to the start of the variable's vector.
Definition: AuxDataSpan.h:53
SG::detail::AuxDataSpan::AuxDataSpan
AuxDataSpan(const AuxDataSpanBase &span)
Constructor.
Definition: AuxDataSpan.h:78
SG::detail::AuxDataConstSpan::front
const T & front() const
Return the first element in the range.
Definition: AuxDataSpan.h:238
SG::detail::AuxDataSpan::back
T & back()
Return the last element in the range.
Definition: AuxDataSpan.h:162
SG::detail::AuxDataSpan::front
T & front()
Return the first element in the range.
Definition: AuxDataSpan.h:150
SG::detail::AuxDataSpan::at
T & at(size_t index)
Bounds-checked element access.
Definition: AuxDataSpan.h:129
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:102
SG::detail::AuxDataConstSpan::m_span
const AuxDataSpanBase & m_span
The wrapped object.
Definition: AuxDataSpan.h:249
SG::detail::AuxDataSpan::size
size_t size() const
Return the size of the span.
Definition: AuxDataSpan.h:84
SG::detail::AuxDataSpan::empty
bool empty() const
Test to see if the span is empty.
Definition: AuxDataSpan.h:90
SG::detail::AuxDataConstSpan::at
const T & at(size_t index) const
Bounds-checked element access.
Definition: AuxDataSpan.h:228
SG::detail::AuxDataConstSpan::size
size_t size() const
Return the size of the span.
Definition: AuxDataSpan.h:199
SG::detail::AuxDataSpan::data
T * data()
Return the start of the span.
Definition: AuxDataSpan.h:96
SG::detail::AuxDataSpan::back
const T & back() const
Return the last element in the range (const).
Definition: AuxDataSpan.h:168