Peano
Loading...
Searching...
No Matches
SmartPointerVector.h
Go to the documentation of this file.
1// This file is part of the Peano project. For conditions of distribution and
2// use, please see the copyright notice at www.peano-framework.org
3#pragma once
4
5#include "tarch/la/la.h"
6#include "tarch/Assertions.h"
9
10#include <memory>
11#include <string>
12#include <bitset>
13#include <sstream>
14#include <initializer_list>
15
16namespace tarch {
17 namespace la {
18 template <int Size, typename Scalar>
19 struct SmartPointerVector;
20
21 template <int Size, typename Scalar>
22 struct Vector;
23
24 template <typename NewScalarType, int Size, typename Scalar>
26 }
27}
28
34template<int Size, typename Scalar>
35std::string toString( const tarch::la::SmartPointerVector<Size,Scalar>& smartPointerVector );
36
46template <int Size, typename Scalar>
48 private:
56 Scalar* _values;
57
58 std::shared_ptr< Scalar[] > _dataSmartPointer;
59
60 public:
65
66 SmartPointerVector( const Scalar* values ) InlineMethod;
67
75 SmartPointerVector( std::initializer_list<Scalar> values );
76
77 SmartPointerVector( const std::bitset<Size>& values ) InlineMethod;
78
82 SmartPointerVector(const Scalar& initialValue);
83
92 SmartPointerVector(const SmartPointerVector<Size,Scalar>& toCopy);
93
112 SmartPointerVector(const Vector<Size,Scalar>& toCopy);
113
122 inline SmartPointerVector<Size,Scalar>& operator= (const SmartPointerVector<Size,Scalar>& toAssign) InlineMethod;
123
131 inline SmartPointerVector<Size,Scalar>& operator=( const Vector<Size,Scalar>& vector );
132
139 inline SmartPointerVector<Size,Scalar>& operator=( const Scalar& vector );
140
144 int size() const;
145
155 inline const Scalar& operator[] (int index) const InlineMethod {
156#if defined(GPUOffloadingOff)
157 assertion3 ( index >= 0, index, Size, ::toString(*this) );
158 assertion4 ( index < Size, index, Size, ::toString(*this), "you may not take the indexth entry from a SmartPointerVector with only Size components" );
159#endif
160 return _values[index];
161 }
162
168 inline Scalar& operator[] (int index) InlineMethod {
169#if defined(GPUOffloadingOff)
170 assertion3 ( index >= 0, index, Size, ::toString(*this) );
171 assertion3 ( index < Size, index, Size, ::toString(*this) );
172#endif
173 return _values[index];
174 }
175
187 inline const Scalar& operator() (int index) const InlineMethod {
188#if defined(GPUOffloadingOff)
189 assertion3 ( index >= 0, index, Size, ::toString(*this) );
190 assertion3 ( index < Size, index, Size, ::toString(*this) );
191#endif
192 return _values[index];
193 }
194
200 inline Scalar& operator() (int index) InlineMethod {
201#if defined(GPUOffloadingOff)
202 assertion3 ( index >= 0, index, Size, ::toString(*this) );
203 assertion3 ( index < Size, index, Size, ::toString(*this) );
204#endif
205 return _values[index];
206 }
207
213 Scalar* data() {
214 return _values;
215 }
216
217 const Scalar * data() const {
218 return _values;
219 }
220
222};
223
224#include "tarch/la/SmartPointerVector.cpph"
225
#define assertion4(expr, param0, param1, param2, param3)
#define assertion3(expr, param0, param1, param2)
std::string toString(const tarch::la::SmartPointerVector< Size, Scalar > &smartPointerVector)
Pipes the elements of a SmartPointerVector into a std::string and returns the string.
tarch::la::SmartPointerVector< Size, NewScalarType > convertScalar(const tarch::la::SmartPointerVector< Size, Scalar > &SmartPointerVector)
Have to include this header, as I need access to the SYCL_EXTERNAL keyword.
Definition accelerator.h:19
std::string toString(MemoryLocation value)
Simple SmartPointerVector class.
int size() const
Returns the number of components of the SmartPointerVector.
SmartPointerVector() InlineMethod
Clang requires the always_inline attribute, as it otherwise makes weird decisions.
Scalar * _values
In the original vector, this is.
Scalar * data()
This routine returns a pointer to the first data element.
const Scalar & operator()(int index) const InlineMethod
Returns read-only ref.
std::shared_ptr< Scalar[] > _dataSmartPointer
Vector< Size, Scalar > toVector() const
const Scalar & operator[](int index) const InlineMethod
Returns read-only ref.
Simple vector class.
Definition Vector.h:159
#define InlineMethod
Generic identifier for inlined functions.
Definition tarch.h:97