26 #include <unordered_map> 118 typedef std::map<std::size_t, unit_pod>
umap;
121 typedef std::unordered_map<map_location, umap::iterator>
lmap;
140 template<
typename iter_types>
211 return i_->second.unit;
227 return *i_->second.unit;
232 assert(valid_entry());
234 iterator_type new_i(i_);
237 }
while((new_i != the_map().
end()) && (!new_i->second.unit));
254 assert(tank_ && i_ != the_map().
begin());
260 }
while(i_ != begin && (!i_->second.unit));
276 return (valid_for_dereference() && i_->second.unit);
279 explicit operator bool()
const 286 return (tank_ == rhs.
tank_) && (i_ == rhs.
i_);
300 return (tank_ !=
nullptr) && (i_ != the_map().end());
305 return ((tank_ !=
nullptr) && (i_ != the_map().
end()));
310 if((tank_ !=
nullptr) && i_ != the_map().
end()) {
311 assert(i_->second.ref_count > 0);
317 return (tank_ !=
nullptr) && (i_ != the_map().end());
323 if(valid_ref_count()) {
324 ++(i_->second.ref_count);
336 if(valid_ref_count()) {
337 assert(i_->second.ref_count != 0);
338 if((--(i_->second.ref_count) == 0) && (!i_->second.unit)) {
339 iterator_type old = i_++;
340 tank_->umap_.erase(old);
374 unit_iterator
find(std::size_t
id);
382 const_unit_iterator
find(std::size_t
id)
const 390 auto res =
find(val);
397 auto res =
find(val);
412 std::vector<const_unit_iterator>
find_leaders(
int side)
const;
416 return lmap_.count(loc);
434 const_unit_iterator
end()
const 448 return lmap_.empty();
451 void clear(
bool force =
false);
518 std::size_t
erase(
const T& iter);
548 return is_found(i) && (i->second.unit !=
nullptr);
553 return is_found(i) && (i->second->second.unit !=
nullptr);
558 return i !=
umap_.end();
563 return i !=
lmap_.end();
604 assert(iter.valid());
606 return erase(iter->get_location());
iterator_base(lmap::iterator ui, container_type *m)
Constructs an iterator from the location map.
iter_types::container_type container_type
unit_const_ptr find_unit_ptr(const T &val) const
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)
bool valid_ref_count() const
iterator_base< standard_iter_types > unit_iterator
This class represents a single unit of a specific type.
unit_map & operator=(const unit_map &that)
umap_retval_pair_t insert(unit_ptr p)
Inserts the unit pointed to by p into the map.
unit_iterator find_leader(int side)
iter_types::iterator_type iterator_type
std::map< std::size_t, unit_pod > umap
pointer operator->() const
std::size_t erase(const map_location &l)
Erases the unit at location l, if any.
unit_map::unit_iterator make_unit_iterator(const X &i)
unit_map const container_type
iterator_base< const_iter_types > const_unit_iterator
std::shared_ptr< unit > unit_ptr
bool is_found(const lmap::const_iterator &i) const
unit_ptr find_unit_ptr(const T &val)
std::shared_ptr< const unit > unit_const_ptr
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(const iterator_base &that)
std::unordered_map< map_location, umap::iterator > lmap
Map of location to umap iterator.
const_unit_iterator const_iterator
umap_retval_pair_t add(const map_location &l, const unit &u)
Adds a copy of unit u at location l of the map.
bool valid_for_dereference() const
iterator_base & operator=(const iterator_base &that)
iterator_base operator--(int)
void clear(bool force=false)
const_unit_iterator find(std::size_t id) const
unit_map::umap::iterator iterator_type
std::pair< unit_iterator, bool > umap_retval_pair_t
umap_retval_pair_t move(const map_location &src, const map_location &dst)
Moves a unit from location src to location dst.
bool operator!=(const iterator_base &rhs) const
iterator_base(iterator_type i, container_type *m)
std::size_t count(const map_location &loc) const
umap::iterator begin_core() const
Encapsulates the map of the game.
unit_map::umap & the_map() const
reference operator*() const
unit_iterator find(std::size_t id)
pointer get_shared_ptr() const
This is exactly the same as operator-> but it's slightly more readable, and can replace &*iter syntax...
unit_iterator find_first_leader(int side)
unit_map::umap::iterator iterator_type
std::size_t num_iters() const
iterator_base & operator--()
void inc()
Increment the reference counter.
bool operator==(const config &a, const config &b)
iterator_base & operator++()
bool operator==(const iterator_base &rhs) const
iterator_type i_
local iterator
const_unit_iterator begin() const
The pointer to the unit and a reference counter to record the number of extant iteratorspointing to t...
bool has_unit_at(const map_location &loc) const
Tests whether a unit exists at the given location.
bool self_check() const
Checks invariants.
std::forward_iterator_tag iterator_category
container_type * tank_
the unit_map for i_
unit_ptr extract(const map_location &loc)
Extracts a unit from the map.
n_ref_counter::ref_counter< signed int > ref_count
lmap lmap_
location -> umap::iterator.
unit_map::const_unit_iterator make_const_unit_iterator(const X &i) const
Container associating units to locations.
bool is_found(const umap::const_iterator &i) const
const_unit_iterator end() const
bool is_valid(const lmap::const_iterator &i) const
umap umap_
underlying_id -> unit_pod.
std::shared_ptr< value_type > pointer
bool is_valid(const umap::const_iterator &i) const
iter_types::value_type value_type
iterator_base operator++(int)
std::string::const_iterator iterator
const_unit_iterator find(const map_location &loc) const
bool has_unit(const unit *const u) const
Is the unit in the map?
const_unit_iterator find_leader(int side) const