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