The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
fake_unit_manager.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2016 by Chris Beck <[email protected]>
3  Part of the Battle for Wesnoth Project http://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 #ifndef INCL_FAKE_UNIT_MGR_HPP_
16 #define INCL_FAKE_UNIT_MGR_HPP_
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 
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  display & my_display_; //!< Reference to my display. The display owns me in a scoped_ptr, so this should never be a dangling reference.
58 };
59 
60 #endif
Definition: unit.hpp:95
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
unit const * internal_ptr_type
display & my_display_
Reference to my display. The display owns me in a scoped_ptr, so this should never be a dangling refe...
void place_temporary_unit(internal_ptr_type)
Register a unit with this manager.
const_iterator begin() const
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