43 virtual const object&
create(
const std::function<
void(
object&)>& constructor )
override
46 auto instance =
id.instance();
47 if( instance >= _objects.size() ) _objects.resize( instance + 1 );
48 _objects[instance] = std::make_unique<T>();
49 _objects[instance]->id = id;
50 constructor( *_objects[instance] );
51 _objects[instance]->id = id;
53 return *_objects[instance];
56 virtual void modify(
const object& obj,
const std::function<
void(
object&)>& modify_callback )
override
59 modify_callback( *_objects[obj.
id.
instance()] );
62 virtual const object&
insert(
object&& obj )
override
65 assert(
nullptr !=
dynamic_cast<T*
>(&obj) );
66 if( _objects.size() <= instance ) _objects.resize( instance+1 );
67 assert( !_objects[instance] );
68 _objects[instance] = std::make_unique<T>( std::move(
static_cast<T&
>(obj) ) );
69 return *_objects[instance];
72 virtual void remove(
const object& obj )
override
74 assert(
nullptr !=
dynamic_cast<const T*
>(&obj) );
76 _objects[instance].reset();
77 while( (_objects.size() > 0) && (_objects.back() ==
nullptr) )
83 assert(
id.space() == T::space_id );
84 assert(
id.type() == T::type_id );
86 const auto instance =
id.instance();
87 if( instance >= _objects.size() )
return nullptr;
88 return _objects[instance].get();
94 for(
const auto& ptr : _objects )
105 explicit const_iterator(
const std::vector<std::unique_ptr<object>>& objects ):_objects(objects) {}
107 const std::vector<std::unique_ptr<object>>& objects,
108 const std::vector<std::unique_ptr<object>>::
const_iterator& a ):_itr(a),_objects(objects){}
111 const T&
operator*()
const {
return static_cast<const T&
>(*_itr->get()); }
121 while( (_itr != _objects.end()) && ( (*_itr) ==
nullptr ) )
132 const std::vector<std::unique_ptr<object>>& _objects;
137 size_t size()
const {
return _objects.size(); }
139 std::vector< std::unique_ptr<object> > _objects;