The Battle for Wesnoth  1.15.1+dev
context_free_grammar_generator.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2018 by Ján Dugáček
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 
19 #include <list>
20 #include <vector>
21 #include <cstdint>
22 
24 {
25 private:
26 
27  struct nonterminal {
28  nonterminal() : last_(1) {}
29  std::vector<std::vector<std::string>> possibilities_;
30  mutable unsigned int last_;
31  };
32 
33  void init_seed(uint32_t seed[]) const;
34  std::map<std::string, nonterminal> nonterminals_;
35  std::string print_nonterminal(const std::string& name, uint32_t seed[], short int seed_pos) const;
36  static const short unsigned int seed_size = 20;
37 
38 public:
39  /** Initialisation
40  * @param source the definition of the context-free grammar to use
41  */
42  context_free_grammar_generator(const std::string& source);
43 
44  /** Initialisation
45  * @param source A map of nonterminals to lists of possibilities
46  */
47  context_free_grammar_generator(const std::map<std::string, std::vector<std::string>>& source);
48 
49  /** Generates a possible word in the grammar set before
50  * @return the word
51  */
52  std::string generate() const override;
53 
55 };
static const char * name(const std::vector< SDL_Joystick *> &joysticks, const std::size_t index)
Definition: joystick.cpp:48
std::vector< std::vector< std::string > > possibilities_
std::string generate() const override
Generates a possible word in the grammar set before.
std::string print_nonterminal(const std::string &name, uint32_t seed[], short int seed_pos) const
context_free_grammar_generator(const std::string &source)
Initialisation.
std::map< std::string, nonterminal > nonterminals_
static const short unsigned int seed_size