The Battle for Wesnoth  1.15.1+dev
recall_list_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 /// This class encapsulates the recall list of a team.
16 
17 #pragma once
18 
19 #include "units/ptr.hpp"
20 
21 #include <string>
22 #include <vector>
23 
24 namespace ai {
25  class readonly_context_impl;
26 }
27 
29 public:
31  typedef std::vector<unit_ptr >::const_iterator const_iterator;
32 
33  iterator begin() { return recall_list_.begin();} //!< begin iterator
34  iterator end() { return recall_list_.end(); } //!< end iterator
35 
36  const_iterator begin() const { return recall_list_.begin();} //!< begin const iterator
37  const_iterator end() const { return recall_list_.end(); } //!< end const iterator
38 
39  unit_ptr operator[](std::size_t index) { return recall_list_[index]; } //!< vector style dereference
40  unit_const_ptr operator[](std::size_t index) const { return recall_list_[index]; } //!< vector style dereference
41 
42  unit_ptr find_if_matches_id(const std::string & unit_id); //!< Find a unit by id. Null pointer if not found.
43  /// Find a unit by id, and extract from this object if found. Null if not found.
44  /// @a pos an output paramter, to know in which position the unit was.
45  unit_ptr extract_if_matches_id(const std::string & unit_id, int * pos = nullptr);
46  unit_const_ptr find_if_matches_id(const std::string & unit_id) const; //!< Const find by id.
47  void erase_if_matches_id(const std::string & unit_id); //!< Erase any unit with this id.
48 
49  unit_ptr find_if_matches_underlying_id(std::size_t uid); //!< Find a unit by underlying id. Null pointer if not found.
50  unit_ptr extract_if_matches_underlying_id(std::size_t uid); //!< Find a unit by underlying id, and extract if found. Null if not found.
51  unit_const_ptr find_if_matches_underlying_id(std::size_t uid) const; //!< Const find by underlying id.
52  void erase_by_underlying_id(std::size_t uid); //!< Erase any unit with this underlying id.
53 
54  iterator erase_index(std::size_t index); //!< Erase by index.
55  iterator erase(iterator it); //!< Erase an iterator to this object.
56 
57  std::size_t find_index(const std::string & unit_id) const; //!< Find the index of a unit by its id.
58  std::size_t size() const { return recall_list_.size(); } //!< Get the number of units on the list.
59  bool empty() const { return recall_list_.empty(); } //!< Is it empty?
60 
61  /// Add a unit to the list.
62  /// @a pos the location where to insert the unit, -1 for 'at end'
63  void add(const unit_ptr & ptr, int pos = -1);
64 
65 private:
66  std::vector<unit_ptr > recall_list_; //!< The underlying data struture. TODO: Should this be a map based on underlying id instead?
67 };
boost::intrusive_ptr< const unit > unit_const_ptr
Definition: ptr.hpp:30
bool empty() const
Is it empty?
unit_ptr operator[](std::size_t index)
vector style dereference
A small explanation about what&#39;s going on here: Each action has access to two game_info objects First...
Definition: actions.cpp:58
unit_const_ptr operator[](std::size_t index) const
vector style dereference
std::vector< unit_ptr >::const_iterator const_iterator
iterator begin()
begin iterator
void erase(const std::string &key)
Definition: general.cpp:220
iterator end()
end iterator
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
Definition: unicode.cpp:71
std::size_t size() const
Get the number of units on the list.
boost::intrusive_ptr< unit > unit_ptr
Definition: ptr.hpp:29
const_iterator begin() const
begin const iterator
const_iterator end() const
end const iterator
std::vector< unit_ptr >::iterator iterator
std::string::const_iterator iterator
Definition: tokenizer.hpp:24
std::vector< unit_ptr > recall_list_
The underlying data struture. TODO: Should this be a map based on underlying id instead?