Holds a temporary unit that can be drawn on the map without being placed in the unit_map. More...
#include <fake_unit_ptr.hpp>
Public Types | |
typedef unit_ptr | internal_ptr |
typedef unit_const_ptr | internal_const_ptr |
Public Member Functions | |
fake_unit_ptr () | |
fake_unit_ptr (const internal_ptr &u) | |
Construct a fake unit pointer wrapping a normal unit pointer, marking it as a fake unit. More... | |
fake_unit_ptr (const internal_ptr &u, fake_unit_manager *mgr) | |
Construct a fake unit pointer, and simultaenously register with a manager. More... | |
fake_unit_ptr (const fake_unit_ptr &ptr) | |
Copy construct a fake unit pointer. Does not reallocate the underlying unit. More... | |
void | swap (fake_unit_ptr &o) |
Pointer swap. More... | |
fake_unit_ptr & | operator= (fake_unit_ptr other) |
Copy assignment operator using copy-and-swap idiom. More... | |
void | reset () |
Reset the internal unit pointer, and deregister from the manager. This fake_unit_ptr is now dissassociated from the manager. More... | |
void | reset (const internal_ptr &ptr) |
Reset the internal unit pointer and point to a new unit. The old unit is deregistered, and the new unit is registered with the old manager, if there was one. More... | |
internal_ptr | operator-> () |
Dereference the internal unit pointer. More... | |
internal_const_ptr | operator-> () const |
Dereference the internal unit pointer. More... | |
internal_ptr | get_unit_ptr () |
Get a copy of the internal unit pointer. More... | |
internal_const_ptr | get_unit_ptr () const |
Get a copy of the internal unit pointer. More... | |
unit & | operator* () |
Derference the internal unit pointer. More... | |
unit * | get () |
Get a raw pointer to the underlying unit. More... | |
~fake_unit_ptr () | |
Removes this from the fake_units_ list if necessary. More... | |
void | place_on_fake_unit_manager (fake_unit_manager *d) |
Place this on manager's fake_units_ dequeue. More... | |
int | remove_from_fake_unit_manager () |
Removes this from whatever fake_units_ list it is on (if any). More... | |
operator bool () const | |
Private Attributes | |
internal_ptr | unit_ |
Internal unit pointer. More... | |
fake_unit_manager * | my_manager_ |
Raw pointer to the manager. More... | |
Holds a temporary unit that can be drawn on the map without being placed in the unit_map.
Temporary units can overlap units. They are drawn after the normal units, and so draw over them. Adding the same unit twice isn't allowed. The fake_unit privately holds a referenced counted point to its underlying unit, when it goes out of scope it removes the entry from the fake_units list. The intent is to provide exception safety when the code creating the temp unit is unexpectedly forced out of scope.
Definition at line 32 of file fake_unit_ptr.hpp.
Definition at line 35 of file fake_unit_ptr.hpp.
typedef unit_ptr fake_unit_ptr::internal_ptr |
Definition at line 34 of file fake_unit_ptr.hpp.
fake_unit_ptr::fake_unit_ptr | ( | ) |
Definition at line 23 of file fake_unit_ptr.cpp.
|
explicit |
Construct a fake unit pointer wrapping a normal unit pointer, marking it as a fake unit.
Definition at line 24 of file fake_unit_ptr.cpp.
fake_unit_ptr::fake_unit_ptr | ( | const internal_ptr & | u, |
fake_unit_manager * | mgr | ||
) |
Construct a fake unit pointer, and simultaenously register with a manager.
Definition at line 25 of file fake_unit_ptr.cpp.
References place_on_fake_unit_manager().
fake_unit_ptr::fake_unit_ptr | ( | const fake_unit_ptr & | ptr | ) |
Copy construct a fake unit pointer. Does not reallocate the underlying unit.
Definition at line 29 of file fake_unit_ptr.cpp.
fake_unit_ptr::~fake_unit_ptr | ( | ) |
Removes this from the fake_units_ list if necessary.
Definition at line 99 of file fake_unit_ptr.cpp.
References my_manager_, and remove_from_fake_unit_manager().
|
inline |
Get a raw pointer to the underlying unit.
Definition at line 56 of file fake_unit_ptr.hpp.
References unit_.
Referenced by unit_display::unit_mover::finish(), unit_display::unit_mover::start(), and game_events::WML_HANDLER_FUNCTION().
|
inline |
Get a copy of the internal unit pointer.
Definition at line 52 of file fake_unit_ptr.hpp.
References unit_.
Referenced by wb::manager::create_temp_move(), wb::move::move(), unit_display::unit_mover::proceed_to(), and game_events::WML_HANDLER_FUNCTION().
|
inline |
Get a copy of the internal unit pointer.
Definition at line 53 of file fake_unit_ptr.hpp.
References unit_.
|
inlineexplicit |
Definition at line 72 of file fake_unit_ptr.hpp.
|
inline |
Derference the internal unit pointer.
Definition at line 55 of file fake_unit_ptr.hpp.
References unit_.
|
inline |
Dereference the internal unit pointer.
Definition at line 49 of file fake_unit_ptr.hpp.
References unit_.
|
inline |
Dereference the internal unit pointer.
Definition at line 50 of file fake_unit_ptr.hpp.
References unit_.
fake_unit_ptr & fake_unit_ptr::operator= | ( | fake_unit_ptr | other | ) |
Copy assignment operator using copy-and-swap idiom.
Definition at line 36 of file fake_unit_ptr.cpp.
References swap().
void fake_unit_ptr::place_on_fake_unit_manager | ( | fake_unit_manager * | manager | ) |
Place this on manager's fake_units_ dequeue.
This will be added at the end (drawn last, over all other units). Duplicate additions are not allowed.
Definition at line 115 of file fake_unit_ptr.cpp.
References my_manager_, fake_unit_manager::place_temporary_unit(), and unit_.
Referenced by fake_unit_ptr(), wb::recall::init(), wb::recruit::init(), reset(), and game_events::WML_HANDLER_FUNCTION().
int fake_unit_ptr::remove_from_fake_unit_manager | ( | ) |
Removes this from whatever fake_units_ list it is on (if any).
Definition at line 126 of file fake_unit_ptr.cpp.
References my_manager_, fake_unit_manager::remove_temporary_unit(), and unit_.
Referenced by reset(), and ~fake_unit_ptr().
void fake_unit_ptr::reset | ( | ) |
Reset the internal unit pointer, and deregister from the manager. This fake_unit_ptr is now dissassociated from the manager.
Assignment operator, taking a unit.
If already in the queue, this will be moved to the end of the queue (drawn last).
This function is unsuitable for derived classes and MUST be overridden. Furthermore, derived classes must not explicitly call this version.
The overriding function can be almost the same, except "new (this)" should be followed by the derived class instead of "fake_unit(a)". Removes the unit from the fake manager, and resets the internal unit pointer. After this, both pointers are null.
Definition at line 73 of file fake_unit_ptr.cpp.
References remove_from_fake_unit_manager(), and unit_.
Referenced by wb::manager::create_temp_move(), wb::recall::recall(), and wb::recruit::recruit().
void fake_unit_ptr::reset | ( | const internal_ptr & | ptr | ) |
Reset the internal unit pointer and point to a new unit. The old unit is deregistered, and the new unit is registered with the old manager, if there was one.
Resets the internal unit pointer to match the given pointer.
The value of my_manager_ is preserved – the old unit is deregistered, and the new unit is registered with the same manager.
Definition at line 84 of file fake_unit_ptr.cpp.
References my_manager_, place_on_fake_unit_manager(), remove_from_fake_unit_manager(), and unit_.
void fake_unit_ptr::swap | ( | fake_unit_ptr & | o | ) |
Pointer swap.
Definition at line 31 of file fake_unit_ptr.cpp.
References my_manager_, swap(), and unit_.
Referenced by operator=().
|
private |
Raw pointer to the manager.
Definition at line 68 of file fake_unit_ptr.hpp.
Referenced by place_on_fake_unit_manager(), remove_from_fake_unit_manager(), reset(), swap(), and ~fake_unit_ptr().
|
private |
Internal unit pointer.
Definition at line 67 of file fake_unit_ptr.hpp.
Referenced by get(), get_unit_ptr(), operator*(), operator->(), place_on_fake_unit_manager(), remove_from_fake_unit_manager(), reset(), and swap().