12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- /*
- * 2D Game Engine
- * Pool.h:
- * Based on pikuma.com 2D game engine in C++ and Lua course
- * Copyright (c) 2021 986-Studio. All rights reserved.
- *
- * Created by Manoël Trapier on 11/02/2021.
- */
- #ifndef GAMEENGINE_POOL_H
- #define GAMEENGINE_POOL_H
- #include <vector>
- class IPool
- {
- public:
- virtual ~IPool() = default;
- };
- template <typename T> class Pool:public IPool
- {
- private:
- std::vector<T> data;
- public:
- Pool(int size = 100) { this->resize(size); }
- virtual ~Pool() = default;
- bool isEmpty() const { return this->data.empty(); }
- uint32_t getSize() { return this->data.size(); }
- void resize(uint32_t size) { this->data.resize(size); }
- void clear() { this->data.clear(); }
- void add(T object) { this->data.push_back(object); }
- void set(uint32_t index, T object) { this->data[index] = object; }
- T& get(uint32_t index) { return this->data[index]; }
- T& operator[](uint32_t index) { return this->data[index]; }
- };
- #endif /* GAMEENGINE_POOL_H */
|