The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
recall_list_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 /// This class encapsulates the recall list of a team.
16 
17 #ifndef RECALL_LIST_MGR_HPP
18 #define RECALL_LIST_MGR_HPP
19 
20 #include "units/ptr.hpp"
21 
22 #include <string>
23 #include <vector>
24 
25 namespace ai {
26  class readonly_context_impl;
27 }
28 
30 public:
32  typedef std::vector<unit_ptr >::const_iterator const_iterator;
33 
34  iterator begin() { return recall_list_.begin();} //!< begin iterator
35  iterator end() { return recall_list_.end(); } //!< end iterator
36 
37  const_iterator begin() const { return recall_list_.begin();} //!< begin const iterator
38  const_iterator end() const { return recall_list_.end(); } //!< end const iterator
39 
40  unit_ptr operator[](size_t index) { return recall_list_[index]; } //!< vector style dereference
41  unit_const_ptr operator[](size_t index) const { return recall_list_[index]; } //!< vector style dereference
42 
43  unit_ptr find_if_matches_id(const std::string & unit_id); //!< Find a unit by id. Null pointer if not found.
44  unit_ptr extract_if_matches_id(const std::string & unit_id); //!< Find a unit by id, and extract from this object if found. Null if not found.
45  unit_const_ptr find_if_matches_id(const std::string & unit_id) const; //!< Const find by id.
46  void erase_if_matches_id(const std::string & unit_id); //!< Erase any unit with this id.
47 
48  unit_ptr find_if_matches_underlying_id(size_t uid); //!< Find a unit by underlying id. Null pointer if not found.
49  unit_ptr extract_if_matches_underlying_id(size_t uid); //!< Find a unit by underlying id, and extract if found. Null if not found.
50  unit_const_ptr find_if_matches_underlying_id(size_t uid) const; //!< Const find by underlying id.
51  void erase_by_underlying_id(size_t uid); //!< Erase any unit with this underlying id.
52 
53  iterator erase_index(size_t index); //!< Erase by index.
54  iterator erase(iterator it); //!< Erase an iterator to this object.
55 
56  size_t find_index(const std::string & unit_id) const; //!< Find the index of a unit by its id.
57  size_t size() const { return recall_list_.size(); } //!< Get the number of units on the list.
58  bool empty() const { return recall_list_.empty(); } //!< Is it empty?
59 
60  void add(const unit_ptr & ptr); //!< Add a unit to the list.
61 
62 private:
63  std::vector<unit_ptr > recall_list_; //!< The underlying data struture. TODO: Should this be a map based on underlying id instead?
64 
65  friend class ai::readonly_context_impl; //!< Friend AI module for ease of implementation there.
66 };
67 
68 #endif
size_t size() const
Get the number of units on the list.
unit_const_ptr operator[](size_t index) const
vector style dereference
const_iterator end() const
end const iterator
const_iterator begin() const
begin const iterator
unit_ptr operator[](size_t index)
vector style dereference
unit_ptr find_if_matches_underlying_id(size_t uid)
Find a unit by underlying id. Null pointer if not found.
unit_ptr extract_if_matches_id(const std::string &unit_id)
Find a unit by id, and extract from this object if found. Null if not found.
A small explanation about what's going on here: Each action has access to two game_info objects First...
Definition: actions.cpp:57
unit_ptr extract_if_matches_underlying_id(size_t uid)
Find a unit by underlying id, and extract if found. Null if not found.
unit_ptr find_if_matches_id(const std::string &unit_id)
Find a unit by id. Null pointer if not found.
std::vector< unit_ptr >::const_iterator const_iterator
bool empty() const
Is it empty?
iterator begin()
begin iterator
iterator end()
end iterator
void erase_if_matches_id(const std::string &unit_id)
Erase any unit with this id.
iterator erase_index(size_t index)
Erase by index.
void erase_by_underlying_id(size_t uid)
Erase any unit with this underlying id.
GLuint index
Definition: glew.h:1782
iterator erase(iterator it)
Erase an iterator to this object.
size_t find_index(const std::string &unit_id) const
Find the index of a unit by its id.
void add(const unit_ptr &ptr)
Add a unit to the list.
std::string::const_iterator iterator
Definition: tokenizer.hpp:21
GLsizei const GLcharARB ** string
Definition: glew.h:4503
std::vector< unit_ptr >::iterator iterator
std::vector< unit_ptr > recall_list_
The underlying data struture. TODO: Should this be a map based on underlying id instead?