The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
context_free_grammar_generator.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 by Ján Dugáček
3  Part of the Battle for Wesnoth Project http://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 #ifndef CONTEXT_FREE_GRAMMAR_GENERATOR_INCLUDED
16 #define CONTEXT_FREE_GRAMMAR_GENERATOR_INCLUDED
17 
18 #include "utils/name_generator.hpp"
19 
20 #include <string>
21 #include <map>
22 #include <list>
23 #include <vector>
24 #include <cstdint>
25 
27 {
28 private:
29 
30  struct nonterminal {
31  nonterminal() : last_(1) {}
32  std::vector<std::vector<std::string> > possibilities_;
33  mutable unsigned int last_;
34  };
35 
36  std::map<std::string, nonterminal> nonterminals_;
38  std::string print_nonterminal(const std::string& name, uint32_t* seed, short int seed_pos) const;
39  static const short unsigned int seed_size = 20;
40 
41 public:
42  /** Initialisation
43  * @param source the definition of the context-free grammar to use
44  */
46 
47  /** Initialisation
48  * @param source A map of nonterminals to lists of possibilities
49  */
50  context_free_grammar_generator(const std::map<std::string, std::vector<std::string>>& source);
51 
52  /** Generates a possible word in the grammar set before
53  * @return the word
54  */
55  std::string generate() const override;
56 
58 
59  /** Checks if the object is initialized
60  * @return if it is initialized
61  */
62  bool is_valid() const override {return initialized_; }
63 };
64 
65 #endif
boost::uint32_t uint32_t
Definition: xbrz.hpp:45
bool is_valid() const override
Checks if the object is initialized.
std::vector< std::vector< std::string > > possibilities_
std::string generate() const override
Generates a possible word in the grammar set before.
context_free_grammar_generator(const std::string &source)
Initialisation.
std::string print_nonterminal(const std::string &name, uint32_t *seed, short int seed_pos) const
GLuint const GLchar * name
Definition: glew.h:1782
std::map< std::string, nonterminal > nonterminals_
GLsizei const GLcharARB ** string
Definition: glew.h:4503
GLsizei GLsizei GLchar * source
Definition: glew.h:1800
static const short unsigned int seed_size