AutoPas  3.0.0
Loading...
Searching...
No Matches
SoAView.h
Go to the documentation of this file.
1
7#pragma once
8
9namespace autopas {
10
11template <class SoAArraysType>
12class SoA;
13
22template <class SoAArraysType>
23class SoAView {
24 public:
28 SoAView() : _soa(nullptr), _startIndex(0), _endIndex(0) {}
29
39 SoAView(SoA<SoAArraysType> *soa, size_t startIndex, size_t endIndex)
40 : _soa(soa), _startIndex(startIndex), _endIndex(endIndex) {
41 if (not(soa->size() >= endIndex and endIndex >= startIndex)) /* @todo C++20 [[unlikely]] */ {
42 utils::ExceptionHandler::exception("SoAView: Trying to view particles outside of the SoA.");
43 }
44 }
45
50 explicit SoAView(SoA<SoAArraysType> *soa) : _soa(soa), _startIndex(0), _endIndex(soa->size()) {}
51
56 SoAView(SoA<SoAArraysType> &soa) : _soa(&soa), _startIndex(0), _endIndex(soa.size()) {}
57
63 template <size_t attribute>
64 [[nodiscard]] auto begin() {
65 return _soa->template begin<attribute>() + _startIndex;
66 }
67
73 template <size_t attribute>
74 [[nodiscard]] auto begin() const {
75 return _soa->template begin<attribute>() + _startIndex;
76 }
77
83 [[nodiscard]] size_t size() const { return _endIndex - _startIndex; }
84
85 private:
90
94 size_t _startIndex;
95
99 size_t _endIndex;
100};
101
102} // namespace autopas
View on a fixed part of a SoA between a start index and an end index.
Definition: SoAView.h:23
size_t size() const
Returns the number of particles in the view.
Definition: SoAView.h:83
auto begin()
Returns a pointer to the given attribute vector.
Definition: SoAView.h:64
auto begin() const
Returns a pointer to the given attribute vector const.
Definition: SoAView.h:74
SoAView(SoA< SoAArraysType > *soa)
Constructs a SoAView on the whole content of soa.
Definition: SoAView.h:50
SoAView(SoA< SoAArraysType > &soa)
Implicit constructor that converts a SoA to SoAView.
Definition: SoAView.h:56
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:39
SoAView()
Default constructor of SoAView to allow storing it in containers.
Definition: SoAView.h:28
Structur of the array class.
Definition: SoA.h:28
size_t size() const
Returns the number of particles.
Definition: SoA.h:177
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:63
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32