The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
reports.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2003 - 2025
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 "mouse_events.hpp"
23
24#include <map>
25#include <set>
26#include <vector>
27
28//this module is responsible for outputting textual reports of
29//various game and unit statistics
30
31class gamemap;
32class team;
33class tod_manager;
34class unit_map;
35
36class display;
37
38namespace wb {
39 class manager;
40}
41
43{
44public:
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_;
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 /** Generate the specified report using the given context. */
78 config generate_report(const std::string& name, const context& ct);
79
80 /** Generate the specified report using the given context, excluding dynamic generators. */
81 config generate_builtin_report(const std::string& name, const context& rc);
82
83 const std::set<std::string> &report_list();
84
85 using generator_function = std::function<config(const reports::context&)>;
86
87 typedef std::map<std::string, std::shared_ptr<reports::generator>> dynamic_report_generators;
88
89private:
90
91 std::set<std::string> all_reports_;
92
94
95};
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
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:176
const display_context & dc_
Definition reports.hpp:62
const tod_manager & tod_
Definition reports.hpp:64
const unit_map & units() const
Definition reports.hpp:52
const display_context & dc() const
Definition reports.hpp:55
utils::optional_reference< events::mouse_handler > mhb_
Definition reports.hpp:66
utils::optional_reference< events::mouse_handler > mhb() const
Definition reports.hpp:59
const display & disp_
Definition reports.hpp:63
std::shared_ptr< wb::manager > wb() const
Definition reports.hpp:58
const display & screen() const
Definition reports.hpp:56
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
const std::vector< team > & teams() const
Definition reports.hpp:51
const gamemap & map() const
Definition reports.hpp:53
const tod_manager & tod() const
Definition reports.hpp:57
std::shared_ptr< wb::manager > wb_
Definition reports.hpp:65
std::set< std::string > all_reports_
Definition reports.hpp:91
std::map< std::string, std::shared_ptr< reports::generator > > dynamic_report_generators
Definition reports.hpp:87
std::function< config(const reports::context &)> generator_function
Definition reports.hpp:85
dynamic_report_generators dynamic_generators_
Definition reports.hpp:93
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
A simple wrapper class for optional reference types.
Definitions for the interface to Wesnoth Markup Language (WML).
Unit and team statistics.
Definition display.hpp:45
virtual config generate(const context &ct)=0
virtual ~generator()
Definition reports.hpp:72