The Battle for Wesnoth  1.15.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. Does not reallocate the underlying unit. 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. 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...
 
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 31 of file fake_unit_ptr.hpp.

Member Typedef Documentation

◆ internal_const_ptr

Definition at line 34 of file fake_unit_ptr.hpp.

◆ internal_ptr

Definition at line 33 of file fake_unit_ptr.hpp.

Constructor & Destructor Documentation

◆ fake_unit_ptr() [1/5]

fake_unit_ptr::fake_unit_ptr ( )

Definition at line 24 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 25 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 26 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 30 of file fake_unit_ptr.cpp.

◆ fake_unit_ptr() [5/5]

fake_unit_ptr::fake_unit_ptr ( fake_unit_ptr &&  ptr)

Definition at line 35 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 110 of file fake_unit_ptr.cpp.

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

Referenced by get().

Member Function Documentation

◆ get()

unit* fake_unit_ptr::get ( )
inline

◆ get_unit_ptr() [1/2]

internal_ptr fake_unit_ptr::get_unit_ptr ( )
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().

◆ 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 53 of file fake_unit_ptr.hpp.

References unit_.

◆ operator bool()

fake_unit_ptr::operator bool ( ) const
inlineexplicit

Definition at line 72 of file fake_unit_ptr.hpp.

◆ operator*()

unit& fake_unit_ptr::operator* ( )
inline

Derference the internal unit pointer.

Definition at line 55 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 49 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 50 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 47 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 131 of file fake_unit_ptr.cpp.

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

Referenced by fake_unit_ptr(), get(), wb::recall::init(), wb::recruit::init(), and reset().

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

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

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

◆ reset() [1/2]

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 84 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. 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 95 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 42 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 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().

◆ unit_

internal_ptr fake_unit_ptr::unit_
private

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