-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStageFactory.h
More file actions
50 lines (47 loc) · 1.4 KB
/
StageFactory.h
File metadata and controls
50 lines (47 loc) · 1.4 KB
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
#pragma once
#include "Pipeline.h"
#include <memory>
#include <algorithm>
#include <stdexcept>
enum class StageType { MultipleByTwo, FilterStage, SumAggregator,
ToUpperStage, MinLengthFilter, ConcatAggregator };
template<typename T>
class StageFactory{
public:
static std::unique_ptr<Stage<T>> create(const StageType type) {
switch (type)
{
case StageType::MultipleByTwo:
return std::make_unique<MultipleByTwo<T>>();
break;
case StageType::FilterStage:
return std::make_unique<FilterStage<T>>();
break;
case StageType::SumAggregator:
return std::make_unique<SumAggregator<T>>();
break;
default:
throw std::runtime_error("Unknown StageType");
}
}
};
template<>
class StageFactory<std::string> {
public:
static std::unique_ptr<Stage<std::string>> create(const StageType type) {
switch (type)
{
case StageType::ToUpperStage:
return std::make_unique<ToUpperStage>();
break;
case StageType::MinLengthFilter:
return std::make_unique<MinLengthFilter>(3);
break;
case StageType::ConcatAggregator:
return std::make_unique<ConcatAggregator>();
break;
default:
throw std::runtime_error("Invalid string stage");
}
}
};