The Battle for Wesnoth  1.19.18+dev
help.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 class terrain_type;
19 class unit;
20 class unit_type;
21 
22 #include <memory>
23 #include <string>
24 
25 namespace help
26 {
27 struct section;
28 
29 /**
30  * The help implementation caches data parsed from the game_config. This class
31  * is used to control the lifecycle of that cache, so that the cache will be
32  * cleared before the game_config itself changes.
33  *
34  * Note: it's okay to call any of the help::show_* functions without creating
35  * an instance of help_manager - that will simply mean that the cache is
36  * cleared before the show function returns.
37  *
38  * Creating two instances of this will cause an assert.
39  */
41 {
42 public:
43  help_manager(const help_manager&) = delete;
44  help_manager& operator=(const help_manager&) = delete;
45 
47 
48  /** Returns the existing help_manager instance, or a newly allocated object otherwise. */
49  static std::shared_ptr<help_manager> get_instance();
50 
51  /**
52  * Regenerates the cached help topics if necessary.
53  *
54  * @returns the toplevel section.
55  */
56  const section& regenerate();
57 
58 private:
59  /**
60  * Private default constructor.
61  *
62  * Use @ref get_instance to get a managed instance instead.
63  */
64  help_manager();
65 
66  class implementation;
67 
68  /** Pointer-to-implementation to reduce include dependencies. */
69  std::unique_ptr<implementation> impl_;
70 
71  static inline std::weak_ptr<help_manager> singleton_;
72 };
73 
74 /**
75  * Open the help browser. The help browser will have the topic with id
76  * show_topic open if it is not the empty string. The default topic
77  * will be shown if show_topic is the empty string.
78  */
79 void show_help(const std::string& show_topic = "");
80 
81 /**
82  * Given a unit type, find the corresponding help topic's id.
83  */
84 std::string get_unit_type_help_id(const unit_type& t);
85 
86 void show_unit_description(const unit_type &t);
87 void show_unit_description(const unit &u);
89 
90 } // End namespace help.
double t
Definition: astarsearch.cpp:63
The help implementation caches data parsed from the game_config.
Definition: help.hpp:41
~help_manager()
Defined out-of-line so the implementation class is visible.
std::unique_ptr< implementation > impl_
Pointer-to-implementation to reduce include dependencies.
Definition: help.hpp:66
help_manager & operator=(const help_manager &)=delete
help_manager(const help_manager &)=delete
static std::weak_ptr< help_manager > singleton_
Definition: help.hpp:71
static std::shared_ptr< help_manager > get_instance()
Returns the existing help_manager instance, or a newly allocated object otherwise.
Definition: help.cpp:152
const section & regenerate()
Regenerates the cached help topics if necessary.
Definition: help.cpp:166
help_manager()
Private default constructor.
Definition: help.cpp:144
A single unit type that the player may recruit.
Definition: types.hpp:43
This class represents a single unit of a specific type.
Definition: unit.hpp:39
std::string get_unit_type_help_id(const unit_type &t)
Given a unit type, find the corresponding help topic's id.
Definition: help.cpp:37
void show_terrain_description(const terrain_type &t)
Definition: help.cpp:73
void show_unit_description(const unit &u)
Definition: help.cpp:63
void show_help(const std::string &show_topic)
Open the help browser.
Definition: help.cpp:83
Contains the implementation details for lexical_cast and shouldn't be used directly.
A section contains topics and sections along with title and ID.
Definition: help_impl.hpp:110