The Battle for Wesnoth  1.17.0-dev
fake_unit_manager.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2021
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 class fake_unit_ptr;
23 
24 /** Manages a list of fake units for the display object. */
26 public:
27  /** Construct a fake unit manager from a display which owns it. */
29 
30  //Anticipate making place_temporary_unit and remove_temporary_unit private to force exception safety
31  friend class fake_unit_ptr;
32 
33  //Typedef internal_ptr_type is the object held internally. It should point to a const unit, since const units are drawable.
34  typedef unit const * internal_ptr_type;
35 
36  //Typedefs and iterator methods which make this object "boost_foreachable"
37  typedef std::deque<internal_ptr_type>::const_iterator iterator;
38  typedef std::deque<internal_ptr_type>::const_iterator const_iterator;
39 
40  iterator begin() { return fake_units_.begin(); }
41  iterator end() { return fake_units_.end(); }
42 
43  const_iterator begin() const { return fake_units_.begin(); }
44  const_iterator end() const { return fake_units_.end(); }
45  bool empty() const { return fake_units_.empty(); }
46 private:
47  /** Register a unit with this manager. private, should only be called by fake_unit_ptr. */
48  void place_temporary_unit(internal_ptr_type);
49 
50  /** Deregister a unit from this manager. private, should only be called by fake_unit_ptr.
51  * @return the number of temp units deleted (0 or 1, any other number indicates an error).
52  */
53  int remove_temporary_unit(internal_ptr_type);
54 
55  /** collection of units destined to be drawn but not put into the unit map */
56  std::deque<internal_ptr_type> fake_units_;
57  /** Reference to my display */
59 };
This class represents a single unit of a specific type.
Definition: unit.hpp:121
Manages a list of fake units for the display object.
fake_unit_manager(display &disp)
Construct a fake unit manager from a display which owns it.
std::deque< internal_ptr_type >::const_iterator iterator
int remove_temporary_unit(internal_ptr_type)
Deregister a unit from this manager.
std::deque< internal_ptr_type > fake_units_
collection of units destined to be drawn but not put into the unit map
const_iterator begin() const
unit const * internal_ptr_type
display & my_display_
Reference to my display.
void place_temporary_unit(internal_ptr_type)
Register a unit with this manager.
const_iterator end() const
Holds a temporary unit that can be drawn on the map without being placed in the unit_map.
std::deque< internal_ptr_type >::const_iterator const_iterator