aboutsummaryrefslogtreecommitdiff
path: root/src/mnemonics/language_base.h
blob: b8b6a162f71bbccffe4e14193f564e878063fd69 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef LANGUAGE_BASE_H
#define LANGUAGE_BASE_H

#include <vector>
#include <unordered_map>
#include <string>

namespace Language
{
	const int unique_prefix_length = 4;
	class Base
	{
	protected:
		std::vector<std::string> *word_list;
		std::unordered_map<std::string, uint32_t> *word_map;
		std::unordered_map<std::string, uint32_t> *trimmed_word_map;
		std::string language_name;
		void populate_maps()
		{
			int ii;
			std::vector<std::string>::iterator it;
			for (it = word_list->begin(), ii = 0; it != word_list->end(); it++, ii++)
			{
				(*word_map)[*it] = ii;
				if (it->length() > 4)
				{
					(*trimmed_word_map)[it->substr(0, 4)] = ii;
				}
				else
				{
					(*trimmed_word_map)[*it] = ii;
				}
			}
		}
	public:
		Base()
		{
			word_list = new std::vector<std::string>;
			word_map = new std::unordered_map<std::string, uint32_t>;
			trimmed_word_map = new std::unordered_map<std::string, uint32_t>;
		}
		const std::vector<std::string>& get_word_list() const
		{
			return *word_list;
		}
		const std::unordered_map<std::string, uint32_t>& get_word_map() const
		{
			return *word_map;
		}
		const std::unordered_map<std::string, uint32_t>& get_trimmed_word_map() const
		{
			return *trimmed_word_map;
		}
		std::string get_language_name() const
		{
			return language_name;
		}
	};
}

#endif