-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathworkers.h
158 lines (133 loc) · 4.41 KB
/
workers.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//
// workers.h
// Workflow
//
// Created by Кирилл on 20.11.17.
// Copyright © 2017 Кирилл. All rights reserved.
//
#ifndef WORKERS_H_
#define WORKERS_H_
#include <string>
#include "worker.h"
/**
* Набор реализаций обработчиков блоков.
*/
namespace workers {
/**
* Фабрика обработчиков блоков.
* Подбирает подходящий обработчик исходя из его имени и кол-ва аргументов.
*
* @return Обработчик, или если не найден nullptr.
*/
const wkfw::Worker* constructWorker(const size_t ident,
const std::string& name,
const std::vector<std::string>& args);
/**
* Считывание текстового файла в память, целиком.
*
* None -> Text
*/
class ReadFile : public wkfw::Worker {
public:
ReadFile(const size_t ident, const std::string& filename)
: wkfw::Worker(ident,
wkfw::WorkerResult::ResultType::TEXT,
wkfw::WorkerResult::ResultType::NONE),
filename(filename) {}
const wkfw::WorkerResult execute(const wkfw::WorkerResult& previous) const
throw(wkfw::WorkerExecuteException) override;
private:
const std::string filename;
};
/**
* Запись текста в файл.
*
* Text -> None
*/
class WriteFile : public wkfw::Worker {
public:
WriteFile(const size_t ident, const std::string& filename)
: wkfw::Worker(ident,
wkfw::WorkerResult::ResultType::NONE,
wkfw::WorkerResult::ResultType::TEXT),
filename(filename) {}
virtual const wkfw::WorkerResult execute(const wkfw::WorkerResult& previous)
const throw(wkfw::WorkerExecuteException) override;
protected:
WriteFile(const size_t ident,
const std::string& filename,
wkfw::WorkerResult::ResultType returnType)
: wkfw::Worker(ident, returnType, wkfw::WorkerResult::ResultType::TEXT),
filename(filename) {}
private:
const std::string filename;
};
/**
* Выбор из входного текста строк, разделенных символами переноса строки,
* содержащих заданное слово.
*
* Text -> Text
*/
class Grep : public wkfw::Worker {
public:
Grep(const size_t ident, const std::string& pattern)
: Worker(ident,
wkfw::WorkerResult::ResultType::TEXT,
wkfw::WorkerResult::ResultType::TEXT),
pattern(pattern) {}
const wkfw::WorkerResult execute(const wkfw::WorkerResult& previous) const
throw(wkfw::WorkerExecuteException) override;
private:
const std::string pattern;
};
/**
* Лексикогорафическая сортировка входного набора строк.
*
* Text -> Text
*/
class Sort : public wkfw::Worker {
public:
Sort(const size_t ident)
: wkfw::Worker(ident,
wkfw::WorkerResult::ResultType::TEXT,
wkfw::WorkerResult::ResultType::TEXT) {}
const wkfw::WorkerResult execute(const wkfw::WorkerResult& previous) const
throw(wkfw::WorkerExecuteException) override;
};
/**
* Замена слова <паттерн> на слово <замена>.
*
* Text -> Text
*/
class Replace : public wkfw::Worker {
public:
Replace(const size_t ident,
const std::string& pattern,
const std::string& substitution)
: wkfw::Worker(ident,
wkfw::WorkerResult::ResultType::TEXT,
wkfw::WorkerResult::ResultType::TEXT),
pattern(pattern),
substitution(substitution) {}
const wkfw::WorkerResult execute(const wkfw::WorkerResult& previous) const
throw(wkfw::WorkerExecuteException) override;
private:
const std::string pattern;
const std::string substitution;
};
/**
* Сохранение пришедшего текста в указанном файле и передача дальше.
*
* Text -> Text
*/
class Dump : public WriteFile {
public:
Dump(const size_t ident, const std::string& filename)
: WriteFile(ident, filename, wkfw::WorkerResult::ResultType::TEXT) {}
const wkfw::WorkerResult execute(const wkfw::WorkerResult& previous) const
throw(wkfw::WorkerExecuteException) override;
private:
const std::string filename;
};
} // namespace workers
#endif /* WORKERS_H_ */