The Battle for Wesnoth  1.17.0-dev
reports.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2021
3  by David White <dave@whitevine.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 "display_context.hpp"
19 
20 #include <vector>
21 
23 
24 //this module is responsible for outputting textual reports of
25 //various game and unit statistics
26 
27 class gamemap;
28 class team;
29 class tod_manager;
30 class unit_map;
31 
32 class display;
33 
34 namespace wb {
35  class manager;
36 }
37 
38 namespace events {
39  class mouse_handler;
40 }
41 
42 class reports
43 {
44 public:
45 
46  class context
47  {
48  public:
49  context(const display_context & dc, display & disp, const tod_manager & tod, std::shared_ptr<wb::manager> wb, utils::optional_reference<events::mouse_handler> mhb) : dc_(dc), disp_(disp), tod_(tod), wb_(wb), mhb_(mhb) {}
50 
51  const std::vector<team> & teams() const { return dc_.teams(); }
52  const unit_map & units() const { return dc_.units(); }
53  const gamemap & map() const { return dc_.map(); }
54 
55  const display_context & dc() const { return dc_; }
56  display & screen() { return disp_; }
57  const tod_manager & tod() const { return tod_; }
58  std::shared_ptr<wb::manager> wb() { return wb_; }
60 
61  private:
64  const tod_manager & tod_;
65  std::shared_ptr<wb::manager> wb_;
67  };
68 
69  struct generator
70  {
71  virtual config generate(context & ct) = 0;
72  virtual ~generator() {}
73  };
74 
75  void register_generator(const std::string &name, generator *);
76 
77  config generate_report(const std::string &name, context & ct, bool only_static = false);
78 
79  const std::set<std::string> &report_list();
80 
81  using generator_function = std::function<config(reports::context&)>;
82 
83  typedef std::map<std::string, std::shared_ptr<reports::generator>> dynamic_report_generators;
84 
85 private:
86 
87  std::set<std::string> all_reports_;
88 
89  dynamic_report_generators dynamic_generators_;
90 
91 };
const gamemap & map() const
Definition: reports.hpp:53
const std::vector< team > & teams() const
Definition: reports.hpp:51
const tod_manager & tod_
Definition: reports.hpp:64
utils::optional_reference< events::mouse_handler > mhb_
Definition: reports.hpp:66
const tod_manager & tod() const
Definition: reports.hpp:57
display & screen()
Definition: reports.hpp:56
std::shared_ptr< wb::manager > wb()
Definition: reports.hpp:58
Unit and team statistics.
display & disp_
Definition: reports.hpp:63
This class stores all the data for a single &#39;side&#39; (in game nomenclature).
Definition: team.hpp:72
std::set< std::string > all_reports_
Definition: reports.hpp:87
Encapsulates the map of the game.
Definition: map.hpp:171
const display_context & dc_
Definition: reports.hpp:62
std::shared_ptr< wb::manager > wb_
Definition: reports.hpp:65
dynamic_report_generators dynamic_generators_
Definition: reports.hpp:89
std::function< config(reports::context &)> generator_function
Definition: reports.hpp:81
const display_context & dc() const
Definition: reports.hpp:55
virtual ~generator()
Definition: reports.hpp:72
utils::optional_reference< events::mouse_handler > mhb()
Definition: reports.hpp:59
const unit_map & units() const
Definition: reports.hpp:52
Handling of system events.
Definition: manager.hpp:43
Container associating units to locations.
Definition: map.hpp:98
context(const display_context &dc, display &disp, const tod_manager &tod, std::shared_ptr< wb::manager > wb, utils::optional_reference< events::mouse_handler > mhb)
Definition: reports.hpp:49
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
Definition: display.hpp:49
std::map< std::string, std::shared_ptr< reports::generator > > dynamic_report_generators
Definition: reports.hpp:83