The Battle for Wesnoth  1.17.0-dev
side_filter.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2021
3  by Yurii Chernyi <terraninfo@terraninfo.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include "variable.hpp"
19 
20 #include <set>
21 #include <string>
22 #include <vector>
23 
24 class config;
25 class filter_context;
26 class unit;
27 class unit_filter;
28 class team;
29 
30 //side_filter: a class that implements the Standard Side Filter
31 class side_filter {
32 public:
33 
34  ~side_filter();
35 
36  side_filter(const std::string &side_string, const filter_context * fc, bool flat_tod = false);
37  side_filter(const vconfig &cfg, const filter_context * fc, bool flat_tod = false);
38 
39  //match: returns true if and only if the given team matches this filter
40  bool match(const team& t) const;
41  bool match(const int side) const;
42  std::vector<int> get_teams() const;
43 
44 private:
45  side_filter(const side_filter &other);
46  side_filter& operator=(const side_filter &other);
47 
48  bool match_internal(const team& t) const;
49 
50  const vconfig cfg_; //config contains WML for a Standard Side Filter
51 
52  bool flat_;
53  std::string side_string_;
54 
55  /** The filter context for this filter. It should be a pointer because otherwise the default ctor doesn't work */
57 
58  mutable std::unique_ptr<unit_filter> ufilter_;
59  mutable std::unique_ptr<side_filter> allied_filter_;
60  mutable std::unique_ptr<side_filter> enemy_filter_;
61  mutable std::unique_ptr<side_filter> has_ally_filter_;
62  mutable std::unique_ptr<side_filter> has_enemy_filter_;
63 };
std::unique_ptr< side_filter > has_enemy_filter_
Definition: side_filter.hpp:62
This class represents a single unit of a specific type.
Definition: unit.hpp:121
const filter_context * fc_
The filter context for this filter.
Definition: side_filter.hpp:56
bool match_internal(const team &t) const
Definition: side_filter.cpp:88
This class stores all the data for a single &#39;side&#39; (in game nomenclature).
Definition: team.hpp:72
std::unique_ptr< unit_filter > ufilter_
Definition: side_filter.hpp:58
std::string side_string_
Definition: side_filter.hpp:53
const vconfig cfg_
Definition: side_filter.hpp:50
side_filter & operator=(const side_filter &other)
std::unique_ptr< side_filter > has_ally_filter_
Definition: side_filter.hpp:61
bool match(const team &t) const
double t
Definition: astarsearch.cpp:65
std::vector< int > get_teams() const
Definition: side_filter.cpp:61
A variable-expanding proxy for the config class.
Definition: variable.hpp:44
std::unique_ptr< side_filter > allied_filter_
Definition: side_filter.hpp:59
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
side_filter(const std::string &side_string, const filter_context *fc, bool flat_tod=false)
Definition: side_filter.cpp:56
std::unique_ptr< side_filter > enemy_filter_
Definition: side_filter.hpp:60