-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_reader.cpp
More file actions
71 lines (55 loc) · 1.59 KB
/
file_reader.cpp
File metadata and controls
71 lines (55 loc) · 1.59 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
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
namespace fs {
static uint32_t size(const std::string& filename) {
std::ifstream in(filename, std::ios::binary | std::ios::ate);
return in.tellg();
}
static bool exists(const std::string& filename) {
std::ifstream in(filename);
return in ? true : false;
}
template <typename RT>
RT readfile(const std::string& filename);
template <>
std::string readfile(const std::string& filename) {}
template <>
std::vector<std::string> readfile(const std::string& filename) {}
struct chunk{
std::string data;
friend std::ostream& operator<<(std::ostream& out, chunk const& ch) {
out << ch.data;
return out;
}
};
template <>
std::vector<chunk> readfile(const std::string& filename) {}
template <typename T>
void print(T&& cont) {
for (const auto& item : cont)
std::cout << item << std::endl;
}
void print(const std::string& text) { std::cout << text << std::endl;}
}
enum {
HELP = 1,
WORK = 3
};
int main(int argc, char**argv) {
if( argc == HELP) {
std::cout << "usage:\n"
<< "file_reader 'mode' 'filename'\n"
<< "mode:\n"
<< "normal\n"
<< "line\n"
<< "chunk"
<< std::endl;
} else if ( argc == WORK ) {
if ( argv [1] == "normal" ) fs::print(fs::readfile<std::string>(argv[2]));
else if (argv[1] == "line") fs::print(fs::readfile<std::vector<std::string>>(argv[2]));
else if(argv[1] == "chunk") fs::print(fs::readfile<std::vector<fs::chunk>>(argv[2]));
}
return 0;
}