-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileHandle.cpp
More file actions
109 lines (96 loc) · 1.8 KB
/
FileHandle.cpp
File metadata and controls
109 lines (96 loc) · 1.8 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "FileHandle.hpp"
#include <absract.h>
#include <fstream>
#include <iostream>
#include <string>
#include <system_error>
#include <vector>
#include <vector>
#include <exception>
FileHandle::FileHandle()
{
throw InvalidCreation();
}
const char *FileHandle::InvalidCreation::what() const throw()
{
return "I would be thankful if you would give me an argument";
}
FileHandle &FileHandle::operator=( const FileHandle &src )
{
if (&src != this)
this->fullFile = src.fullFile;
return *this;
}
FileHandle::FileHandle( const FileHandle &cpy )
{
*this = cpy;
}
FileHandle::~FileHandle() {}
FileHandle::FileHandle(int ac, char **av)
{
if (ac == 1)
{
this->readIn();
this->entryType = STDIN;
}
else
{
this->entryType = FILE_OUT;
this->readFile(av[1]);
}
}
bool FileHandle::checkEmpty( std::string &line )
{
int i = 0;
for (char c = line[i]; c != '\0'; i++, c = line[i])
{
if (c != '\t' && c != ' ' && c != '\n')
return false;
}
return true;
}
void FileHandle::readIn()
{
std::string line;
bool run = true;
while (run)
{
std::getline(std::cin, line);
if (std::cin.eof())
return ;
if (line.find(";;") != std::string::npos)
run = 0;
if (!line.empty() && !checkEmpty(line))
this->fullFile.insert(this->fullFile.end(), line);
}
}
void FileHandle::readFile(char *fileName)
{
std::fstream file;
std::string line;
int run = 1;
file.open(fileName);
if (!file.is_open())
{
this->readIn();
return ;
}
while (run)
{
if (!std::getline(file, line))
break ;
if (line.find("exit") != std::string::npos)
run = 0;
if (!line.empty() && !checkEmpty(line))
this->fullFile.insert(this->fullFile.end(), line);
}
file.close();
}
std::vector<std::string> FileHandle::getVec() const
{
return this->fullFile;
}
int FileHandle::getType() const
{
return this->entryType;
}