The Battle for Wesnoth  1.19.0-dev
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
unit_map Class Reference

Container associating units to locations. More...

#include <map.hpp>

Classes

struct  const_iter_types
 
struct  iterator_base
 
struct  standard_iter_types
 
struct  unit_pod
 The pointer to the unit and a reference counter to record the number of extant iteratorspointing to this unit. More...
 

Public Types

typedef iterator_base< standard_iter_typesunit_iterator
 
typedef iterator_base< const_iter_typesconst_unit_iterator
 
typedef unit_iterator iterator
 
typedef const_unit_iterator const_iterator
 
using umap_retval_pair_t = std::pair< unit_iterator, bool >
 

Public Member Functions

 unit_map ()
 
 unit_map (const unit_map &that)
 
unit_mapoperator= (const unit_map &that)
 
 ~unit_map ()
 
void swap (unit_map &o)
 
unit_iterator find (std::size_t id)
 
unit_iterator find (const map_location &loc)
 
const_unit_iterator find (const map_location &loc) const
 
const_unit_iterator find (std::size_t id) const
 
template<typename T >
unit_ptr find_unit_ptr (const T &val)
 
template<typename T >
unit_const_ptr find_unit_ptr (const T &val) const
 
unit_iterator find_leader (int side)
 
const_unit_iterator find_leader (int side) const
 
unit_iterator find_first_leader (int side)
 
std::vector< unit_iteratorfind_leaders (int side)
 
std::vector< const_unit_iteratorfind_leaders (int side) const
 
std::size_t count (const map_location &loc) const
 
unit_iterator begin ()
 
const_unit_iterator begin () const
 
unit_iterator end ()
 
const_unit_iterator end () const
 
std::size_t size () const
 
std::size_t num_iters () const
 
bool empty () const
 
void clear (bool force=false)
 
umap_retval_pair_t add (const map_location &l, const unit &u)
 Adds a copy of unit u at location l of the map. More...
 
umap_retval_pair_t insert (unit_ptr p)
 Inserts the unit pointed to by p into the map. More...
 
umap_retval_pair_t move (const map_location &src, const map_location &dst)
 Moves a unit from location src to location dst. More...
 
umap_retval_pair_t replace (const map_location &l, unit_ptr p)
 Works like unit_map::add; but l is emptied first, if needed. More...
 
std::size_t erase (const map_location &l)
 Erases the unit at location l, if any. More...
 
template<typename T >
std::size_t erase (const T &iter)
 Erases a unit given by a pointer or an iterator. More...
 
unit_ptr extract (const map_location &loc)
 Extracts a unit from the map. More...
 
bool self_check () const
 Checks invariants. More...
 
bool has_unit (const unit *const u) const
 Is the unit in the map? More...
 
bool has_unit_at (const map_location &loc) const
 Tests whether a unit exists at the given location. More...
 

Private Types

typedef std::map< std::size_t, unit_podumap
 
typedef std::unordered_map< map_location, umap::iterator > lmap
 Map of location to umap iterator. More...
 

Private Member Functions

umap::iterator begin_core () const
 
bool is_valid (const umap::const_iterator &i) const
 
bool is_valid (const lmap::const_iterator &i) const
 
bool is_found (const umap::const_iterator &i) const
 
bool is_found (const lmap::const_iterator &i) const
 
template<typename X >
unit_map::unit_iterator make_unit_iterator (const X &i)
 
template<typename X >
unit_map::const_unit_iterator make_const_unit_iterator (const X &i) const
 

Private Attributes

umap umap_
 underlying_id -> unit_pod. More...
 
lmap lmap_
 location -> umap::iterator. More...
 

Detailed Description

Container associating units to locations.

The indirection location -> underlying_id -> unit ensures that iterators stay valid even if WML modifies or moves units on the fly. They even stay valid if a unit is erased from the map and another unit with the same underlying id is inserted in the map. In other words, it is a doubly indexed ordered map with persistent iterators (that never invalidate).

Note
The unit_map is implemented as 2 maps: an unordered map that stores iterators from the ordered map of reference-counted pointers to units.

