The Battle for Wesnoth  1.19.0-dev
side_filter.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2024
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 <string>
21 #include <vector>
22 
23 class config;
24 class filter_context;
25 class unit_filter;
26 class team;
27 
28 //side_filter: a class that implements the Standard Side Filter
29 class side_filter {
30 public:
31 
32  ~side_filter();
33 
34  side_filter(const std::string &side_string, const filter_context * fc, bool flat_tod = false);
35  side_filter(const vconfig &cfg, const filter_context * fc, bool flat_tod = false);
36 
37  //match: returns true if and only if the given team matches this filter
38  bool match(const team& t) const;
39  bool match(const int side) const;
40  std::vector<int> get_teams() const;
41  const config& get_config() const {return cfg_.get_config();}
42 
43 private:
44  side_filter(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  /** The filter context for this filter. It should be a pointer because otherwise the default ctor doesn't work */
56 
57  mutable std::unique_ptr<unit_filter> ufilter_;
58  mutable std::unique_ptr<side_filter> allied_filter_;
59  mutable std::unique_ptr<side_filter> enemy_filter_;
60  mutable std::unique_ptr<side_filter> has_ally_filter_;
61  mutable std::unique_ptr<side_filter> has_enemy_filter_;
62 };
double t
Definition: astarsearch.cpp:63
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
std::unique_ptr< side_filter > has_ally_filter_
Definition: side_filter.hpp:60
std::vector< int > get_teams() const
Definition: side_filter.cpp:59
const filter_context * fc_
The filter context for this filter.
Definition: side_filter.hpp:55
std::string side_string_
Definition: side_filter.hpp:52
bool match(const team &t) const
const config & get_config() const
Definition: side_filter.hpp:41
side_filter(const side_filter &other)
bool match_internal(const team &t) const
Definition: side_filter.cpp:86
std::unique_ptr< side_filter > allied_filter_
Definition: side_filter.hpp:58
std::unique_ptr< side_filter > has_enemy_filter_
Definition: side_filter.hpp:61
const vconfig cfg_
Definition: side_filter.hpp:49
side_filter & operator=(const side_filter &other)
std::unique_ptr< side_filter > enemy_filter_
Definition: side_filter.hpp:59
side_filter(const std::string &side_string, const filter_context *fc, bool flat_tod=false)
Definition: side_filter.cpp:54
std::unique_ptr< unit_filter > ufilter_
Definition: side_filter.hpp:57
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:74
A variable-expanding proxy for the config class.
Definition: variable.hpp:45
const config & get_config() const
Definition: variable.hpp:75