-
Notifications
You must be signed in to change notification settings - Fork 1
/
workflow.cpp
48 lines (39 loc) · 1.32 KB
/
workflow.cpp
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
//
// workflow.cpp
// Workflow
//
// Created by Кирилл on 20.11.17.
// Copyright © 2017 Кирилл. All rights reserved.
//
#include "workflow.h"
#include "workers.h"
namespace wkfw {
Workflow::Workflow(std::istream& stream,
const std::string& ifname,
const std::string& ofname) throw(InvalidWorkflowException)
: parser(WorkflowParser(stream)), ifname(ifname), ofname(ofname) {}
void Workflow::execute() throw(WorkerExecuteException) {
WorkerResult lastResult;
Worker const* worker = parser.nextInstruction();
if (worker == nullptr)
return;
// Проверяем наличие чтения из файла
if (worker->getAcceptType() != WorkerResult::NONE) {
if (ifname == "")
throw WorkerExecuteException("No input file set.");
workers::ReadFile reader(0, ifname);
lastResult = reader.execute(lastResult);
}
// Выполняем инструкции
do
lastResult = worker->execute(lastResult);
while ((worker = parser.nextInstruction()));
// Проверяем наличие записи в файл
if (lastResult.getType() != WorkerResult::NONE) {
if (ofname == "")
throw WorkerExecuteException("No output file set.");
workers::WriteFile writer(0, ofname);
writer.execute(lastResult);
}
}
} // namespace wkfw