123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- #pragma once
- #include <cstddef>
- #include <vector>
- namespace WwiseGTE
- {
- template <typename T>
- class Array2
- {
- public:
-
-
-
-
- Array2(size_t bound0, size_t bound1)
- :
- mBound0(bound0),
- mBound1(bound1),
- mObjects(bound0 * bound1),
- mIndirect1(bound1)
- {
- SetPointers(mObjects.data());
- }
- Array2(size_t bound0, size_t bound1, T* objects)
- :
- mBound0(bound0),
- mBound1(bound1),
- mIndirect1(bound1)
- {
- SetPointers(objects);
- }
-
-
-
- Array2()
- :
- mBound0(0),
- mBound1(0)
- {
- }
- Array2(Array2 const& other)
- :
- mBound0(other.mBound0),
- mBound1(other.mBound1)
- {
- *this = other;
- }
- Array2& operator=(Array2 const& other)
- {
-
- mObjects = other.mObjects;
- SetPointers(other);
- return *this;
- }
- Array2(Array2&& other) noexcept
- :
- mBound0(other.mBound0),
- mBound1(other.mBound1)
- {
- *this = std::move(other);
- }
- Array2& operator=(Array2&& 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 T const* operator[](int row) const
- {
- return mIndirect1[row];
- }
- inline T* operator[](int row)
- {
- return mIndirect1[row];
- }
- private:
- void SetPointers(T* objects)
- {
- for (size_t i1 = 0; i1 < mBound1; ++i1)
- {
- size_t j0 = mBound0 * i1;
- mIndirect1[i1] = &objects[j0];
- }
- }
- void SetPointers(Array2 const& other)
- {
- mBound0 = other.mBound0;
- mBound1 = other.mBound1;
- mIndirect1.resize(mBound1);
- if (mBound0 > 0)
- {
-
- SetPointers(mObjects.data());
- }
- else if (mIndirect1.size() > 0)
- {
-
- SetPointers(other.mIndirect1[0]);
- }
-
- }
- size_t mBound0, mBound1;
- std::vector<T> mObjects;
- std::vector<T*> mIndirect1;
- };
- }
|