void test(void) { ObjectManager<> m; Object<>* obj = Create<Item>(); m.add(obj->id(), obj); printf("%u\n", obj->id()); obj = Create<Item>(); m.add(obj->id(), obj); printf("%u\n", obj->id()); obj = Create<Item>(); m.add(obj->id(), obj); printf("%u\n", obj->id()); obj = Create<Object<> >(); m.add(obj->id(), obj); printf("%u\n", obj->id()); obj = Create<Object<> >(); m.add(obj->id(), obj); printf("%u\n", obj->id()); obj = Create<Object<> >(); m.add(obj->id(), obj); printf("%u\n", obj->id()); m.del(2); ItemNT* itemn = CreateNT<ItemNT>("hello"); printf("%u, %s, %u\n", itemn->id(), itemn->name().c_str(), itemn->tempid()); while (!m.add(itemn->id(), itemn)) itemn->id()++; printf("%u, %s, %u\n", itemn->id(), itemn->name().c_str(), itemn->tempid()); }
void testObjectManager() { ObjectManager<int> manager; std::vector<ObjectID> ids; static const int nb = 1024; for(int i = 0; i < nb; ++i) { ids.push_back(manager.add(i)); } bool check_array[2 * nb]; std::fill(std::begin(check_array), std::end(check_array), true); srand(0); for(int i = 0; i < nb / 2; ++i) { int idx = rand() % nb; if(manager.isValid(ids[idx])) { int value = manager[ids[idx]]; check_array[value] = false; } manager.remove(ids[idx]); } for(int i = nb; i < 2 * nb; ++i) { ids.push_back(manager.add(i)); } for(const auto& data: manager) { if(!check_array[data]) { return; } } }