The Battle for Wesnoth  1.15.12+dev
lua_terrainfilter.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2018 the Battle for Wesnoth Project https://www.wesnoth.org/
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY.
10 
11  See the COPYING file for more details.
12 */
13 
14 #pragma once
15 
16 #include <cstddef>
17 #include <string>
18 #include <memory>
19 #include <map>
20 #include <set>
21 #include "map/map.hpp"
22 
23 #include "scripting/lua_common.hpp"
24 struct lua_State;
25 struct map_location;
26 class mapgen_gamemap;
27 class filter_impl;
28 namespace lua_mapgen
29 {
30  class filter
31  {
32  public:
33  /**
34  * @a a lua table with the following attributes
35  * [1]: the filter table,
36  * [2]: attributeslocation_sets
37  */
38  explicit filter(lua_State* L, int data_index, int res_index = 0);
39 
40  //impl_ may contain pointers to known_sets_, copycontructing this will result in segfaults.
41  filter(const filter&) = delete;
42  filter& operator=(const filter&) = delete;
43  //moving is ok though.
44  filter(filter&&) = default;
45  filter& operator=(filter&&) = default;
46 
47  ~filter();
48 
49  bool matches(const gamemap_base& m, map_location l);
50  //todo: add a clear cache function.
51  private:
52  std::map<std::string, std::set<map_location>> known_sets_;
53  std::unique_ptr<filter_impl> impl_;
54  };
55 
56  std::string register_filter_metatables(lua_State *L);
57 }
58 
59 bool luaW_is_mgfilter(lua_State* L, int index);
60 
62 
64 
66 
68 
71 
72 namespace lua_terrainfilter {
73  std::string register_metatables(lua_State *L);
74 }
void lua_mgfilter_setmetatable(lua_State *L)
bool matches(const gamemap_base &m, map_location l)
filter(lua_State *L, int data_index, int res_index=0)
a lua table with the following attributes [1]: the filter table,
std::unique_ptr< filter_impl > impl_
int intf_terrainfilter_create(lua_State *L)
Create a filter.
lua_mapgen::filter * luaW_to_mgfilter(lua_State *L, int index)
std::string register_filter_metatables(lua_State *L)
lua_mapgen::filter & luaW_check_mgfilter(lua_State *L, int index)
filter & operator=(const filter &)=delete
std::string register_metatables(lua_State *L)
Definition: lua_color.cpp:135
Encapsulates the map of the game.
Definition: location.hpp:37
std::map< std::string, std::set< map_location > > known_sets_
bool luaW_is_mgfilter(lua_State *L, int index)
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
Definition: unicode.cpp:71
int intf_mg_get_locations(lua_State *L)
int intf_mg_get_tiles_radius(lua_State *L)