The unordered map provides O(1) find times. The ordered map ensures ordering of units by underlying_id. The reference counting is what guarantees the persistent iterators. Storing an iterator only prevents that dead unit's id-map entry from being recovered.

Note
Preferred usages for tight loops follows:

Use the std::pair<iterator, bool> format which checks the preconditions and returns false (second) to indicate failure and no change to the unit_map. True indicates success along with the new iterator (first).

Storing the result iterator prevents the old iterator from entering the fallback recovery code. This is faster than the old methodology of find to check if empty, insert, and then find to check for success. It is the same method as std::map uses, the C++ way.


unit_iterator i; //results are stored here

ADD: std::pair<unit_iterator, bool> try_add(units->add(loc, unit)); if(try_add.second) { i = try_add.first; }

MOVE: std::pair<unit_iterator, bool> try_add(units->move(src, dst)); if(try_add.second) { i = try_add.first; }

INSERT: std::pair<unit_iterator, bool> try_add(units->insert(unitp)); if(try_add.second) { i = try_add.first; }

REPLACE (preferred over erase and then add) std::pair<unit_iterator, bool> try_add(units->move(loc, unit)); if(try_add.second){ i = try_add.first; }


Note
The previous implementation was 2 binary tree based maps: a location map pointing to another. Lookups were O(2*log(N)) and O(log(N)). Order was implicit in the id map chosen as the base. Persistence was provided by reference counting all iterators collectively and only recovering space when there were no iterators outstanding. Even 1 iterator being stored caused a leak, because all space for dead units was not recovered.
Units are owned by the container.
The indirection does not involve map lookups whenever an iterator is dereferenced, it just causes a pointer indirection. The downside is that incrementing iterators is not O(1).
The code does not involve any magic, so units moved while being iterated upon may be skipped or visited twice.
Iterators prevent ghost units from being collected, so they should never be stored in data structures, as it will cause slowdowns!
By popular demand iterators are effectively permanent. They are handles and not iterators. Any access might cause a full lookup. Keeping iterators around holds onto memory.

Definition at line 97 of file map.hpp.

Member Typedef Documentation

◆ const_iterator

Definition at line 371 of file map.hpp.

◆ const_unit_iterator

Definition at line 367 of file map.hpp.

◆ iterator

Definition at line 370 of file map.hpp.

◆ lmap

typedef std::unordered_map<map_location, umap::iterator> unit_map::lmap
private

Map of location to umap iterator.

Definition at line 120 of file map.hpp.

◆ umap

typedef std::map<std::size_t, unit_pod> unit_map::umap
private

Definition at line 117 of file map.hpp.

◆ umap_retval_pair_t

using unit_map::umap_retval_pair_t = std::pair<unit_iterator, bool>

Definition at line 452 of file map.hpp.

◆ unit_iterator

Definition at line 366 of file map.hpp.

Constructor & Destructor Documentation

◆ unit_map() [1/2]

unit_map::unit_map ( )

Definition at line 29 of file map.cpp.

◆ unit_map() [2/2]

unit_map::unit_map ( const unit_map that)

Definition at line 35 of file map.cpp.

References add().

◆ ~unit_map()

unit_map::~unit_map ( )

Definition at line 59 of file map.cpp.

References clear().

Member Function Documentation

◆ add()

unit_map::umap_retval_pair_t unit_map::add ( const map_location l,
const unit u 
)

Adds a copy of unit u at location l of the map.

Returns
A pair consisting of an iterator pointing to the new unit (or the unit already occupying that location) and a bool indicating success.
Note
It is 3 times as fast to attempt to insert a unit at l and check for success than it is to verify that the location is empty, insert the unit, and then check the location for the unit.

Definition at line 76 of file map.cpp.

References unit::clone(), insert(), p, and self_check().

Referenced by BOOST_AUTO_TEST_CASE(), editor::editor_action_unit::perform_without_undo(), temporary_unit_placer::temporary_unit_placer(), and unit_map().

◆ begin() [1/2]

unit_iterator unit_map::begin ( )
inline

