1 #ifndef NTA_IDFACTORY_H_INCLUDED
2 #define NTA_IDFACTORY_H_INCLUDED
4 #define NTA_INVALID_ID 0
8 #include "nta/MyEngine.h"
53 T ret = m_free.back();
64 if (
id > m_last_id)
return true;
65 for (
const auto& id2 : m_free) {
66 if (
id == id2)
return true;
73 #endif // NTA_IDFACTORY_H_INCLUDED
bool is_free(T id) const
Returns whether or not an id is free.
T get_last_id() const
Returns m_last_id.
bool is_in_use(T id) const
Returns whether or not the id is in use.
std::vector< T > m_free
IDs that were previously active but have since been freed.
void reset()
Resets this to a new IDFactory.
T m_last_id
The smallest id that has never been assigned.
Class for generating unique (integral) IDs.
void free(T id)
calls free_id
T gen_id()
Generates a new, unused ID.
void clear()
Resets this to a new IDFactory.
std::size_t get_count() const
Returns the number of active ids.
T operator()()
Calls (and returns) gen_id.