ATLAS Offline Software
AlignedDynArray.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 #ifndef GSFUtils_AlignedDynArray_H
11 #define GSFUtils_AlignedDynArray_H
12 #include <cstdlib>
13 #include <memory>
14 #include <type_traits>
15 namespace GSFUtils {
16 
28 template<typename T, size_t ALIGNMENT>
30 {
31 
32  // These come from the posix_memalign
33  // which is the typical underlying implementation
34  static_assert(ALIGNMENT != 0, "Zero alignment 0");
35  static_assert(
36  (ALIGNMENT & (ALIGNMENT - 1)) == 0,
37  "Alignment not a power of 2");
38  static_assert(
39  (ALIGNMENT % sizeof(void*)) == 0,
40  "Alignment not an integral multiple of sizeof(void*)");
41  //Also we assert is POD
42  static_assert(
43  std::is_pod_v<T>,
44  "Type T is not POD");
46  // Standard typedefs
47  typedef T value_type;
48  typedef T* pointer;
49  typedef const T* const_pointer;
51  typedef const value_type& const_reference;
52  typedef value_type* iterator;
53  typedef const value_type* const_iterator;
54  typedef std::size_t size_type;
55  typedef std::ptrdiff_t difference_type;
57 
59  AlignedDynArray() = delete;
60 
62  AlignedDynArray(AlignedDynArray const&) = delete;
63 
66 
68  explicit AlignedDynArray(const size_type n);
69 
71  explicit AlignedDynArray(const size_type n, const T& value);
72 
75 
77  AlignedDynArray& operator=(AlignedDynArray&&) noexcept;
78 
81 
83  pointer buffer() noexcept;
84 
87 
89  reference operator[](size_type pos) noexcept;
90 
92  const_reference operator[](size_type pos) const noexcept;
93 
95  iterator begin() noexcept;
96 
99 
101  iterator end() noexcept;
102 
105 
107  size_type size() const noexcept;
108 
110  bool empty() const noexcept;
111 
112 private:
114  void cleanup();
115 
117  pointer m_buffer = nullptr;
118 
121 };
122 
123 } // namespace GSFUtils
124 
125 // impl .icc
126 #include "TrkGaussianSumFilterUtils/AlignedDynArray.icc"
127 
128 #endif
GSFUtils::AlignedDynArray::const_pointer
const T * const_pointer
Definition: AlignedDynArray.h:49
GSFUtils::AlignedDynArray::empty
bool empty() const noexcept
returns true is size == 0
GSFUtils::AlignedDynArray::difference_type
std::ptrdiff_t difference_type
Definition: AlignedDynArray.h:55
GSFUtils::AlignedDynArray::AlignedDynArray
AlignedDynArray()=delete
Deleted default constructor.
GSFUtils::AlignedDynArray::m_buffer
pointer m_buffer
Pointer to the underlying buffer.
Definition: AlignedDynArray.h:117
GSFUtils::AlignedDynArray::pointer
T * pointer
Definition: AlignedDynArray.h:48
athena.value
value
Definition: athena.py:124
GSFUtils::AlignedDynArray::m_size
size_type m_size
Num of elements/size.
Definition: AlignedDynArray.h:120
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
GSFUtils::AlignedDynArray::operator=
AlignedDynArray & operator=(AlignedDynArray const &)=delete
Deleted default assignment operator.
GSFUtils::AlignedDynArray::buffer
pointer buffer() noexcept
Get the underlying buffer.
GSFUtils::AlignedDynArray::size
size_type size() const noexcept
number of elements/size
beamspotman.n
n
Definition: beamspotman.py:731
GSFUtils::AlignedDynArray::AlignedDynArray
AlignedDynArray(const size_type n, const T &value)
Constructor initializing elements to value.
GSFUtils::AlignedDynArray::AlignedDynArray
AlignedDynArray(AlignedDynArray &&) noexcept
Move copy constructor.
GSFUtils::AlignedDynArray::AlignedDynArray
AlignedDynArray(AlignedDynArray const &)=delete
Deleted default copy constructor.
private
#define private
Definition: DetDescrConditionsDict_dict_fixes.cxx:13
GSFUtils::AlignedDynArray::begin
iterator begin() noexcept
iterator pointing to the first element
GSFUtils::AlignedDynArray::end
iterator end() noexcept
iterator pointing to the past-the-end element
GSFUtils::AlignedDynArray::const_reference
const value_type & const_reference
Definition: AlignedDynArray.h:51
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
GSFUtils::AlignedDynArray::const_iterator
const value_type * const_iterator
Definition: AlignedDynArray.h:53
GSFUtils::AlignedDynArray::reference
value_type & reference
Definition: AlignedDynArray.h:50
GSFUtils::AlignedDynArray::AlignedDynArray
AlignedDynArray(const size_type n)
Constructor with default initializing elements.
GSFUtils::AlignedDynArray::value_type
T value_type
Definition: AlignedDynArray.h:34
GSFUtils::AlignedDynArray::size_type
std::size_t size_type
Definition: AlignedDynArray.h:54
GSFUtils
Dynamic array fullfilling alignment requirements.
Definition: KLGaussianMixtureReduction.cxx:391
GSFUtils::AlignedDynArray::iterator
value_type * iterator
Definition: AlignedDynArray.h:52
GSFUtils::AlignedDynArray::cleanup
void cleanup()
Helper method for calling the dtor for the elements.
GSFUtils::AlignedDynArray
A wrapper around std::aligned_alloc.
Definition: AlignedDynArray.h:30