aboutsummaryrefslogtreecommitdiff
path: root/mwe/ecs-memory-efficient/inc/ContiguousContainer.h
blob: e3b57ba544cc077c2ecbd75cd49c2372c1abad67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#pragma once

#include <cstdlib> // For malloc and free
#include <new> // For placement new
#include <stdexcept> // For std::bad_alloc
#include <utility> // For std::move and std::forward
#include <vector> // For returning references

template <typename T>
class ContiguousContainer {
public:
	ContiguousContainer();
	~ContiguousContainer();

	// Use perfect forwarding for pushBack
	template <typename... Args>
	void pushBack(Args &&... args);

	void popBack();
	T & operator[](size_t index);
	size_t getSize() const;

	// Function to return references to all stored objects
	std::vector<std::reference_wrapper<T>> getAllReferences();

private:
	T * mData;
	size_t mSize;
	size_t mCapacity;

	void resize(size_t new_capacity); // Resize function to allocate more space
};

#include "ContiguousContainer.hpp"