ArrayView-Impl.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_IMPL_HPP
12 #define CUBBYFLOW_ARRAY_VIEW_IMPL_HPP
13 
14 #include <Core/Array/Array.hpp>
15 
16 namespace CubbyFlow
17 {
18 template <typename T, size_t N>
20 {
21  // Do nothing
22 }
23 
24 template <typename T, size_t N>
26 {
27  Base::SetPtrAndSize(ptr, size);
28 }
29 
30 template <typename T, size_t N>
31 template <size_t M>
32 ArrayView<T, N>::ArrayView(std::enable_if_t<(M == 1), T*> ptr, size_t size)
33  : ArrayView(ptr, Vector<size_t, N>{ size })
34 {
35  // Do nothing
36 }
37 
38 template <typename T, size_t N>
40 {
41  Set(other);
42 }
43 
44 template <typename T, size_t N>
46 {
47  Set(other);
48 }
49 
50 template <typename T, size_t N>
52 {
53  *this = std::move(other);
54 }
55 
56 template <typename T, size_t N>
58 {
59  Set(other);
60 
61  return *this;
62 }
63 
64 template <typename T, size_t N>
66 {
67  Base::SetPtrAndSize(other.data(), other.Size());
68  other.SetPtrAndSize(nullptr, Vector<size_t, N>{});
69 
70  return *this;
71 }
72 
73 template <typename T, size_t N>
75 {
76  Base::SetPtrAndSize(other.data(), other.Size());
77 }
78 
79 template <typename T, size_t N>
80 void ArrayView<T, N>::Set(const ArrayView& other)
81 {
82  Base::SetPtrAndSize(const_cast<T*>(other.data()), other.Size());
83 }
84 
85 template <typename T, size_t N>
86 void ArrayView<T, N>::Fill(const T& val)
87 {
89  [&](auto... idx) { this->At(idx...) = val; });
90 }
91 
92 template <typename T, size_t N>
94 {
95  // Do nothing
96 }
97 
98 template <typename T, size_t N>
100  : ArrayView()
101 {
102  Base::SetPtrAndSize(ptr, size);
103 }
104 
105 template <typename T, size_t N>
106 template <size_t M>
107 ArrayView<const T, N>::ArrayView(const std::enable_if_t<(M == 1), T*> ptr,
108  size_t size)
109  : ArrayView(ptr, Vector<size_t, N>{ size })
110 {
111  // Do nothing
112 }
113 
114 template <typename T, size_t N>
116 {
117  Set(other);
118 }
119 
120 template <typename T, size_t N>
122 {
123  Set(other);
124 }
125 
126 template <typename T, size_t N>
128 {
129  Set(other);
130 }
131 
132 template <typename T, size_t N>
134 {
135  *this = std::move(other);
136 }
137 
138 template <typename T, size_t N>
140  const ArrayView<T, N>& other)
141 {
142  Set(other);
143 
144  return *this;
145 }
146 
147 template <typename T, size_t N>
149  const ArrayView<const T, N>& other)
150 {
151  Set(other);
152 
153  return *this;
154 }
155 
156 template <typename T, size_t N>
158  ArrayView<const T, N>&& other) noexcept
159 {
160  Base::SetPtrAndSize(other.data(), other.Size());
161  other.SetPtrAndSize(nullptr, Vector<size_t, N>{});
162 
163  return *this;
164 }
165 
166 template <typename T, size_t N>
168 {
169  Base::SetPtrAndSize(other.data(), other.Size());
170 }
171 
172 template <typename T, size_t N>
174 {
175  Base::SetPtrAndSize(other.data(), other.Size());
176 }
177 
178 template <typename T, size_t N>
180 {
181  Base::SetPtrAndSize(other.data(), other.Size());
182 }
183 } // namespace CubbyFlow
184 
185 #endif
Definition: ArrayView.hpp:60
ArrayView()
Definition: ArrayView-Impl.hpp:19
void Set(Array< T, N > &other)
Definition: ArrayView-Impl.hpp:74
Definition: Matrix.hpp:27
Definition: pybind11Utils.hpp:20
void Fill(ArrayView< T, N > a, const Vector< size_t, N > &begin, const Vector< size_t, N > &end, const T &val)
Definition: ArrayUtils-Impl.hpp:19
Definition: Array-Impl.hpp:19
ArrayView & operator=(const ArrayView &other)
Definition: ArrayView-Impl.hpp:57
Generic N-dimensional array class interface.
Definition: Array.hpp:32
Pointer data()
Definition: ArrayBase-Impl.hpp:39
void ForEachIndex(const Vector< IndexType, N > &begin, const Vector< IndexType, N > &end, const Func &func)
Definition: IterationUtils-Impl.hpp:51
const Vector< size_t, N > & Size() const
Definition: ArrayBase-Impl.hpp:51
void SetPtrAndSize(Pointer ptr, size_t ni, Args... args)
Definition: ArrayBase-Impl.hpp:250