/
InFileHandler.hpp
73 lines (63 loc) · 1.55 KB
/
InFileHandler.hpp
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
#ifndef INFILE_HPP_INCLUDED
#define INFILE_HPP_INCLUDED
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <iterator>
#include <algorithm>
#include <vector>
#include <math.h>
template<class T>
class InFileHandler
{
public:
void read_file_to_vector(const std::string file_name, std::vector<T>& buffer);
void converter(std::string& origi);
void read_string_to_vector(const std::string file, std::vector<T>& buffer);
};
template<class T>
void InFileHandler<T>::converter(std::string& origi)
{
for(int i=0; i<origi.length(); i++)
{
switch (origi[i])
{
case '·': origi[i]=160; break;
case 'È': origi[i]=130; break;
case 'Ì': origi[i]=161; break;
case 'Û': origi[i]=162; break;
case 'ˆ': origi[i]=148; break;
case 'ı': origi[i]=139; break;
case '˙': origi[i]=163; break;
case '¸': origi[i]=129; break;
}
}
};
template<class T>
void InFileHandler<T>::read_file_to_vector(const std::string file_name, std::vector<T>& buffer)
{
std::ifstream in_file(file_name.c_str());
T temp;
while(in_file>>temp)
{
//converter(temp);
//std::string trash;
//in_file>>trash;
//in_file>>trash;
buffer.push_back(temp);
}
}
template<class T>
void InFileHandler<T>::read_string_to_vector(const std::string file, std::vector<T>& buffer)
{
std::stringstream in_file;
in_file<<file;
T temp;
while(in_file>>temp)
{
converter(temp);
buffer.push_back(temp);
}
}
#endif