-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperators.cpp
More file actions
92 lines (75 loc) · 2.14 KB
/
Operators.cpp
File metadata and controls
92 lines (75 loc) · 2.14 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
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
#include <fstream>
#include <string>
#include <vector>
#include "Worker.h"
#include "Operators.h"
#include <algorithm>
#include <sstream>
using namespace std;
void Readfile::run(vector<vector<string>> &in,vector<vector<string>> &out) {
ifstream in_file (in_file_name);
string line;
if(in_file.is_open()){
while(getline(in_file,line)){
istringstream ss(line);
istream_iterator<string> begin(ss), end;
//putting all the tokens in the vector
vector<string> arrayTokens(begin, end);
in.push_back(arrayTokens);
}
}
else{
throw runtime_error("File is not open! \n");
}
in_file.close();
}
void Writefile::run(vector<vector<string>> &in,vector<vector<string>> &out) {
ofstream out_file(out_file_name);
for(auto & string : in){
for(auto & word : string){
out_file << word << " ";
}
out_file << "\n";
}
out_file.close();
}
void Grep::run(vector<vector<string>> &in,vector<vector<string>> &out) {
for(auto & string : in) {
bool word_not_exist=true;
for (auto & this_word : string) {
if(this_word==word){
word_not_exist=false;
}
}
if(word_not_exist){
out.push_back(string);
}
}
in=out;
}
void Sort::run(vector<vector<string>> &in,vector<vector<string>> &out) {
for(auto & string : in) {
sort(string.begin(), string.end());
}
}
void Replace::run(vector<vector<string>> &in,vector<vector<string>> &out) {
for(auto & string : in) {
for (auto & word : string) {
if(word==word_1){
word=word_2;
}
}
out.push_back(string);
}
in=out;
}
void Dump::run(vector<vector<string>> &in,vector<vector<string>> &out) {
ofstream out_file(out_file_name);
for(auto & string : in){
for(auto & word : string){
out_file << word << " ";
}
out_file << "\n";
}
out_file.close();
}