-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtemplate-method.cc
More file actions
52 lines (47 loc) · 1020 Bytes
/
template-method.cc
File metadata and controls
52 lines (47 loc) · 1020 Bytes
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
#include <iostream>
// Helper function.
template<typename ...Ts>
void println(Ts ...args) {
((std::cout << args), ...) << std::endl;
}
class Task {
// Internal states.
const char* path;
public:
explicit Task(const char* path) : path(path) {}
virtual ~Task() {}
void start() {
open();
parse();
transform();
store();
}
protected:
virtual void open() {
println("[Default] Open file, with path: ", path);
}
virtual void parse() {
println("[Default] Parse data ...");
}
virtual void transform() {
println("[Default] Transform data ...");
}
virtual void store() {
println("[Default] Store data to DB ...");
}
};
struct CSVTask : Task {
explicit CSVTask(const char* path) : Task { path } {}
// Override certain steps.
virtual void parse() override {
println("Parse CSV data ...");
}
virtual void transform() override {
println("Transform CSV data ...");
}
};
int main() {
CSVTask task { "/root/csv-file" };
task.start();
return 0;
}