◆ begin() [2/2]

const_unit_iterator unit_map::begin ( ) const
inline

Definition at line 423 of file map.hpp.

References begin_core(), and make_const_unit_iterator().

◆ begin_core()

unit_map::umap::iterator unit_map::begin_core ( ) const
private

Definition at line 64 of file map.cpp.

References i, self_check(), and umap_.

Referenced by begin().

◆ clear()

void unit_map::clear ( bool  force = false)

Definition at line 244 of file map.cpp.

References DBG_NG, i, is_valid(), lmap_, num_iters(), and umap_.

Referenced by ~unit_map().

◆ count()

std::size_t unit_map::count ( const map_location loc) const
inline

◆ empty()

bool unit_map::empty ( ) const
inline

Definition at line 445 of file map.hpp.

References lmap_.

Referenced by editor::editor_controller::can_execute_command().

◆ end() [1/2]

unit_iterator unit_map::end ( )
inline

Definition at line 428 of file map.hpp.

References make_unit_iterator(), and umap_.

Referenced by unit::ability_active(), ai::ai_default_rca::move_to_targets_phase::access_points(), scoped_xy_unit::activate(), ai::attack_analysis::analyze(), wb::move::apply_temp_modifier(), backstab_check(), BOOST_AUTO_TEST_CASE(), ai::readonly_context_impl::calculate_moves(), editor::editor_controller::can_execute_command(), editor::editor_controller::change_unit_id(), actions::check_recall_location(), actions::check_recruit_location(), ai::ai_default_rca::move_to_targets_phase::choose_move(), actions::shroud_clearer::clear_unit(), editor::mouse_action_unit::click_left(), wfl::attack_map_callable::collect_possible_attacks(), ai::default_ai_context_impl::count_free_hexes_in_castle(), events::mouse_handler::cycle_units(), ai::ai_default_rca::aspect_attacks_base::do_attack_analysis(), ai::stage_unit_formulas::do_play_stage(), editor::mouse_action_unit::drag_end_left(), display::draw_invalidated(), game_display::draw_movement_info(), ai::ai_default_rca::goto_phase::evaluate(), ai::ai_default_rca::get_healing_phase::evaluate(), ai::ai_default_rca::retreat_phase::evaluate(), wfl::move_candidate_action::evaluate(), wfl::attack_candidate_action::evaluate(), ai::ai_default_rca::get_villages_phase::execute(), wfl::set_unit_var_callable::execute_self(), ai::attack_analysis::execute_self(), unit_filter_impl::unit_filter_compound::fill(), find_first_leader(), find_leader(), find_leaders(), ai::default_ai_context_impl::find_targets(), events::mouse_handler::find_unit(), find_unit_ptr(), pathfind::find_vacant_tile(), game_board::find_visible_unit(), actions::shroud_clearer::fire_events(), unit_filter::first_match_on_map(), footsteps_images(), ai::ai_default_rca::move_to_targets_phase::form_group(), unit::get_abilities(), unit::get_ability_bool(), tod_manager::get_illuminated_time_of_day(), gui2::dialogs::game_stats::get_leader(), actions::get_recalls(), actions::get_recruits(), gui2::dialogs::get_title_suffix(), ai::formula_ai::get_value(), ai::ai_default_rca::get_villages_phase::get_villages(), game_board::get_visible_unit(), unit::halo_or_icon_abilities(), has_unit_at(), attack_type::has_weapon_ability(), impl_unit_type_next(), ai::default_recruitment::recruitment::is_enemy_in_radius(), editor::mouse_action_unit::move(), ai::ai_default_rca::move_to_targets_phase::move_group(), actions::move_unit_and_record(), wb::manager::on_mouseover_change(), game_events::filter_attack::operator()(), unit_map::iterator_base< iter_types >::operator++(), editor::editor_action_unit_delete::perform(), editor::editor_action_unit_facing::perform_without_undo(), ai::readonly_context_impl::power_projection(), ai::ai_default_rca::move_to_targets_phase::rate_group(), editor::editor_controller::rename_unit(), game_board::replace_map(), actions::move_unit_spectator::reset(), actions::undo::reset_adjacent(), unit_display::reset_helpers(), events::mouse_handler::select_hex(), ai::formula_ai::shortest_path_calculator(), gui2::dialogs::unit_mode_controller::show_list(), gui2::dialogs::show_unit_list(), gui2::dialogs::team_mode_controller::show_units(), game_state::side_can_recruit_on(), attack_type::special_active_impl(), actions::undo::move_action::undo(), actions::undo::recall_action::undo(), actions::undo::recruit_action::undo(), editor::editor_controller::unit_description(), unit_display::unit_recruited(), unit_map::iterator_base< iter_types >::valid_entry(), unit_map::iterator_base< iter_types >::valid_exit(), verify(), and attack_type::weapon_specials_impl_adj().

