17#ifndef __ONERT_UTIL_OBJECT_MANAGER_H__
18#define __ONERT_UTIL_OBJECT_MANAGER_H__
26#include <unordered_map>
49 auto index = generateIndex();
52 _objects.emplace(index, std::make_unique<Object>(std::forward<Args>(args)...));
67 auto gen_index = tryIndex(index);
68 if (gen_index.valid())
69 _objects.emplace(gen_index, std::move(
object));
82 auto gen_index = generateIndex();
83 if (gen_index.valid())
84 _objects.emplace(gen_index, std::move(
object));
100 _objects[index] = std::move(
object);
144 assert(itr->second !=
nullptr);
145 return itr->second.get();
158 return const_cast<Object *
>(
186 for (
const auto &[index, obj] :
_objects)
205 l.push_back(e.first);
208 for (
const auto &index : l)
235 Index generateIndex()
246 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.