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