◆ end() [2/2]

const_unit_iterator unit_map::end ( ) const
inline

Definition at line 433 of file map.hpp.

References make_const_unit_iterator(), and umap_.

◆ erase() [1/2]

std::size_t unit_map::erase ( const map_location l)

◆ erase() [2/2]

template<typename T >
std::size_t unit_map::erase ( const T &  iter)

Erases a unit given by a pointer or an iterator.

Precondition
The unit is on the map.

Definition at line 601 of file map.hpp.

References erase().

◆ extract()

unit_ptr unit_map::extract ( const map_location loc)

Extracts a unit from the map.

The unit is no longer owned by the map. It can be reinserted later, if needed.

Definition at line 259 of file map.cpp.

References DBG_NG, i, lmap_, self_check(), and umap_.

Referenced by ai::attack_analysis::analyze(), wb::suppose_dead::apply_temp_modifier(), BOOST_AUTO_TEST_CASE(), erase(), game_lua_kernel::intf_extract_unit(), wb::recall::remove_temp_modifier(), and wb::recruit::remove_temp_modifier().

◆ find() [1/4]

unit_map::unit_iterator unit_map::find ( const map_location loc)

Definition at line 314 of file map.cpp.

References lmap_, and self_check().

◆ find() [2/4]

const_unit_iterator unit_map::find ( const map_location loc) const
inline

Definition at line 376 of file map.hpp.

References find().

◆ find() [3/4]

unit_map::unit_iterator unit_map::find ( std::size_t  id)

Definition at line 302 of file map.cpp.

References i, self_check(), and umap_.

