-
-
Notifications
You must be signed in to change notification settings - Fork 990
/
recall_list_manager.hpp
68 lines (49 loc) · 2.91 KB
/
recall_list_manager.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
Copyright (C) 2014 by Chris Beck <render787@gmail.com>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
/// This class encapsulates the recall list of a team.
#ifndef RECALL_LIST_MGR_HPP
#define RECALL_LIST_MGR_HPP
#include "unit_ptr.hpp"
#include <string>
#include <vector>
namespace ai {
class readonly_context_impl;
}
class recall_list_manager {
public:
typedef std::vector<UnitPtr >::iterator iterator;
typedef std::vector<UnitPtr >::const_iterator const_iterator;
iterator begin() { return recall_list_.begin();} //!< begin iterator
iterator end() { return recall_list_.end(); } //!< end iterator
const_iterator begin() const { return recall_list_.begin();} //!< begin const iterator
const_iterator end() const { return recall_list_.end(); } //!< end const iterator
UnitPtr operator[](size_t index) { return recall_list_[index]; } //!< vector style dereference
UnitConstPtr operator[](size_t index) const { return recall_list_[index]; } //!< vector style dereference
UnitPtr find_if_matches_id(const std::string & unit_id); //!< Find a unit by id. Null pointer if not found.
UnitPtr 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.
UnitConstPtr find_if_matches_id(const std::string & unit_id) const; //!< Const find by id.
void erase_if_matches_id(const std::string & unit_id); //!< Erase any unit with this id.
UnitPtr find_if_matches_underlying_id(size_t uid); //!< Find a unit by underlying id. Null pointer if not found.
UnitPtr extract_if_matches_underlying_id(size_t uid); //!< Find a unit by underlying id, and extract if found. Null if not found.
UnitConstPtr find_if_matches_underlying_id(size_t uid) const; //!< Const find by underlying id.
void erase_by_underlying_id(size_t uid); //!< Erase any unit with this underlying id.
iterator erase_index(size_t index); //!< Erase by index.
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.
size_t size() const { return recall_list_.size(); } //!< Get the number of units on the list.
bool empty() const { return recall_list_.empty(); } //!< Is it empty?
void add(const UnitPtr & ptr); //!< Add a unit to the list.
private:
std::vector<UnitPtr > recall_list_; //!< The underlying data struture. TODO: Should this be a map based on underlying id instead?
friend class ai::readonly_context_impl; //!< Friend AI module for ease of implementation there.
};
#endif