The Battle for Wesnoth  1.19.0-dev
name_generator_factory.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2024
3  by Marius Spix
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 "utils/name_generator.hpp"
19 #include "config.hpp"
20 #include <vector>
21 #include <memory>
22 
24 {
25 public:
26  /**
27  * Creates a new name generator factory
28  * @param config the WML data to be parsed for name generators
29  * @param ids a list of generator ids, e.g. genders or terrain types
30  */
31  name_generator_factory(const config& config, std::vector<std::string> ids);
32 
33  /**
34  * Gets the default name generator
35  * @returns the default name generator
36  */
37  std::shared_ptr<name_generator> get_name_generator();
38 
39  /**
40  * Gets a specific name generator or the default name generator, if the
41  * specific name generator is not found.
42  * @param name generator id, e.g. a gender or a terrain type
43  * @returns a name generator
44  */
45  std::shared_ptr<name_generator> get_name_generator(const std::string name);
46 
47 private:
48  std::map<std::string, std::shared_ptr<name_generator>> name_generators_;
49 
50  /**
51  * Determines a name generator from WML data. Tries first to load a context-free generator,
52  * then falls back to Markov.
53  * @param config the WML data to be parsed for name generators
54  * @param id the generator id to use
55  * @param prefix the prefix to look for
56  */
57  void add_name_generator_from_config(const config& config, const std::string id, const std::string prefix);
58 };
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
std::shared_ptr< name_generator > get_name_generator()
Gets the default name generator.
void add_name_generator_from_config(const config &config, const std::string id, const std::string prefix)
Determines a name generator from WML data.
std::map< std::string, std::shared_ptr< name_generator > > name_generators_
name_generator_factory(const config &config, std::vector< std::string > ids)
Creates a new name generator factory.