forked from SM719/CPU_Scheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileReader.cpp
More file actions
71 lines (68 loc) · 1.65 KB
/
fileReader.cpp
File metadata and controls
71 lines (68 loc) · 1.65 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
#include"fileReader.h"
int fileReader::getFileContents(){
ifstream readFile;
string fileName,temp;
totalProcesses_ = 0;
cout << "Enter the filename:";
getline (cin, fileName);
readFile.open(fileName.c_str());
if(readFile.is_open()){
while(!readFile.eof()){
totalProcesses_++;
getline(readFile,temp);
fContents_.append(temp);
fContents_.append(" ");
}
fContents_.append("\n");
readFile.close();
return 0;
}
else
readFile.close();
return -1;
}
void fileReader::contentParser(){
int j=0;
length_=0;
for(int i=0;fContents_[i]!='\n';i++){
if(fContents_[i] == ' '){
length_++;
}
}
processInfo_ = new int[length_];
for(int i=0;j<length_;i++){
processInfo_[j] = stoi(fContents_.substr(i,fContents_.find_first_of(" ",i)));
i = fContents_.find_first_of(" \n",i);
j++;
}
}
void fileReader::processParser(){
int j = 0;
for(int i=0;i<totalProcesses_;i++){
Process temp;
temp.pid_ = processInfo_[j++];
temp.timeIn_ = processInfo_[j++];
temp.prio_ = processInfo_[j++];
temp.tncpu_ = processInfo_[j++];
for(int k=0;k<(temp.tncpu_-1);k++){
temp.cpuBrusts_.push_back(processInfo_[j++]);
temp.IOBrusts_.push_back(processInfo_[j++]);
}
temp.cpuBrusts_.push_back(processInfo_[j++]); //Always ends with a cpu burst
if (processes_.size() ==0)
processes_.push_back(temp);
else
for (vector<Process>::iterator it = processes_.begin(); it != processes_.end(); ++it)
if (temp.timeIn_ > it->timeIn_)
{
processes_.insert(it,temp); //Put process into a vector of processes
break;
}
else if (processes_.end() - 1 == it)
{
processes_.push_back(temp);
break;
}
}
delete processInfo_;
}