25 #include <unordered_map>
117 typedef std::map<std::size_t, unit_pod>
umap;
120 typedef std::unordered_map<map_location, umap::iterator>
lmap;
139 template<
typename iter_types>
210 return i_->second.unit;
226 return *
i_->second.unit;
236 }
while((new_i !=
the_map().
end()) && (!new_i->second.unit));
259 }
while(
i_ !=
begin && (!
i_->second.unit));
278 explicit operator bool()
const
310 assert(
i_->second.ref_count > 0);
323 ++(
i_->second.ref_count);
336 assert(
i_->second.ref_count != 0);
337 if((--(
i_->second.ref_count) == 0) && (!
i_->second.unit)) {
339 tank_->umap_.erase(old);
389 auto res =
find(val);
396 auto res =
find(val);
411 std::vector<const_unit_iterator>
find_leaders(
int side)
const;
415 return lmap_.count(loc);
447 return lmap_.empty();
450 void clear(
bool force =
false);
517 std::size_t
erase(
const T& iter);
547 return is_found(
i) && (
i->second.unit !=
nullptr);
552 return is_found(
i) && (
i->second->second.unit !=
nullptr);
603 assert(iter.valid());
605 return erase(iter->get_location());
Container associating units to locations.
unit_const_ptr find_unit_ptr(const T &val) const
umap::iterator begin_core() const
std::vector< unit_iterator > find_leaders(int side)
umap umap_
underlying_id -> unit_pod.
bool has_unit_at(const map_location &loc) const
Tests whether a unit exists at the given location.
std::pair< unit_iterator, bool > umap_retval_pair_t
const_unit_iterator end() const
bool self_check() const
Checks invariants.
iterator_base< const_iter_types > const_unit_iterator
const_unit_iterator find(std::size_t id) const
void clear(bool force=false)
unit_ptr extract(const map_location &loc)
Extracts a unit from the map.
std::size_t count(const map_location &loc) const
const_unit_iterator const_iterator
umap_retval_pair_t replace(const map_location &l, unit_ptr p)
Works like unit_map::add; but l is emptied first, if needed.
iterator_base< standard_iter_types > unit_iterator
unit_ptr find_unit_ptr(const T &val)
const_unit_iterator begin() const
const_unit_iterator find(const map_location &loc) const
unit_iterator find(std::size_t id)
unit_map & operator=(const unit_map &that)
unit_map::unit_iterator make_unit_iterator(const X &i)
std::size_t num_iters() const
unit_iterator find_first_leader(int side)
lmap lmap_
location -> umap::iterator.
bool is_found(const lmap::const_iterator &i) const
bool has_unit(const unit *const u) const
Is the unit in the map?
std::size_t erase(const map_location &l)
Erases the unit at location l, if any.
umap_retval_pair_t add(const map_location &l, const unit &u)
Adds a copy of unit u at location l of the map.
unit_iterator find_leader(int side)
std::unordered_map< map_location, umap::iterator > lmap
Map of location to umap iterator.
umap_retval_pair_t insert(unit_ptr p)
Inserts the unit pointed to by p into the map.
const_unit_iterator find_leader(int side) const
bool is_valid(const lmap::const_iterator &i) const
bool is_found(const umap::const_iterator &i) const
bool is_valid(const umap::const_iterator &i) const
std::map< std::size_t, unit_pod > umap
umap_retval_pair_t move(const map_location &src, const map_location &dst)
Moves a unit from location src to location dst.
unit_map::const_unit_iterator make_const_unit_iterator(const X &i) const
This class represents a single unit of a specific type.
std::string::const_iterator iterator
std::shared_ptr< const unit > unit_const_ptr
std::shared_ptr< unit > unit_ptr
rect dst
Location on the final composed sheet.
rect src
Non-transparent portion of the surface to compose.
Encapsulates the map of the game.
unit_map const container_type
unit_map::umap::iterator iterator_type
std::forward_iterator_tag iterator_category
iterator_base & operator++()
iter_types::value_type value_type
iterator_base & operator--()
iterator_base(lmap::iterator ui, container_type *m)
Constructs an iterator from the location map.
iterator_base & operator=(const iterator_base &that)
iterator_base operator--(int)
iterator_base(const iterator_base &that)
unit_map::umap & the_map() const
bool valid_for_dereference() const
std::shared_ptr< value_type > pointer
reference operator*() const
bool operator==(const iterator_base &rhs) const
iterator_base(iterator_type i, container_type *m)
iter_types::container_type container_type
pointer operator->() const
bool operator!=(const iterator_base &rhs) const
iter_types::iterator_type iterator_type
iterator_base operator++(int)
iterator_type i_
local iterator
void dec()
Decrement the reference counter Delete the umap entry if the unit is gone and the reference counter i...
container_type * tank_
the unit_map for i_
pointer get_shared_ptr() const
This is exactly the same as operator-> but it's slightly more readable, and can replace &*iter syntax...
void inc()
Increment the reference counter.
bool valid_ref_count() const
unit_map::umap::iterator iterator_type
The pointer to the unit and a reference counter to record the number of extant iteratorspointing to t...
n_ref_counter::ref_counter< signed int > ref_count
void swap(unit_map &lhs, unit_map &rhs)
Implement non-member swap function for std::swap (calls unit_map::swap).