-
Notifications
You must be signed in to change notification settings - Fork 2
/
streamreplacer.h
76 lines (60 loc) · 2.22 KB
/
streamreplacer.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
64
65
66
67
68
69
70
71
72
73
74
75
76
#pragma once
#include <memory>
#include <utility>
#include <vector>
namespace bpatch
{
/// <summary>
/// forward declarations for factory methods
/// </summary>
class Writer;
class AbstractBinaryLexeme;
/// <summary>
/// source is first (will be replaced)
/// target is second in pair (with this lexeme)
/// </summary>
typedef std::pair<std::unique_ptr<AbstractBinaryLexeme>&,
std::unique_ptr<AbstractBinaryLexeme>&> AbstractLexemesPair;
/// <summary>
/// one replaces possible among provided pairs
/// </summary>
typedef std::vector<AbstractLexemesPair> StreamReplacerChoice;
//--------------------------------------------------
/// <summary>
/// stream for bytes to replace
/// </summary>
struct StreamReplacer
{
/// <summary>
/// callback from StreamReplacer
/// </summary>
/// <param name="toProcess">char - next in sequence</param>
/// <param name="aEod">this is sign that no more data,
/// current char 'toProcess' is not valid if aEod is true</param>
virtual void DoReplacements(const char toProcess, const bool aEod) const = 0;
/// <summary>
/// Set next replacer in chain of replacers.
/// </summary>
/// <param name="pNext">replacer to call next</param>
virtual void SetNextReplacer(std::unique_ptr<StreamReplacer>&& pNext) = 0;
virtual ~StreamReplacer() = default;
// how to create Stream Replacers
public:
/// <summary>
/// creates a StreamReplacer for writing the lexemes to file
/// Adding another StreamReplacer after adding this one leads to exception
/// </summary>
/// <param name="pWriter">writer interface</param>
/// <returns>unique_ptr with object which should be last in chain of processing</returns>
static std::unique_ptr<StreamReplacer> ReplacerLastInChain(Writer* const pWriter);
/// <summary>
/// creates replacer for choose specific lexeme among others to replace
/// </summary>
/// <param name="choice">set of pairs of src & trg lexemes - one of which
/// can be processed. The one that was found first.
/// if it has only one pair than it's ok
/// </param>
/// <returns>Replacer for building replacement chain</returns>
static std::unique_ptr<StreamReplacer> CreateReplacer(StreamReplacerChoice& choice);
};
};// namespace bpatch