123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- #pragma once
- #include <cstddef>
- #include <vector>
- namespace WwiseGTE
- {
- template <typename T>
- class Array3
- {
- public:
-
-
-
-
- Array3(size_t bound0, size_t bound1, size_t bound2)
- :
- mBound0(bound0),
- mBound1(bound1),
- mBound2(bound2),
- mObjects(bound0 * bound1 * bound2),
- mIndirect1(bound1 * bound2),
- mIndirect2(bound2)
- {
- SetPointers(mObjects.data());
- }
- Array3(size_t bound0, size_t bound1, size_t bound2, T* objects)
- :
- mBound0(bound0),
- mBound1(bound1),
- mBound2(bound2),
- mIndirect1(bound1 * bound2),
- mIndirect2(bound2)
- {
- SetPointers(objects);
- }
-
-
-
- Array3()
- :
- mBound0(0),
- mBound1(0),
- mBound2(0)
- {
- }
- Array3(Array3 const& other)
- :
- mBound0(other.mBound0),
- mBound1(other.mBound1),
- mBound2(other.mBound2)
- {
- *this = other;
- }
- Array3& operator=(Array3 const& other)
- {
-
- mObjects = other.mObjects;
- SetPointers(other);
- return *this;
- }
- Array3(Array3&& other) noexcept
- :
- mBound0(other.mBound0),
- mBound1(other.mBound1),
- mBound2(other.mBound2)
- {
- *this = std::move(other);
- }
- Array3& operator=(Array3&& other) noexcept
- {
-
- mObjects = std::move(other.mObjects);
- SetPointers(other);
- return *this;
- }
-
-
-
-
-
- inline size_t GetBound0() const
- {
- return mBound0;
- }
- inline size_t GetBound1() const
- {
- return mBound1;
- }
- inline size_t GetBound2() const
- {
- return mBound2;
- }
- inline T* const* operator[](int slice) const
- {
- return mIndirect2[slice];
- }
- inline T** operator[](int slice)
- {
- return mIndirect2[slice];
- }
- private:
- void SetPointers(T* objects)
- {
- for (size_t i2 = 0; i2 < mBound2; ++i2)
- {
- size_t j1 = mBound1 * i2;
- mIndirect2[i2] = &mIndirect1[j1];
- for (size_t i1 = 0; i1 < mBound1; ++i1)
- {
- size_t j0 = mBound0 * (i1 + j1);
- mIndirect2[i2][i1] = &objects[j0];
- }
- }
- }
- void SetPointers(Array3 const& other)
- {
- mBound0 = other.mBound0;
- mBound1 = other.mBound1;
- mBound2 = other.mBound2;
- mIndirect1.resize(mBound1 * mBound2);
- mIndirect2.resize(mBound2);
- if (mBound0 > 0)
- {
-
- SetPointers(mObjects.data());
- }
- else if (mIndirect1.size() > 0)
- {
-
- SetPointers(other.mIndirect2[0][0]);
- }
-
- }
- size_t mBound0, mBound1, mBound2;
- std::vector<T> mObjects;
- std::vector<T*> mIndirect1;
- std::vector<T**> mIndirect2;
- };
- }
|