The Battle for Wesnoth  1.15.1+dev
side_filter.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2018 by Yurii Chernyi <terraninfo@terraninfo.net>
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 "variable.hpp"
18 
19 #include <set>
20 #include <string>
21 #include <vector>
22 
23 class config;
24 class filter_context;
25 class unit;
26 class unit_filter;
27 class team;
28 
29 //side_filter: a class that implements the Standard Side Filter
30 class side_filter {
31 public:
32 
33  ~side_filter();
34 
35  side_filter(const std::string &side_string, const filter_context * fc, bool flat_tod = false);
36  side_filter(const vconfig &cfg, const filter_context * fc, bool flat_tod = false);
37 
38  //match: returns true if and only if the given team matches this filter
39  bool match(const team& t) const;
40  bool match(const int side) const;
41  std::vector<int> get_teams() const;
42 
43 private:
44  side_filter(const side_filter &other);
45  side_filter& operator=(const side_filter &other);
46 
47  bool match_internal(const team& t) const;
48 
49  const vconfig cfg_; //config contains WML for a Standard Side Filter
50 
51  bool flat_;
52  std::string side_string_;
53 
54  const filter_context * fc_; //!< The filter context for this filter. It should be a pointer because otherwise the default ctor doesn't work
55 
56  mutable std::unique_ptr<unit_filter> ufilter_;
57  mutable std::unique_ptr<side_filter> allied_filter_;
58  mutable std::unique_ptr<side_filter> enemy_filter_;
59  mutable std::unique_ptr<side_filter> has_ally_filter_;
60  mutable std::unique_ptr<side_filter> has_enemy_filter_;
61 };
std::unique_ptr< side_filter > has_enemy_filter_
Definition: side_filter.hpp:60
This class represents a single unit of a specific type.
Definition: unit.hpp:99
const filter_context * fc_
The filter context for this filter. It should be a pointer because otherwise the default ctor doesn&#39;t...
Definition: side_filter.hpp:54
bool match_internal(const team &t) const
Definition: side_filter.cpp:82
This class stores all the data for a single &#39;side&#39; (in game nomenclature).
Definition: team.hpp:44
std::unique_ptr< unit_filter > ufilter_
Definition: side_filter.hpp:56
std::string side_string_
Definition: side_filter.hpp:52
const vconfig cfg_
Definition: side_filter.hpp:49
side_filter & operator=(const side_filter &other)
std::unique_ptr< side_filter > has_ally_filter_
Definition: side_filter.hpp:59
bool match(const team &t) const
double t
Definition: astarsearch.cpp:64
std::vector< int > get_teams() const
Definition: side_filter.cpp:55
A variable-expanding proxy for the config class.
Definition: variable.hpp:42
std::unique_ptr< side_filter > allied_filter_
Definition: side_filter.hpp:57
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:92
side_filter(const std::string &side_string, const filter_context *fc, bool flat_tod=false)
Definition: side_filter.cpp:50
std::unique_ptr< side_filter > enemy_filter_
Definition: side_filter.hpp:58