-
Notifications
You must be signed in to change notification settings - Fork 2
/
dictionary.h
63 lines (50 loc) · 1.95 KB
/
dictionary.h
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
62
63
#pragma once
#include <list>
#include <memory>
#include <unordered_map>
#include "streamreplacer.h"
namespace bpatch
{
/// <summary>
/// class Holds binary lexemes and provides access to them by name
/// </summary>
class Dictionary final
{
public:
/// <summary>
/// access to Binary lexeme by name
/// </summary>
/// <param name="aname"> name of the lexeme from dictionary file</param>
/// <returns>lexeme from dictionary file, or nullptr</returns>
std::unique_ptr<AbstractBinaryLexeme>& Lexeme(const std::string_view aname) const;
/// <summary>
/// return pair of Binary lexemes by name
/// </summary>
/// <param name="anameSrc">name of the lexeme from dictionary file</param>
/// <param name="anameTrg">name of the lexeme from dictionary file</param>
/// <returns>lexeme from dictionary file, or nullptr</returns>
AbstractLexemesPair LexemesPair(const std::string_view anameSrc, const std::string_view anameTrg) const;
/// <summary>
/// moves binary lexeme into dictionary
/// </summary>
/// <param name="aname">set the name for lexeme</param>
/// <param name="alexeme">lexeme to store inside</param>
/// <returns>true - if this lexeme is just added;
/// false - if lexeme already was in the dictionary: new lexeme is lost</returns>
bool AddBinaryLexeme(const std::string_view aname, std::unique_ptr<AbstractBinaryLexeme>&& alexeme);
protected:
using LEXEMES_HOLDER = std::list<std::unique_ptr<AbstractBinaryLexeme>>;
/// <summary>
/// lexemes wich are under our responsibility
/// </summary>
LEXEMES_HOLDER lexemes_;
/// <summary>
/// for fast search of lexeme
/// </summary>
std::unordered_map<std::string_view, LEXEMES_HOLDER::iterator> dict;
/// <summary>
/// Default lexeme returned when result lexeme is not found
/// </summary>
std::unique_ptr<AbstractBinaryLexeme> empty_result;
}; // class Dictionary
};// namespace bpatch