Referenced by unit::ability_active(), ai::ai_default_rca::move_to_targets_phase::access_points(), scoped_xy_unit::activate(), unit_creator::add_unit(), replay::add_unit_checksum(), advance_unit(), ai::attack_analysis::analyze(), wb::move::apply_temp_modifier(), attack_unit_and_advance(), backstab_check(), battle_context::battle_context(), ai::readonly_context_impl::best_defensive_position(), BOOST_AUTO_TEST_CASE(), editor::editor_controller::can_execute_command(), editor::editor_controller::change_unit_id(), ai::readonly_context_impl::check_attack_action(), actions::check_recall_location(), actions::check_recruit_location(), wb::move::check_validity(), wb::suppose_dead::check_validity(), ai::ai_default_rca::move_to_targets_phase::choose_move(), actions::shroud_clearer::clear_unit(), editor::mouse_action_unit::click_left(), wfl::attack_map_callable::collect_possible_attacks(), ai::default_ai_context_impl::count_free_hexes_in_castle(), wfl::gamestate::DEFINE_WFL_FUNCTION(), ai::ai_default_rca::aspect_attacks_base::do_attack_analysis(), ai::recall_result::do_check_after(), ai::recruit_result::do_check_after(), ai::stopunit_result::do_check_after(), ai::attack_result::do_check_before(), ai::attack_result::do_execute(), ai::move_result::do_execute(), ai::stopunit_result::do_execute(), editor::editor_controller::do_execute_command(), do_replay_handle(), editor::mouse_action_unit::drag_end_left(), display::draw_invalidated(), game_display::draw_movement_info(), ai::ai_default_rca::goto_phase::evaluate(), ai::ai_default_rca::combat_phase::evaluate(), ai::ai_default_rca::move_leader_to_keep_phase::evaluate(), ai::ai_default_rca::get_healing_phase::evaluate(), ai::ai_default_rca::get_villages_phase::execute(), ai::ai_default_rca::leader_shares_keep_phase::execute(), wb::attack::execute(), wb::move::execute(), wb::recruit::execute(), ai::readwrite_context_impl::execute_attack_action(), wfl::set_unit_var_callable::execute_self(), ai::attack_analysis::execute_self(), unit_filter_impl::unit_filter_compound::fill(), find(), game_board::find_unit(), find_unit_ptr(), pathfind::find_vacant_tile(), ai::ai_default_rca::get_villages_phase::find_villages(), game_board::find_visible_unit(), actions::shroud_clearer::fire_events(), footsteps_images(), ai::ai_default_rca::move_to_targets_phase::form_group(), lua_unit::get(), unit::get_abilities(), unit::get_ability_bool(), editor::editor_controller::get_action_state(), tod_manager::get_illuminated_time_of_day(), actions::get_recalls(), actions::get_recruits(), lua_unit::get_shared(), wb::manager::get_temp_move_unit(), ai::move_result::get_unit(), ai::stopunit_result::get_unit(), game_events::entity_location::get_unit(), wb::move::get_unit(), wb::suppose_dead::get_unit(), display_context::get_visible_unit(), display_context::get_visible_unit_shared_ptr(), unit::halo_or_icon_abilities(), has_unit_at(), game_board::has_visible_unit(), attack_type::has_weapon_ability(), ai::helper_advance_unit(), impl_unit_type_next(), game_lua_kernel::intf_find_cost_map(), game_lua_kernel::intf_find_path(), game_lua_kernel::intf_find_reach(), game_lua_kernel::intf_find_vision_range(), game_lua_kernel::intf_get_unit(), game_lua_kernel::intf_teleport(), ai::default_recruitment::recruitment::is_enemy_in_radius(), ai::lua_sticky_candidate_action_wrapper::lua_sticky_candidate_action_wrapper(), luaW_pushfaivariant(), pathfind::mark_route(), terrain_filter::match_internal(), unit_animation::matches(), wb::move::move(), editor::mouse_action_unit::move(), ai::ai_default_rca::move_to_targets_phase::move_group(), events::mouse_handler::move_unit_along_route(), actions::move_unit_and_record(), wb::manager::on_mouseover_change(), game_events::filter_unit::operator()(), game_events::filter_attack::operator()(), editor::editor_action_unit_delete::perform(), editor::editor_action_unit::perform_without_undo(), editor::editor_action_unit_replace::perform_without_undo(), editor::editor_action_unit_facing::perform_without_undo(), wb::manager::post_draw(), ai::readonly_context_impl::power_projection(), wb::manager::pre_draw(), ai::ai_default_rca::move_to_targets_phase::rate_group(), wb::move::remove_temp_modifier(), wb::suppose_dead::remove_temp_modifier(), editor::editor_controller::rename_unit(), actions::undo::reset_adjacent(), unit_display::reset_helpers(), events::mouse_handler::select_hex(), wb::highlighter::set_mouseover_hex(), ai::formula_ai::shortest_path_calculator(), events::mouse_handler::show_attack_dialog(), events::mouse_handler::show_attack_options(), game_state::side_can_recruit_on(), ai::simulated_attack(), ai::simulated_stopunit(), attack_type::special_active_impl(), wb::suppose_dead::suppose_dead(), SYNCED_COMMAND_HANDLER_FUNCTION(), pathfind::teleport_map::teleport_map(), actions::undo::move_action::undo(), actions::undo::recall_action::undo(), actions::undo::recruit_action::undo(), unit_display::unit_attack(), display_context::unit_can_move(), editor::editor_controller::unit_description(), unit_display::unit_recruited(), verify(), pathfind::vision_path::vision_path(), attack_type::weapon_specials_impl_adj(), and display_context::would_be_discovered().

◆ find() [4/4]

