Array.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_HPP
12 #define CUBBYFLOW_ARRAY_HPP
13 
14 #include <Core/Array/ArrayBase.hpp>
15 
16 #include <vector>
17 
18 namespace CubbyFlow
19 {
31 template <typename T, size_t N>
32 class ArrayView;
33 
34 template <typename T, size_t N>
35 class Array final : public ArrayBase<T, N, Array<T, N>>
36 {
38  using Base::At;
40  using Base::m_size;
41  using Base::SetPtrAndSize;
43 
44  public:
45  Array();
46 
47  Array(const Vector<size_t, N>& size, const T& initVal = T{});
48 
49  template <typename... Args>
50  Array(size_t nx, Args... args);
51 
53 
54  template <typename OtherDerived>
56 
57  template <typename OtherDerived>
59 
60  ~Array() override = default;
61 
62  Array(const Array& other);
63 
64  Array(Array&& other) noexcept;
65 
66  Array& operator=(const Array& other);
67 
68  Array& operator=(Array&& other) noexcept;
69 
70  template <typename OtherDerived>
72 
73  template <typename OtherDerived>
75 
76  template <typename D>
77  void CopyFrom(const ArrayBase<T, N, D>& other);
78 
79  template <typename D>
80  void CopyFrom(const ArrayBase<const T, N, D>& other);
81 
82  void Fill(const T& val);
83 
84  void Resize(Vector<size_t, N> size_, const T& initVal = T{});
85 
86  template <typename... Args>
87  void Resize(size_t nx, Args... args);
88 
89  template <size_t M = N>
90  std::enable_if_t<(M == 1), void> Append(const T& val);
91 
92  template <typename OtherDerived, size_t M = N>
93  std::enable_if_t<(M == 1), void> Append(
94  const ArrayBase<T, N, OtherDerived>& extra);
95 
96  template <typename OtherDerived, size_t M = N>
97  std::enable_if_t<(M == 1), void> Append(
99 
100  void Clear();
101 
102  void Swap(Array& other);
103 
104  [[nodiscard]] ArrayView<T, N> View();
105 
106  [[nodiscard]] ArrayView<const T, N> View() const;
107 
108  private:
109  std::vector<T> m_data;
110 };
111 
112 template <class T>
114 
115 template <class T>
117 
118 template <class T>
120 
121 template <class T>
123 } // namespace CubbyFlow
124 
125 #include <Core/Array/Array-Impl.hpp>
126 
127 #endif
void SwapPtrAndSize(ArrayBase &other)
Definition: ArrayBase-Impl.hpp:269
void ClearPtrAndSize()
Definition: ArrayBase-Impl.hpp:263
Definition: ArrayBase.hpp:19
Definition: ArrayView.hpp:60
void Fill(const T &val)
Definition: Array-Impl.hpp:280
~Array() override=default
Array()
Definition: Array-Impl.hpp:162
void Clear()
Definition: Array-Impl.hpp:339
void CopyFrom(const ArrayBase< T, N, D > &other)
Definition: Array-Impl.hpp:263
Vector< size_t, N > m_size
Definition: ArrayBase.hpp:125
Definition: Matrix.hpp:27
Definition: pybind11Utils.hpp:20
Definition: Array-Impl.hpp:19
Generic N-dimensional array class interface.
Definition: Array.hpp:32
std::enable_if_t<(M==1), void > Append(const T &val)
Definition: Array-Impl.hpp:311
void Swap(Array &other)
Definition: Array-Impl.hpp:347
typename NestedInitializerLists< T, N >::Type NestedInitializerListsT
Definition: NestedInitializerList.hpp:57
void Resize(Vector< size_t, N > size_, const T &initVal=T{})
Definition: Array-Impl.hpp:286
Reference At(size_t i)
Definition: ArrayBase-Impl.hpp:138
Array & operator=(const Array &other)
Definition: Array-Impl.hpp:224
void SetPtrAndSize(Pointer ptr, size_t ni, Args... args)
Definition: ArrayBase-Impl.hpp:250
ArrayView< T, N > View()
Definition: Array-Impl.hpp:355