18 #ifndef UNIT_MAP_H_INCLUDED
19 #define UNIT_MAP_H_INCLUDED
28 #include <boost/unordered_map.hpp>
108 typedef std::map<size_t, unit_pod>
t_umap;
110 typedef boost::unordered_map<map_location, t_umap::iterator>
t_lmap;
128 template<
typename iter_types>
179 return i_->second.unit; }
183 return i_->second.unit; }
187 return *
i_->second.unit; }
192 iterator_type new_i(
i_);
195 }
while ((new_i !=
the_map().
end()) && (!new_i->second.unit)) ;
216 }
while(
i_ != begin && (!
i_->second.unit));
233 explicit operator bool()
const
246 assert(
i_->second.ref_count > 0);
259 assert(
i_->second.ref_count != 0);
260 if( (--(
i_->second.ref_count) == 0) && (!
i_->second.unit) ){
261 iterator_type old =
i_++;
262 tank_->umap_.erase(old);
293 unit_iterator
find(
size_t id);
297 const_unit_iterator
find(
size_t id)
const {
return const_cast<unit_map *
>(
this)->
find(
id); }
304 std::vector<const_unit_iterator>
find_leaders(
int side)
const;
317 void clear(
bool force =
false);
369 template <
typename T>
370 size_t erase(
const T &iter);
381 #ifndef DEBUG_UNIT_MAP
402 return is_found(i) && (i->second.unit !=
nullptr);
405 return is_found(i) && (i->second->second.unit !=
nullptr);
408 bool is_found(
const t_umap::const_iterator &
i)
const {
return i !=
umap_.end(); }
409 bool is_found(
const t_lmap::const_iterator &
i)
const {
return i !=
lmap_.end(); }
411 template <
typename X>
416 template <
typename X>
435 template <
typename T>
437 assert(iter.valid());
439 return erase(iter->get_location());
444 #endif // UNIT_MAP_H_INCLUDED
iter_types::container_type container_type
unit_map::t_umap::iterator iterator_type
void dec()
Decrement the reference counter Delete the umap entry if the unit is gone and the reference counter i...
std::vector< unit_iterator > find_leaders(int side)
iterator_base< standard_iter_types > unit_iterator
unit_map & operator=(const unit_map &that)
boost::intrusive_ptr< value_type > pointer
size_t count(const map_location &loc) const
unit_iterator find_leader(int side)
boost::unordered_map< map_location, t_umap::iterator > t_lmap
Map of location to umap iterator.
t_lmap lmap_
location -> umap::iterator.
bool is_found(const t_lmap::const_iterator &i) const
bool operator==(const iterator_base &rhs) const
iter_types::iterator_type iterator_type
const_unit_iterator find_leader(int side) const
bool valid_ref_count() const
bool self_check() const
Checks invariants. For debugging purposes only. Doesn't do anything in non-debug mode.
n_ref_counter::t_ref_counter< signed int > ref_count
unit_map const container_type
iterator_base< const_iter_types > const_unit_iterator
unit_map::const_unit_iterator make_const_unit_iterator(X const &i) const
reference operator*() const
const_unit_iterator find(size_t id) const
unit_map::t_umap::iterator iterator_type
t_umap umap_
underlying_id -> unit_pod.
const_unit_iterator find(const map_location &loc) const
iterator_base(const iterator_base &that)
const_unit_iterator const_iterator
pointer operator->() const
bool is_found(const t_umap::const_iterator &i) const
pointer get_shared_ptr() const
std::pair< unit_iterator, bool > insert(unit_ptr p)
Adds the unit to the map.
iterator_base & operator=(const iterator_base &that)
iterator_base operator--(int)
void clear(bool force=false)
bool is_valid(const t_umap::const_iterator &i) const
const_unit_iterator end() const
iterator_base(iterator_type i, container_type *m)
std::pair< unit_iterator, bool > replace(const map_location &l, const unit &u)
Works like unit_map::add; but l is emptied first, if needed.
iterator_base(t_lmap::iterator ui, container_type *m)
Construct an iterator from the location map.
std::pair< unit_iterator, bool > add(const map_location &l, const unit &u)
Adds a copy of unit u at location l of the map.
Encapsulates the map of the game.
t_umap::iterator begin_core() const
unit_iterator find_first_leader(int side)
unit_map::t_umap & the_map() const
iterator_base & operator--()
void inc()
Increment the reference counter.
std::map< size_t, unit_pod > t_umap
Map of underlying_id to unit and a reference counter.
const_unit_iterator begin() const
iterator_base & operator++()
bool has_unit(const unit *const u) const
Is the unit in the map?
bool is_valid(const t_lmap::const_iterator &i) const
std::pair< unit_iterator, bool > move(const map_location &src, const map_location &dst)
Moves a unit from location src to location dst.
unit_map::unit_iterator make_unit_iterator(X const &i)
size_t erase(const map_location &l)
Erases the unit at location l, if any.
bool operator!=(const iterator_base &rhs) const
The pointer to the unit and a reference counter to record the number of extant iterators pointing to ...
std::forward_iterator_tag iterator_category
container_type * tank_
local iterator
unit_ptr extract(const map_location &loc)
Extracts a unit from the map.
Container associating units to locations.
unit_iterator find(size_t id)
iter_types::value_type value_type
iterator_base operator++(int)
bool valid_for_dereference() const