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 
14 #include <Core/Matrix/Matrix.hpp>
15 
16 namespace CubbyFlow
17 {
18 template <typename T, size_t N, typename Derived>
19 class ArrayBase;
20 
21 template <typename T, size_t N>
22 class Array;
23 
24 template <typename T, size_t N>
25 class ArrayView final : public ArrayBase<T, N, ArrayView<T, N>>
26 {
27  using Base = ArrayBase<T, N, ArrayView<T, N>>;
28  using Base::At;
29  using Base::m_size;
30  using Base::SetPtrAndSize;
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 
59 template <typename T, size_t N>
60 class ArrayView<const T, N> final
61  : public ArrayBase<const T, N, ArrayView<const T, N>>
62 {
64  using Base::m_size;
65  using Base::SetPtrAndSize;
66 
67  public:
68  ArrayView();
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 
79  ArrayView(const ArrayView<T, N>& other);
80 
81  ArrayView(const ArrayView<const T, N>& other);
82 
83  ArrayView(ArrayView<const T, N>&&) noexcept;
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 
98 template <class T>
100 
101 template <class T>
103 
104 template <class T>
106 
107 template <class T>
109 
110 template <class T>
112 
113 template <class T>
115 
116 template <class T>
118 
119 template <class T>
121 } // namespace CubbyFlow
122 
124 
125 #endif
void Fill(const T &val)
Definition: ArrayView-Impl.hpp:86
Definition: ArrayBase.hpp:19
Definition: ArrayView.hpp:60
ArrayView()
Definition: ArrayView-Impl.hpp:19
void Set(Array< T, N > &other)
Definition: ArrayView-Impl.hpp:74
Vector< size_t, N > m_size
Definition: ArrayBase.hpp:125
Definition: Matrix.hpp:27
Definition: pybind11Utils.hpp:20
Definition: Array-Impl.hpp:19
~ArrayView() override=default
ArrayView & operator=(const ArrayView &other)
Definition: ArrayView-Impl.hpp:57
Generic N-dimensional array class interface.
Definition: Array.hpp:32
Reference At(size_t i)
Definition: ArrayBase-Impl.hpp:138
void SetPtrAndSize(Pointer ptr, size_t ni, Args... args)
Definition: ArrayBase-Impl.hpp:250