wesnoth/wesnoth — pull request #222 by cbeck88 (2014-06-24 15:37:33+00:00)
Title: *DONT MERGE* Factor out the unit_pod from unit_map

This commit attempts to cleanup and simplify the unit_map
further. After this commit, unit_pods are removed and
instead the unit_map is based on the "universal" reference
counted pointer (UnitPtr).

However this also changes the guarantee of iterators and
when they are invalidated. Formerly, iterators *never*
invalidate. After this commit, they never invalidate for
*dereference* but they may invalidate for increment
if the unit they refer to is extracted from the map. Thus
code along the following lines:

BOOST_FOREACH( unit & u , *resources::units ) {
if (...) {
resources::units->extract(u.get_location());
...
}
}

will likely segfault, because it does not "preincrement" the iterator before deleting the object.

The unit_pod system effectively prevented any deletions from occurring in the unit_map
internal data structures until there are no iterators pointing at the relevant node. Some kind
of reference counting is probably necessary for this behavior, so the approach here should
perhaps be reconsidered.