The Battle for Wesnoth  1.19.4+dev
fake_unit_manager.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2024
3  by Chris Beck <render787@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include <deque>
19 
20 class display;
21 class unit;
22 
23 /** Manages a list of fake units for the display object. */
25 public:
26  /** Construct a fake unit manager from a display which owns it. */
28 
29  //Anticipate making place_temporary_unit and remove_temporary_unit private to force exception safety
30  friend class fake_unit_ptr;
31 
32  //Typedef internal_ptr_type is the object held internally. It should point to a const unit, since const units are drawable.
33  typedef unit const * internal_ptr_type;
34 
35  //Typedefs and iterator methods which make this object "boost_foreachable"
36  typedef std::deque<internal_ptr_type>::const_iterator iterator;
37  typedef std::deque<internal_ptr_type>::const_iterator const_iterator;
38 
39  iterator begin() { return fake_units_.begin(); }
40  iterator end() { return fake_units_.end(); }
41 
42  const_iterator begin() const { return fake_units_.begin(); }
43  const_iterator end() const { return fake_units_.end(); }
44  bool empty() const { return fake_units_.empty(); }
45 private:
46  /** Register a unit with this manager. private, should only be called by fake_unit_ptr. */
48 
49  /** Deregister a unit from this manager. private, should only be called by fake_unit_ptr.
50  * @return the number of temp units deleted (0 or 1, any other number indicates an error).
51  */
53 
54  /** collection of units destined to be drawn but not put into the unit map */
55  std::deque<internal_ptr_type> fake_units_;
56  /** Reference to my display */
58 };
Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
Definition: display.hpp:89
Manages a list of fake units for the display object.
display & my_display_
Reference to my display.
fake_unit_manager(display &disp)
Construct a fake unit manager from a display which owns it.
std::deque< internal_ptr_type > fake_units_
collection of units destined to be drawn but not put into the unit map
const_iterator end() const
void place_temporary_unit(internal_ptr_type)
Register a unit with this manager.
std::deque< internal_ptr_type >::const_iterator iterator
int remove_temporary_unit(internal_ptr_type)
Deregister a unit from this manager.
const_iterator begin() const
std::deque< internal_ptr_type >::const_iterator const_iterator
unit const * internal_ptr_type
Holds a temporary unit that can be drawn on the map without being placed in the unit_map.
This class represents a single unit of a specific type.
Definition: unit.hpp:133