36 lines
617 B
C++
36 lines
617 B
C++
|
|
#ifndef IDSET_H
|
|
#define IDSET_H
|
|
|
|
#include <map>
|
|
|
|
template <class T>
|
|
class IDSet
|
|
{
|
|
public:
|
|
IDSet() { m_next_index = 1; }
|
|
int add(const T & o)
|
|
{
|
|
int id = m_next_index++;
|
|
m_data[id] = o;
|
|
return id;
|
|
}
|
|
void remove(int id)
|
|
{
|
|
m_data.erase(id);
|
|
}
|
|
T & operator[](int id)
|
|
{
|
|
return m_data[id];
|
|
}
|
|
bool contains(int id)
|
|
{
|
|
return m_data.find(id) != m_data.end();
|
|
}
|
|
protected:
|
|
std::map<int, T> m_data;
|
|
int m_next_index;
|
|
};
|
|
|
|
#endif
|