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

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. More...
 
 fake_unit_ptr (fake_unit_ptr &&ptr)
 
void swap (fake_unit_ptr &o)
 Pointer swap. More...
 
fake_unit_ptroperator= (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. More...
 
void reset (const internal_ptr &ptr)
 Reset the internal unit pointer and point to a new unit. 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...
 
unitoperator* ()
 Derference the internal unit pointer. More...
 
unitget ()
 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_managermy_manager_
 Raw pointer to the manager. More...
 

Detailed Description

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.

Member Typedef Documentation

◆ internal_const_ptr

Definition at line 35 of file fake_unit_ptr.hpp.

◆ internal_ptr

Definition at line 34 of file fake_unit_ptr.hpp.

Constructor & Destructor Documentation

◆ fake_unit_ptr() [1/5]

fake_unit_ptr::fake_unit_ptr ( )

Definition at line 22 of file fake_unit_ptr.cpp.

◆ fake_unit_ptr() [2/5]

fake_unit_ptr::fake_unit_ptr ( const internal_ptr u)
explicit

Construct a fake unit pointer wrapping a normal unit pointer, marking it as a fake unit.

Definition at line 23 of file fake_unit_ptr.cpp.

◆ fake_unit_ptr() [3/5]

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 24 of file fake_unit_ptr.cpp.

References place_on_fake_unit_manager().

◆ fake_unit_ptr() [4/5]

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 28 of file fake_unit_ptr.cpp.

◆ fake_unit_ptr() [5/5]

fake_unit_ptr::fake_unit_ptr ( fake_unit_ptr &&  ptr)

Definition at line 33 of file fake_unit_ptr.cpp.

◆ ~fake_unit_ptr()

fake_unit_ptr::~fake_unit_ptr ( )

Removes this from the fake_units_ list if necessary.

Definition at line 108 of file fake_unit_ptr.cpp.

References resources::fake_units, my_manager_, and remove_from_fake_unit_manager().

Member Function Documentation

◆ get()

unit* fake_unit_ptr::get ( )
inline

Get a raw pointer to the underlying unit.

Definition at line 70 of file fake_unit_ptr.hpp.

References unit_.

Referenced by game_events::WML_HANDLER_FUNCTION().

◆ get_unit_ptr() [1/2]

internal_ptr fake_unit_ptr::get_unit_ptr ( )
inline

◆ get_unit_ptr() [2/2]

internal_const_ptr fake_unit_ptr::get_unit_ptr ( ) const
inline

Get a copy of the internal unit pointer.

Definition at line 65 of file fake_unit_ptr.hpp.

References unit_.

◆ operator bool()

fake_unit_ptr::operator bool ( ) const
inlineexplicit

Definition at line 88 of file fake_unit_ptr.hpp.

References unit_.

◆ operator*()

unit& fake_unit_ptr::operator* ( )
inline

Derference the internal unit pointer.

Definition at line 68 of file fake_unit_ptr.hpp.

References unit_.

◆ operator->() [1/2]

internal_ptr fake_unit_ptr::operator-> ( )
inline

Dereference the internal unit pointer.

Definition at line 58 of file fake_unit_ptr.hpp.

References unit_.

◆ operator->() [2/2]

internal_const_ptr fake_unit_ptr::operator-> ( ) const
inline

Dereference the internal unit pointer.

Definition at line 60 of file fake_unit_ptr.hpp.

References unit_.

◆ operator=()

fake_unit_ptr & fake_unit_ptr::operator= ( fake_unit_ptr  other)

Copy assignment operator using copy-and-swap idiom.

Definition at line 45 of file fake_unit_ptr.cpp.

References swap().

◆ place_on_fake_unit_manager()

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 129 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().

◆ remove_from_fake_unit_manager()

int fake_unit_ptr::remove_from_fake_unit_manager ( )

Removes this from whatever fake_units_ list it is on (if any).

Returns
the number of fake_units deleted, which should be 0 or 1 (any other number indicates an error).

Definition at line 140 of file fake_unit_ptr.cpp.

References my_manager_, fake_unit_manager::remove_temporary_unit(), and unit_.

Referenced by reset(), and ~fake_unit_ptr().

◆ reset() [1/2]

void fake_unit_ptr::reset ( )

Reset the internal unit pointer, and deregister from the manager.

Assignment operator, taking a unit.

This fake_unit_ptr is now dissassociated from the manager.

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 82 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().

◆ reset() [2/2]

void fake_unit_ptr::reset ( const internal_ptr ptr)

Reset the internal unit pointer and point to a new unit.

Resets the internal unit pointer to match the given pointer.

The old unit is deregistered, and the new unit is registered with the old manager, if there was one.

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 93 of file fake_unit_ptr.cpp.

References my_manager_, place_on_fake_unit_manager(), remove_from_fake_unit_manager(), and unit_.

◆ swap()

void fake_unit_ptr::swap ( fake_unit_ptr o)

Pointer swap.

Definition at line 40 of file fake_unit_ptr.cpp.

References my_manager_, swap(), and unit_.

Referenced by operator=().

Member Data Documentation

◆ my_manager_

fake_unit_manager* fake_unit_ptr::my_manager_
private

Raw pointer to the manager.

Definition at line 84 of file fake_unit_ptr.hpp.

Referenced by place_on_fake_unit_manager(), remove_from_fake_unit_manager(), reset(), swap(), and ~fake_unit_ptr().

◆ unit_

internal_ptr fake_unit_ptr::unit_
private

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