aboutsummaryrefslogtreecommitdiff
path: root/mwe/ecs-memory-efficient/inc/ContiguousContainer.h
blob: dd0321e9d4a8cd01527c347861c892153fc3aea8 (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 <utility>   // For std::move and std::forward
#include <stdexcept> // For std::bad_alloc
#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"