The Battle for Wesnoth  1.19.0-dev
reports.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2024
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, const 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  const display & screen() const { return disp_; }
57  const tod_manager & tod() const { return tod_; }
58  std::shared_ptr<wb::manager> wb() const { return wb_; }
60 
61  private:
63  const display& disp_;
64  const tod_manager& tod_;
65  std::shared_ptr<wb::manager> wb_;
67  };
68 
69  struct generator
70  {
71  virtual config generate(const 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, const context& ct, bool only_static = false);
78 
79  const std::set<std::string> &report_list();
80 
81  using generator_function = std::function<config(const 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 
90 
91 };
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
Abstract class for exposing game data that doesn't depend on the GUI, however which for historical re...
virtual const gamemap & map() const =0
virtual const std::vector< team > & teams() const =0
virtual const unit_map & units() const =0
Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
Definition: display.hpp:88
Encapsulates the map of the game.
Definition: map.hpp:172
const display_context & dc() const
Definition: reports.hpp:55
const display_context & dc_
Definition: reports.hpp:62
const std::vector< team > & teams() const
Definition: reports.hpp:51
utils::optional_reference< events::mouse_handler > mhb() const
Definition: reports.hpp:59
const tod_manager & tod_
Definition: reports.hpp:64
const unit_map & units() const
Definition: reports.hpp:52
utils::optional_reference< events::mouse_handler > mhb_
Definition: reports.hpp:66
const tod_manager & tod() const
Definition: reports.hpp:57
const gamemap & map() const
Definition: reports.hpp:53
const display & screen() const
Definition: reports.hpp:56
const display & disp_
Definition: reports.hpp:63
context(const display_context &dc, const display &disp, const tod_manager &tod, std::shared_ptr< wb::manager > wb, utils::optional_reference< events::mouse_handler > mhb)
Definition: reports.hpp:49
std::shared_ptr< wb::manager > wb() const
Definition: reports.hpp:58
std::shared_ptr< wb::manager > wb_
Definition: reports.hpp:65
config generate_report(const std::string &name, const context &ct, bool only_static=false)
Definition: reports.cpp:1807
void register_generator(const std::string &name, generator *)
Definition: reports.cpp:1802
std::set< std::string > all_reports_
Definition: reports.hpp:87
const std::set< std::string > & report_list()
Definition: reports.cpp:1820
std::map< std::string, std::shared_ptr< reports::generator > > dynamic_report_generators
Definition: reports.hpp:83
std::function< config(const reports::context &)> generator_function
Definition: reports.hpp:81
dynamic_report_generators dynamic_generators_
Definition: reports.hpp:89
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:74
Container associating units to locations.
Definition: map.hpp:98
Handling of system events.
rng * generator
This generator is automatically synced during synced context.
Definition: random.cpp:60
Unit and team statistics.
Definition: display.hpp:45
virtual config generate(const context &ct)=0
virtual ~generator()
Definition: reports.hpp:72