17#ifndef __ONERT_UTIL_OBJECT_MANAGER_H__
18#define __ONERT_UTIL_OBJECT_MANAGER_H__
26#include <unordered_map>
51 auto index = generateIndex();
54 _objects.emplace(index, std::make_unique<Object>(std::forward<Args>(args)...));
69 auto gen_index = tryIndex(index);
70 if (gen_index.valid())
71 _objects.emplace(gen_index, std::move(
object));
84 auto gen_index = generateIndex();
85 if (gen_index.valid())
86 _objects.emplace(gen_index, std::move(
object));
102 _objects[index] = std::move(
object);
146 assert(itr->second !=
nullptr);
147 return itr->second.get();
160 return const_cast<Object *
>(
188 for (
const auto &[index, obj] :
_objects)
207 l.push_back(e.first);
210 for (
const auto &index : l)
237 Index generateIndex()
248 std::unordered_map<Index, std::unique_ptr<Object>>
_objects;
A wrapper class for unsigned integral Index NOTE : Max value of the underlying type is used as the in...
Class that owns objects and maps them with indices as a handle for them.
Index set(Index index, std::unique_ptr< Object > &&object)
Set the object in the container with given index.
Object & at(const Index &index)
Get the object that is associated with the given index.
size_t size() const
Return the number of objects that the manager contains.
Index emplace(Args &&...args)
Create an object with args and put it in the container with a newly assigned Index.
void remove(const Index &index)
Remove the object that is associated with the given index.
Index push(std::unique_ptr< Object > &&object, Index index)
Put the object in the container with given index.
Index push(std::unique_ptr< Object > &&object)
Put the object in the container with a newly assigned index.
Object * getRawPtr(const Index &index)
Get the object that is associated with the given index.
void iterate(const std::function< void(const Index &, const Object &)> &fn) const
Iterate over the container with given function.
std::unordered_map< Index, std::unique_ptr< Object > > _objects
const Object & at(const Index &index) const
Get the object that is associated with the given index.
const Object * getRawPtr(const Index &index) const
Get the object that is associated with the given index.
void iterate(const std::function< void(const Index &, Object &)> &fn)
Iterate over the container with given function.
bool exist(const Index &index) const
Get the object that is associated with the given index.