Loading...
Searching...
No Matches
ArrayView.hpp
Go to the documentation of this file.
1// This code is based on Jet framework.
2// Copyright (c) 2018 Doyub Kim
3// CubbyFlow is voxel-based fluid simulation engine for computer games.
4// Copyright (c) 2020 CubbyFlow Team
5// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6// AI Part: Dongheon Cho, Minseo Kim
7// We are making my contributions/submissions to this project solely in our
8// personal capacity and are not conveying any rights to any intellectual
9// property of any third parties.
10
11#ifndef CUBBYFLOW_ARRAY_VIEW_HPP
12#define CUBBYFLOW_ARRAY_VIEW_HPP
13
15
16namespace CubbyFlow
17{
18template <typename T, size_t N, typename Derived>
19class ArrayBase;
20
21template <typename T, size_t N>
22class Array;
23
24template <typename T, size_t N>
25class ArrayView final : public ArrayBase<T, N, ArrayView<T, N>>
26{
28 using Base::At;
29 using Base::m_size;
31
32 public:
33 ArrayView();
34
35 ArrayView(T* ptr, const Vector<size_t, N>& size);
36
37 template <size_t M = N>
38 ArrayView(std::enable_if_t<(M == 1), T*> ptr, size_t size);
39
40 ArrayView(Array<T, N>& other);
41
42 ~ArrayView() override = default;
43
44 ArrayView(const ArrayView& other);
45
46 ArrayView(ArrayView&& other) noexcept;
47
48 ArrayView& operator=(const ArrayView& other);
49
50 ArrayView& operator=(ArrayView&& other) noexcept;
51
52 void Set(Array<T, N>& other);
53
54 void Set(const ArrayView& other);
55
56 void Fill(const T& val);
57};
58
59template <typename T, size_t N>
60class ArrayView<const T, N> final
61 : public ArrayBase<const T, N, ArrayView<const T, N>>
62{
64 using Base::m_size;
66
67 public:
69
70 ArrayView(const T* ptr, const Vector<size_t, N>& size);
71
72 template <size_t M = N>
73 ArrayView(std::enable_if_t<(M == 1), T*> ptr, size_t size);
74
75 ArrayView(const Array<T, N>& other);
76
77 ~ArrayView() override = default;
78
80
82
84
85 ArrayView& operator=(const ArrayView<T, N>& other);
86
87 ArrayView& operator=(const ArrayView<const T, N>& other);
88
89 ArrayView& operator=(ArrayView<const T, N>&& other) noexcept;
90
91 void Set(const Array<T, N>& other);
92
93 void Set(const ArrayView<T, N>& other);
94
95 void Set(const ArrayView<const T, N>& other);
96};
97
98template <class T>
99using ArrayView1 = ArrayView<T, 1>;
100
101template <class T>
102using ArrayView2 = ArrayView<T, 2>;
103
104template <class T>
105using ArrayView3 = ArrayView<T, 3>;
106
107template <class T>
108using ArrayView4 = ArrayView<T, 4>;
109
110template <class T>
111using ConstArrayView1 = ArrayView<const T, 1>;
112
113template <class T>
114using ConstArrayView2 = ArrayView<const T, 2>;
115
116template <class T>
117using ConstArrayView3 = ArrayView<const T, 3>;
118
119template <class T>
120using ConstArrayView4 = ArrayView<const T, 4>;
121} // namespace CubbyFlow
122
123#include <Core/Array/ArrayView-Impl.hpp>
124
125#endif
Definition ArrayBase.hpp:20
Vector< size_t, N > m_size
Definition ArrayBase.hpp:125
void SetPtrAndSize(Pointer ptr, size_t ni, Args... args)
Definition ArrayBase-Impl.hpp:250
Reference At(size_t i)
Definition ArrayBase-Impl.hpp:138
Definition Array.hpp:36
ArrayView(const T *ptr, const Vector< size_t, N > &size)
ArrayView(ArrayView< const T, N > &&) noexcept
ArrayView(const ArrayView< T, N > &other)
ArrayView(const Array< T, N > &other)
ArrayView(const ArrayView< const T, N > &other)
ArrayView(std::enable_if_t<(M==1), T * > ptr, size_t size)
Generic N-dimensional array class interface.
Definition ArrayView.hpp:26
ArrayView()
Definition ArrayView-Impl.hpp:19
void Set(Array< T, N > &other)
Definition ArrayView-Impl.hpp:74
~ArrayView() override=default
void Fill(const T &val)
Definition ArrayView-Impl.hpp:86
ArrayView & operator=(const ArrayView &other)
Definition ArrayView-Impl.hpp:57
Definition Matrix.hpp:30
Definition pybind11Utils.hpp:21