The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
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
18class terrain_type;
19class unit;
20class unit_type;
21
22#include <memory>
23#include <string>
24
25namespace help
26{
27struct 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{
42public:
43 help_manager(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
58private:
59 /**
60 * Private default constructor.
61 *
62 * Use @ref get_instance to get a managed instance instead.
63 */
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 */
79void show_help(const std::string& show_topic = "");
80
81/**
82 * Given a unit type, find the corresponding help topic's id.
83 */
84std::string get_unit_type_help_id(const unit_type& t);
85
87void show_unit_description(const unit &u);
89
90} // End namespace help.
double t
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:69
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:161
help_manager & operator=(const help_manager &)=delete
const section & regenerate()
Regenerates the cached help topics if necessary.
Definition help.cpp:175
help_manager()
Private default constructor.
Definition help.cpp:153
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:38
void show_terrain_description(const terrain_type &t)
Definition help.cpp:74
void show_unit_description(const unit &u)
Definition help.cpp:64
void show_help(const std::string &show_topic)
Open the help browser.
Definition help.cpp:84
Contains the implementation details for lexical_cast and shouldn't be used directly.
A section contains topics and sections along with title and ID.