The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
filter.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[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 #ifndef TERRAIN_FILTER_H_INCLUDED
16 #define TERRAIN_FILTER_H_INCLUDED
17 
18 #include "game_config.hpp"
19 #include "pathutils.hpp"
20 #include "terrain/translation.hpp"
21 #include "variable.hpp"
22 
23 class config;
24 class filter_context;
25 class unit;
26 class unit_filter;
27 class unit_map;
28 class team;
29 
30 #include <boost/scoped_ptr.hpp> //to memoize unit_filter
31 
32 //terrain_filter: a class that implements the Standard Location Filter
33 class terrain_filter : public xy_pred {
34 public:
35 
36 #ifdef _MSC_VER
37  // This constructor is required for MSVC 9 SP1 due to a bug there
38  // see http://social.msdn.microsoft.com/forums/en-US/vcgeneral/thread/34473b8c-0184-4750-a290-08558e4eda4e
39  // other compilers don't need it.
41 #endif
42 
43  terrain_filter(const vconfig& cfg,
44  const filter_context * fc, const bool flat_tod=false, const size_t max_loop=game_config::max_loop);
45  terrain_filter(const vconfig& cfg, const terrain_filter& original);
46  /** Default implementation, but defined out-of-line for efficiency reasons. */
48 
49  terrain_filter(const terrain_filter &other);
51 
52  //match: returns true if and only if the given location matches this filter
53  bool match(const map_location& loc) const;
54  virtual bool operator()(const map_location& loc) const { return this->match(loc); }
55 
56  //get_locations: gets all locations on the map that match this filter
57  // @param locs - out parameter containing the results
58  void get_locations(std::set<map_location>& locs, bool with_border=false) const;
59 
60  //restrict: limits the allowed radius size and also limits nesting
61  // The purpose to limit the time spent for WML handling
62  // Note: this feature is not fully implemented, e.g. SLF inside SUF inside SLF
63  void restrict_size(const size_t max_loop) { max_loop_ = max_loop; }
64 
65  //flatten: use base time of day -- ignore illumination ability
66  void flatten(const bool flat_tod=true) { flat_ = flat_tod; }
67 
68  config to_config() const;
69  friend class terrain_filterimpl;
70 private:
71  bool match_internal(const map_location& loc, const bool ignore_xy) const;
72 
73  const vconfig cfg_; //config contains WML for a Standard Location Filter
75 
78 
80 
81  //parsed_terrain: optimizes handling of terrain="..."
83 
84  //adjacent_matches: optimize handling of [filter_adjacent_location] for get_locations()
85  std::vector< std::set<map_location> > *adjacent_matches;
86 
87  //adjacent_match_cache: optimize handling of [filter_adjacent_location] for match()
88  std::vector< std::pair<terrain_filter, std::map<map_location,bool> > > adjacent_match_cache;
89 
90  boost::scoped_ptr<unit_filter> ufilter_;
91  };
92 
94  size_t max_loop_;
95  bool flat_;
96 };
97 
98 #endif
99 
Definition: unit.hpp:95
virtual bool operator()(const map_location &loc) const
Definition: filter.hpp:54
std::vector< std::set< map_location > > * adjacent_matches
Definition: filter.hpp:85
terrain_filter_cache cache_
Definition: filter.hpp:93
const vconfig cfg_
Definition: filter.hpp:73
bool match(const map_location &loc) const
Definition: filter.cpp:364
const filter_context * fc_
Definition: filter.hpp:74
t_translation::t_match * parsed_terrain
Definition: filter.hpp:82
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:50
This structure can be used for matching terrain strings.
Definition: translation.hpp:83
const size_t max_loop
The maximum number of hexes on a map and items in an array and also used as maximum in wml loops...
void flatten(const bool flat_tod=true)
Definition: filter.hpp:66
~terrain_filter()
Default implementation, but defined out-of-line for efficiency reasons.
Definition: filter.cpp:43
Encapsulates the map of the game.
Definition: location.hpp:38
void restrict_size(const size_t max_loop)
Definition: filter.hpp:63
void get_locations(std::set< map_location > &locs, bool with_border=false) const
Definition: filter.cpp:495
size_t max_loop_
Definition: filter.hpp:94
config to_config() const
Definition: filter.cpp:642
terrain_filter & operator=(const terrain_filter &other)
Definition: filter.cpp:95
A variable-expanding proxy for the config class.
Definition: variable.hpp:36
boost::scoped_ptr< unit_filter > ufilter_
Definition: filter.hpp:90
std::vector< std::pair< terrain_filter, std::map< map_location, bool > > > adjacent_match_cache
Definition: filter.hpp:88
Container associating units to locations.
Definition: map.hpp:90
terrain_filter(const vconfig &cfg, const filter_context *fc, const bool flat_tod=false, const size_t max_loop=game_config::max_loop)
Definition: filter.cpp:65
bool match_internal(const map_location &loc, const bool ignore_xy) const
Definition: filter.cpp:120
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83