-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
127 lines (92 loc) · 2.23 KB
/
main.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
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
#include <iostream>
#include <mutex>
#include <dirent.h>
#include <deque>
#include "BoundBuffer.h"
template<typename T>
class Stage {
public:
virtual void read(BoundBuffer<T> buffer) = 0;
virtual void work() = 0;
virtual void output(BoundBuffer<std::string> buffer) = 0;
virtual ~Stage() {}
};
template<typename T>
class findFile : public Stage<T> {
private:
DIR* dir;
std::deque<std::string> fileNames;
public:
void read(BoundBuffer<T> &readBuffer) override {
}
void work() override {
dir = opendir(".");
if ((dir = opendir(".")) == NULL) {
std::cerr << "Cannot open current directory.";
exit(1);
}
struct dirent* entry;
while ((entry = readdir(dir)) != nullptr) {
std::string str(entry->d_name);
fileNames.push_back(str);
}
}
void output(BoundBuffer<std::string> &writeBuffer) {
while(!fileNames.empty()) {
writeBuffer.put(fileNames.front());
fileNames.pop_front();
}
writeBuffer.put("\\EOB\\");
}
};
template<typename T>
class filterFile : public Stage<T> {
private:
public:
void read(BoundBuffer<T> &readBuffer) override {
}
void work() override {
}
void output(BoundBuffer<std::string> &writeBuffer) {
}
};
template<typename T>
class generateLine : public Stage<T> {
private:
public:
void read(BoundBuffer<T> &readBuffer) override {
}
void work() override {
}
void output(BoundBuffer<std::string> &writeBuffer) {
}
};
template<typename T>
class filterLine : public Stage<T> {
private:
public:
void read(BoundBuffer<T> &readBuffer) override {
}
void work() override {
}
void output(BoundBuffer<std::string> &writeBuffer) {
}
};
template<typename T>
void worker(Stage<T>* stage, BoundBuffer<T> input, BoundBuffer<std::string> output) {
while(true){
stage -> read();
stage -> work();
stage -> output();
}
}
void usage(char* name) {
std::cerr << "Usage: " << name << " <buffsize> <filesize> <uid> <gid> <string>";
}
int main(int argc, char** argv) {
if (argc < 6) {
usage(argv[0]);
exit(1);
}
return 0;
}