-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKernel.h
93 lines (86 loc) · 1.83 KB
/
Kernel.h
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
#pragma once
#include<fstream>
#include<strstream>
#include<sstream>
#include<string>
constexpr auto MAXLINE = 128;
class ExportFile {
private:
std::ifstream in;
std::ofstream out;
public:
ExportFile(std::string outname) {
in.open("kernal.dat");
out.open(outname + ".cc");
}
ExportFile() {
in.open("kernal.dat");
out.open("defaultoutputfile.cc");
}
~ExportFile() {
in.close();
out.close();
}
ExportFile(const ExportFile&) = delete;
void CopyToOut(std::string tag) {
std::string line;
bool start = false, end=false;
while (!in.eof()) {
std::getline(in, line);
if (line == '_'+tag) {
if (start) end=true;
start ^=1;
if(start) continue;
if (end) break;
}
if (start) {
if (line[0] == '_' || line[0] == '-') continue;
else out << line << std::endl;
}
}
in.clear();
in.seekg(0, std::ios::beg);
}
void FormatToOut(std::string tag,const std::vector<std::string>& container) {
std::string line,temp;
bool found=false,numin=false;
int n,i=0;
while (!in.eof()) {
std::getline(in, line);
std::stringstream ss(line);
if (line == '-' + tag) {
found = true;
numin = true;
continue;
}
if (found) {
if (numin) {
numin = false;
ss >> n;
continue;
}
if (line[0] == '_') continue;
else if (line[0] == '-') break;
else {
int lvc = std::count(line.begin(),line.end(),'#');
if (lvc>0) {
while (std::getline(ss, temp, '#')) {
out << temp;
if (i < n && lvc) {
out << container[i];
i++;
lvc--;
}
}
out << std::endl;
}else out << line << std::endl;
}
}
}
in.clear();
in.seekg(0, std::ios::beg);
}
void WriteLine(std::string output) {
out << output << std::endl;
}
};