-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInput.cpp
61 lines (48 loc) · 1.17 KB
/
Input.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
#include <cassert>
#include <iostream>
#include "Input.h"
Input::Input(const std::string _filepath ) : count(0), filepath(_filepath), isFileOpenedSuccesful(true) {
fin.open(filepath,std::ios::binary);
if (!fin.is_open()) {
std::cout << "file " << filepath << " cant be open" << std::endl;
fin.close();
}
}
Input::Input(const Input &input){
filepath = input.filepath;
fin.open(input.filepath, std::ios::binary);
count = input.count;
if (!fin.is_open()) {
std::cout << "file " << filepath << " cant be open" << std::endl;
fin.close();
isFileOpenedSuccesful = false;
}
}
size_t Input::GetFileSize() {
return count;
}
void Input::RemoveFile() {
const char *filep = filepath.c_str();
std::remove(filep);
}
bool Input::Read(byte& value) {
char buff;
if (fin.read(&buff, sizeof(char))) {
value = (unsigned char)buff;
++count;
return true;
}
return false;
}
Input::~Input() {
fin.close();
}
bool Input::isFileEmpty(){
(0 == count) ? true : false;
}
std::string Input::GetFilePath(){
return filepath;
}
size_t Input::GetCount() const {
return count;
}