13 #ifndef _ENTITY_ENTITYPOOL_H_INCLUDED_
14 #define _ENTITY_ENTITYPOOL_H_INCLUDED_
16 #include <boost/function.hpp>
17 #include <boost/iterator/iterator_facade.hpp>
18 #include <boost/pool/pool.hpp>
19 #include <boost/signals2.hpp>
20 #include <boost/signals2/optional_last_value.hpp>
21 #include <boost/smart_ptr/shared_ptr.hpp>
25 #include <type_traits>
28 #include "entity/config.hpp"
35 struct forward_traversal_tag;
39 namespace iterator_traits {
51 : boost::iterator_facade<
54 , boost::forward_traversal_tag
60 friend class boost::iterator_core_access;
72 bool equal(iterator_impl
const& other)
const
74 return iterator_ == other.iterator_;
103 while(!entities_.empty())
113 entities_.push_back(new_idx);
121 void* new_index_mem =
nullptr;
122 bool pop_on_catch =
false;
125 new_index_mem = entity_pool_.malloc();
126 new_idx_ptr =
new(new_index_mem)
entity_index_t(entities_.size());
129 entities_.push_back(new_idx_ptr);
134 unique_entity::ref_type new_idx(
136 entity_deleter(*
this)
140 return std::move(new_idx);
145 entities_.pop_back();
147 new_idx_ptr->~entity_index_t();
149 entity_pool_.free(new_index_mem);
161 destroy_impl(e.index());
166 return entities_.size();
171 return entities_.empty();
176 return iterator_impl(0);
181 return iterator_impl(
size());
194 struct entity_deleter
197 : owner_pool_(owner_pool)
202 owner_pool_.destroy_impl(*p);
211 swap(entities_[a], entities_[b]);
212 swap(*entities_[a], *entities_[b]);
219 if((e + 1) < entities_.size())
221 swap_entities(e, *entities_.back());
225 entities_.pop_back();
229 idx->~entity_index_t();
232 entity_pool_.free(idx_mem);
237 entities_.push_back(idx);
241 boost::pool<> entity_pool_;
242 std::vector<entity_index_t*> entities_;
243 signal_list signals_;
257 namespace iterator_traits
266 #endif // _ENTITY_ENTITYPOOL_H_INCLUDED_
iterator_impl const_iterator
entity_pool::iterator end(entity_pool const &p)
boost::signals2::signal< void(entity)> on_entity_destroy
unique_entity create_unique()
void swap(unique_entity &a, unique_entity &b)
std::size_t entity_index_t
entity_pool::iterator begin(entity_pool const &p)
shared_entity create_shared()
boost::signals2::signal< void(entity)> on_entity_create
entity make_entity(entity_index_t idx) BOOST_NOEXCEPT_OR_NOTHROW
boost::signals2::signal< void(entity, entity)> on_entity_swap