entity
Entity/Component System for C++
entity::entity_pool Class Reference

Description

Definition at line 48 of file entity_pool.hpp.

Instances and minimal complete definitions

struct  signal_list
 

Public Types

typedef iterator_impl const_iterator
 
typedef iterator_impl iterator
 

Public Member Functions

iterator begin () const
 
entity create ()
 
shared_entity create_shared ()
 
unique_entity create_unique ()
 
void destroy (entity e)
 
bool empty () const
 
iterator end () const
 
 entity_pool ()
 
signal_listsignals ()
 
std::size_t size () const
 
 ~entity_pool ()
 

Member Function Documentation

iterator entity::entity_pool::begin ( ) const

Definition at line 174 of file entity_pool.hpp.

Referenced by entity::begin(), entity::component::dense_pool< T >::dense_pool(), and entity::component::sparse_pool< T >::sparse_pool().

175  {
176  return iterator_impl(0);
177  }
entity entity::entity_pool::create ( )

Definition at line 109 of file entity_pool.hpp.

References entity::make_entity(), entity::entity_pool::signal_list::on_entity_create, and signals().

110  {
111  entity_index_t* new_idx = new(entity_pool_.malloc()) entity_index_t(entities_.size());
112  entity ret_val = make_entity(*new_idx);
113  entities_.push_back(new_idx);
114  signals().on_entity_create(ret_val);
115  return ret_val;
116  }
signal_list & signals()
std::size_t entity_index_t
boost::signals2::signal< void(entity)> on_entity_create
Definition: entity_pool.hpp:92
entity make_entity(entity_index_t idx) BOOST_NOEXCEPT_OR_NOTHROW
Definition: entity.hpp:64
shared_entity entity::entity_pool::create_shared ( )

Definition at line 154 of file entity_pool.hpp.

References create_unique().

155  {
156  return create_unique();
157  }
unique_entity create_unique()
unique_entity entity::entity_pool::create_unique ( )

Definition at line 118 of file entity_pool.hpp.

References entity::make_entity(), entity::entity_pool::signal_list::on_entity_create, and signals().

Referenced by create_shared().

119  {
120  entity_index_t* new_idx_ptr = nullptr;
121  void* new_index_mem = nullptr;
122  bool pop_on_catch = false;
123  try
124  {
125  new_index_mem = entity_pool_.malloc();
126  new_idx_ptr = new(new_index_mem) entity_index_t(entities_.size());
127 
128  entity ent_val = make_entity(*new_idx_ptr);
129  entities_.push_back(new_idx_ptr);
130 
131  // Ensure we leave the container in a good state if shared_ptr throws.
132  pop_on_catch = true;
133 
134  unique_entity::ref_type new_idx(
135  new_idx_ptr,
136  entity_deleter(*this)
137  );
138 
139  signals().on_entity_create(ent_val);
140  return std::move(new_idx);
141  }
142  catch(...)
143  {
144  if(pop_on_catch)
145  entities_.pop_back();
146  if(new_idx_ptr)
147  new_idx_ptr->~entity_index_t();
148  if(new_index_mem)
149  entity_pool_.free(new_index_mem);
150  throw;
151  }
152  }
signal_list & signals()
std::size_t entity_index_t
boost::signals2::signal< void(entity)> on_entity_create
Definition: entity_pool.hpp:92
entity make_entity(entity_index_t idx) BOOST_NOEXCEPT_OR_NOTHROW
Definition: entity.hpp:64
void entity::entity_pool::destroy ( entity  e)

Definition at line 159 of file entity_pool.hpp.

Referenced by ~entity_pool().

160  {
161  destroy_impl(e.index());
162  }
bool entity::entity_pool::empty ( ) const

Definition at line 169 of file entity_pool.hpp.

170  {
171  return entities_.empty();
172  }
iterator entity::entity_pool::end ( ) const

Definition at line 179 of file entity_pool.hpp.

References size().

Referenced by entity::component::dense_pool< T >::dense_pool(), entity::end(), and entity::component::sparse_pool< T >::sparse_pool().

180  {
181  return iterator_impl(size());
182  }
std::size_t size() const
std::size_t entity::entity_pool::size ( ) const

Definition at line 164 of file entity_pool.hpp.

Referenced by entity::component::dense_pool< T >::dense_pool(), end(), and entity::component::saturated_pool< T >::saturated_pool().

165  {
166  return entities_.size();
167  }

Member Typedef Documentation

typedef iterator_impl entity::entity_pool::const_iterator

Definition at line 88 of file entity_pool.hpp.

typedef iterator_impl entity::entity_pool::iterator

Definition at line 87 of file entity_pool.hpp.

Constructor & Destructor Documentation

entity::entity_pool::entity_pool ( )

Definition at line 97 of file entity_pool.hpp.

98  : entity_pool_(16)
99  {}
entity::entity_pool::~entity_pool ( )

Definition at line 101 of file entity_pool.hpp.

References destroy(), and entity::make_entity().

102  {
103  while(!entities_.empty())
104  {
105  destroy(make_entity(*entities_.back()));
106  }
107  }
void destroy(entity e)
entity make_entity(entity_index_t idx) BOOST_NOEXCEPT_OR_NOTHROW
Definition: entity.hpp:64