The Battle for Wesnoth  1.15.2+dev
reports.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2018 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
17 #include "display_context.hpp"
18 
19 #include <vector>
20 
21 #include <boost/optional.hpp>
22 
23 //this module is responsible for outputting textual reports of
24 //various game and unit statistics
25 
26 class gamemap;
27 class team;
28 class tod_manager;
29 class unit_map;
30 
31 class display;
32 
33 namespace wb {
34  class manager;
35 }
36 
37 namespace events {
38  class mouse_handler;
39 }
40 
41 class reports
42 {
43 public:
44 
45  class context
46  {
47  public:
48  context(const display_context & dc, display & disp, const tod_manager & tod, std::shared_ptr<wb::manager> wb, boost::optional<events::mouse_handler &> mhb) : dc_(dc), disp_(disp), tod_(tod), wb_(wb), mhb_(mhb) {}
49 
50  const std::vector<team> & teams() const { return dc_.teams(); }
51  const unit_map & units() const { return dc_.units(); }
52  const gamemap & map() const { return dc_.map(); }
53 
54  const display_context & dc() const { return dc_; }
55  display & screen() { return disp_; }
56  const tod_manager & tod() const { return tod_; }
57  std::shared_ptr<wb::manager> wb() { return wb_; }
58  boost::optional<events::mouse_handler&> mhb() { return mhb_; }
59 
60  private:
63  const tod_manager & tod_;
64  std::shared_ptr<wb::manager> wb_;
65  boost::optional<events::mouse_handler&> mhb_;
66  };
67 
68  struct generator
69  {
70  virtual config generate(context & ct) = 0;
71  virtual ~generator() {}
72  };
73 
74  void register_generator(const std::string &name, generator *);
75 
76  config generate_report(const std::string &name, context & ct, bool only_static = false);
77 
78  const std::set<std::string> &report_list();
79 
80  using generator_function = std::function<config(reports::context&)>;
81 
82  typedef std::map<std::string, std::shared_ptr<reports::generator>> dynamic_report_generators;
83 
84 private:
85 
86  std::set<std::string> all_reports_;
87 
88  dynamic_report_generators dynamic_generators_;
89 
90 };
const gamemap & map() const
Definition: reports.hpp:52
boost::optional< events::mouse_handler & > mhb_
Definition: reports.hpp:65
const std::vector< team > & teams() const
Definition: reports.hpp:50
const tod_manager & tod_
Definition: reports.hpp:63
const tod_manager & tod() const
Definition: reports.hpp:56
display & screen()
Definition: reports.hpp:55
std::shared_ptr< wb::manager > wb()
Definition: reports.hpp:57
Unit and team statistics.
display & disp_
Definition: reports.hpp:62
This class stores all the data for a single &#39;side&#39; (in game nomenclature).
Definition: team.hpp:44
context(const display_context &dc, display &disp, const tod_manager &tod, std::shared_ptr< wb::manager > wb, boost::optional< events::mouse_handler &> mhb)
Definition: reports.hpp:48
std::set< std::string > all_reports_
Definition: reports.hpp:86
Encapsulates the map of the game.
Definition: map.hpp:36
const display_context & dc_
Definition: reports.hpp:61
std::shared_ptr< wb::manager > wb_
Definition: reports.hpp:64
dynamic_report_generators dynamic_generators_
Definition: reports.hpp:88
std::function< config(reports::context &)> generator_function
Definition: reports.hpp:80
const display_context & dc() const
Definition: reports.hpp:54
virtual ~generator()
Definition: reports.hpp:71
const unit_map & units() const
Definition: reports.hpp:51
Handling of system events.
Definition: manager.hpp:41
boost::optional< events::mouse_handler & > mhb()
Definition: reports.hpp:58
Container associating units to locations.
Definition: map.hpp:99
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
Definition: display.hpp:48
std::map< std::string, std::shared_ptr< reports::generator > > dynamic_report_generators
Definition: reports.hpp:82