const_unit_iterator unit_map::find ( std::size_t  id) const
inline

Definition at line 381 of file map.hpp.

References find().

◆ find_first_leader()

unit_map::unit_iterator unit_map::find_first_leader ( int  side)

Definition at line 332 of file map.cpp.

References begin(), end(), and i.

◆ find_leader() [1/2]

unit_map::unit_iterator unit_map::find_leader ( int  side)

◆ find_leader() [2/2]

const_unit_iterator unit_map::find_leader ( int  side) const
inline

Definition at line 402 of file map.hpp.

References find_leader().

◆ find_leaders() [1/2]

std::vector< unit_map::unit_iterator > unit_map::find_leaders ( int  side)

◆ find_leaders() [2/2]

std::vector< unit_map::const_unit_iterator > unit_map::find_leaders ( int  side) const

Definition at line 362 of file map.cpp.

References find_leaders().

◆ find_unit_ptr() [1/2]

template<typename T >
unit_ptr unit_map::find_unit_ptr ( const T &  val)
inline

◆ find_unit_ptr() [2/2]

template<typename T >
unit_const_ptr unit_map::find_unit_ptr ( const T &  val) const
inline

Definition at line 394 of file map.hpp.

References end(), and find().

◆ has_unit()

bool unit_map::has_unit ( const unit *const  u) const

Is the unit in the map?

Precondition
u != nullptr
Parameters
uPointer to the unit to find.
Returns
True if found, false otherwise.

Definition at line 422 of file map.cpp.

References umap_.

◆ has_unit_at()

bool unit_map::has_unit_at ( const map_location loc) const

Tests whether a unit exists at the given location.

Definition at line 435 of file map.cpp.

References end(), and find().

◆ insert()

unit_map::umap_retval_pair_t unit_map::insert ( unit_ptr  p)

Inserts the unit pointed to by p into the map.

If insertion into either the unit or location map fails, all operations are reverted.

The one oddity is that to facilitate non-invalidating iterators, the list sometimes has nullptr pointers which should be used when they correspond to uids previously used.

Returns
A pair consisting of an iterator pointing to the new unit (or the unit already occupying that location) and a bool indicating success.
Note
It is 3 times as fast to attempt to insert a unit at l and check for success than it is to verify that the location is empty, insert the unit, and then check the location for the unit.
If the unit::underlying_id is already in use, a new one will be generated.
The map takes ownership of the pointed object only if the operation succeeds.

Definition at line 135 of file map.cpp.

References DBG_NG, ERR_NG, lmap_, make_unit_iterator(), unit::name(), p, unit_map::unit_pod::ref_count, self_check(), umap_, unit_map::unit_pod::unit, and map_location::valid().

Referenced by add(), advance_unit(), ai::attack_analysis::analyze(), wb::recall::apply_temp_modifier(), wb::recruit::apply_temp_modifier(), BOOST_AUTO_TEST_CASE(), ai::default_ai_context_impl::count_free_hexes_in_castle(), ai::default_recruitment::recruitment::do_combat_analysis(), ai::helper_place_unit(), game_lua_kernel::intf_put_unit(), editor::map_context::load_scenario(), actions::place_recruit(), wb::suppose_dead::remove_temp_modifier(), replace(), SYNCED_COMMAND_HANDLER_FUNCTION(), temporary_unit_mover::~temporary_unit_mover(), temporary_unit_placer::~temporary_unit_placer(), and temporary_unit_remover::~temporary_unit_remover().

◆ is_found() [1/2]

bool unit_map::is_found ( const lmap::const_iterator &  i) const
inlineprivate

Definition at line 560 of file map.hpp.

References i, and lmap_.

◆ is_found() [2/2]

bool unit_map::is_found ( const umap::const_iterator &  i) const
inlineprivate

Definition at line 555 of file map.hpp.

References i, and umap_.

Referenced by is_valid(), make_const_unit_iterator(), and make_unit_iterator().

◆ is_valid() [1/2]

bool unit_map::is_valid ( const lmap::const_iterator &  i) const
inlineprivate

