The Battle for Wesnoth  1.15.1+dev
fake_unit_manager.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2018 by Chris Beck <render787@gmail.com>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
17 #include <deque>
18 
19 class display;
20 class unit;
21 class fake_unit_ptr;
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. */
47  void place_temporary_unit(internal_ptr_type);
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  */
52  int remove_temporary_unit(internal_ptr_type);
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  display & my_display_; //!< Reference to my display
57 };
This class represents a single unit of a specific type.
Definition: unit.hpp:99
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