Initial commit

This commit is contained in:
Hash Borgir
2024-04-16 21:45:38 -06:00
commit 3159020c38
533 changed files with 135446 additions and 0 deletions

41
include/fw/pool.h Normal file
View File

@@ -0,0 +1,41 @@
#pragma once
#include <cstdint>
#include <queue>
template<typename T>
class growing_object_pool {
std::queue<T*> m_objects;
uint32_t m_objects_count;
T* (*m_factory)();
public:
explicit growing_object_pool(T* (*factory)(), uint32_t initialSize = 0) {
m_factory = factory;
m_objects_count = initialSize;
for (size_t i = 0; i < initialSize; i++) {
m_objects.push(m_factory());
}
}
uint32_t get_count() const {
return m_objects_count;
}
T* get() {
if (m_objects.empty()) {
m_objects.push(m_factory());
m_objects_count++;
}
auto result = m_objects.front();
m_objects.pop();
return result;
}
void put(T* obj) {
m_objects.push(obj);
}
};

21
include/fw/singleton.h Normal file
View File

@@ -0,0 +1,21 @@
#pragma once
template<typename T>
class singleton {
public:
static T& instance();
singleton(const singleton&) = delete;
singleton& operator= (singleton) = delete;
protected:
struct token {};
singleton() = default;
};
#include <memory>
template<typename T>
T& singleton<T>::instance() {
static const std::unique_ptr<T> instance{ new T{token{}} };
return *instance;
}