Definition at line 550 of file map.hpp.

References i, and is_found().

◆ is_valid() [2/2]

bool unit_map::is_valid ( const umap::const_iterator &  i) const
inlineprivate

Definition at line 545 of file map.hpp.

References i, and is_found().

Referenced by clear().

◆ make_const_unit_iterator()

template<typename X >
unit_map::const_unit_iterator unit_map::make_const_unit_iterator ( const X &  i) const
inlineprivate

Definition at line 576 of file map.hpp.

References i, is_found(), and umap_.

Referenced by begin(), and end().

◆ make_unit_iterator()

template<typename X >
unit_map::unit_iterator unit_map::make_unit_iterator ( const X &  i)
inlineprivate

Definition at line 566 of file map.hpp.

References i, is_found(), and umap_.

Referenced by begin(), end(), insert(), and move().

◆ move()

unit_map::umap_retval_pair_t unit_map::move ( const map_location src,
const map_location dst 
)

Moves a unit from location src to location dst.

Returns
A pair consisting of an iterator pointing to the new unit (or the unit already occupying that location) and a bool indicating success.
Note
It is 3 times as fast to attempt to insert a unit at l and check for success than it is to verify that the location is empty, insert the unit, and then check the location for the unit.

Definition at line 92 of file map.cpp.

References DBG_NG, display::get_singleton(), i, display::invalidate(), lmap_, make_unit_iterator(), p, and self_check().

Referenced by ai::attack_analysis::analyze(), game_lua_kernel::intf_teleport(), editor::editor_action_unit_replace::perform_without_undo(), ai::simulated_move(), temporary_unit_mover::temporary_unit_mover(), actions::undo::move_action::undo(), and temporary_unit_mover::~temporary_unit_mover().

◆ num_iters()

std::size_t unit_map::num_iters ( ) const

Add up number of extant iterators

Definition at line 224 of file map.cpp.

References umap_.

Referenced by clear(), and swap().

◆ operator=()

unit_map & unit_map::operator= ( const unit_map that)

Definition at line 44 of file map.cpp.

References swap().

◆ replace()

unit_map::umap_retval_pair_t unit_map::replace ( const map_location l,
unit_ptr  p 
)

Works like unit_map::add; but l is emptied first, if needed.

Returns
A pair consisting of an iterator pointing to the new unit (or the unit already occupying that location) and a bool indicating success.

Definition at line 216 of file map.cpp.

References erase(), insert(), p, and self_check().

Referenced by unit_creator::add_unit(), ai::helper_advance_unit(), lua_unit::put_map(), and SYNCED_COMMAND_HANDLER_FUNCTION().

◆ self_check()

bool unit_map::self_check ( ) const

Checks invariants.

For debugging purposes only. Doesn't do anything in non-debug mode.

Definition at line 370 of file map.cpp.

References ERR_NG, good, lmap_, and umap_.

Referenced by add(), begin_core(), erase(), extract(), find(), insert(), move(), and replace().

◆ size()

std::size_t unit_map::size ( ) const
inline

Definition at line 438 of file map.hpp.

References lmap_.

Referenced by BOOST_AUTO_TEST_CASE(), and verify().

◆ swap()

void unit_map::swap ( unit_map o)

Definition at line 51 of file map.cpp.

References lmap_, num_iters(), swap(), and umap_.

Referenced by operator=(), and swap().

Member Data Documentation

◆ lmap_

lmap unit_map::lmap_
private

location -> umap::iterator.

Definition at line 594 of file map.hpp.

Referenced by clear(), count(), empty(), extract(), find(), insert(), is_found(), move(), self_check(), size(), and swap().

◆ umap_

umap unit_map::umap_
mutableprivate

underlying_id -> unit_pod.

This requires that underlying_id be unique (which is enforced in unit_map::insert).

Definition at line 589 of file map.hpp.

Referenced by begin_core(), clear(), end(), extract(), find(), has_unit(), insert(), is_found(), make_const_unit_iterator(), make_unit_iterator(), num_iters(), self_check(), and swap().


The documentation for this class was generated from the following files: