AutoPas  3.0.0
Loading...
Searching...
No Matches
SoAView.h
Go to the documentation of this file.
1
7#pragma once
8
10
11namespace autopas {
12
13template <class SoAArraysType>
14class SoA;
15
24template <class SoAArraysType>
25class SoAView {
26 public:
30 SoAView() : _soa(nullptr), _startIndex(0), _endIndex(0) {}
31
41 SoAView(SoA<SoAArraysType> *soa, size_t startIndex, size_t endIndex)
42 : _soa(soa), _startIndex(startIndex), _endIndex(endIndex) {
43 if (not(soa->size() >= endIndex and endIndex >= startIndex)) /* @todo C++20 [[unlikely]] */ {
44 utils::ExceptionHandler::exception("SoAView: Trying to view particles outside of the SoA.");
45 }
46 }
47
52 explicit SoAView(SoA<SoAArraysType> *soa) : _soa(soa), _startIndex(0), _endIndex(soa->size()) {}
53
58 SoAView(SoA<SoAArraysType> &soa) : _soa(&soa), _startIndex(0), _endIndex(soa.size()) {}
59
65 template <size_t attribute>
66 [[nodiscard]] auto begin() {
67 return _soa->template begin<attribute>() + _startIndex;
68 }
69
75 template <size_t attribute>
76 [[nodiscard]] auto begin() const {
77 return _soa->template begin<attribute>() + _startIndex;
78 }
79
85 [[nodiscard]] size_t size() const { return _endIndex - _startIndex; }
86
87 private:
92
96 size_t _startIndex;
97
101 size_t _endIndex;
102};
103
104} // namespace autopas
View on a fixed part of a SoA between a start index and an end index.
Definition: SoAView.h:25
size_t size() const
Returns the number of particles in the view.
Definition: SoAView.h:85
auto begin()
Returns a pointer to the given attribute vector.
Definition: SoAView.h:66
auto begin() const
Returns a pointer to the given attribute vector const.
Definition: SoAView.h:76
SoAView(SoA< SoAArraysType > *soa)
Constructs a SoAView on the whole content of soa.
Definition: SoAView.h:52
SoAView(SoA< SoAArraysType > &soa)
Implicit constructor that converts a SoA to SoAView.
Definition: SoAView.h:58
SoAView(SoA< SoAArraysType > *soa, size_t startIndex, size_t endIndex)
Constructs a view on soa that starts at startIndex (inclusive) and ends at endIndex (exclusive).
Definition: SoAView.h:41
SoAView()
Default constructor of SoAView to allow storing it in containers.
Definition: SoAView.h:30
Structur of the array class.
Definition: SoA.h:28
size_t size() const
Returns the number of particles.
Definition: SoA.h:187
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:64
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:34