-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTAsciiFileReader.h
More file actions
69 lines (55 loc) · 2.03 KB
/
TAsciiFileReader.h
File metadata and controls
69 lines (55 loc) · 2.03 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
/*
* TAsciiFileReader.h
*
* Created on: Mar 22, 2016
* Author: mss
*/
#ifndef TASCIIFILEREADER_H_
#define TASCIIFILEREADER_H_
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <algorithm>
#include <vector>
namespace std {
template <typename TStorage> class TAsciiFileReader {
private:
int verbose;
bool fileOpened; // has the file been opened successfully?
std::string filePath; // full path
std::string fileContents; // whole-file-buffer
std::string comment; // usually the first lines of file
protected:
vector<TStorage> vStorage; // structured buffer for file data
std::stringstream log; // push all warnings here
int16_t ReadString(); // invoked at the end of ReadFile(),
// parses the file data from fileContents
// and saves it to vector<TStorage>
virtual int16_t ReadLine(const std::string& sLine, const int32_t iLine)=0;
// invoked in the center of ReadString()
void ResetDataLow(); // Resets all data fields of the base parent class only,
virtual void ResetData()=0; // Resets all data fields,
virtual void InitLutVectors()=0;
virtual void FillLutVectors()=0;
bool CheckVectorIndex(const std::vector<int16_t>& v, const uint32_t index);
bool CheckVectorLutValue(const std::vector<int16_t>& v, const uint32_t index);
public:
TAsciiFileReader();
virtual ~TAsciiFileReader();
int16_t ReadFile(const string& path); // opens file with all error checks and saves it to string
streampos GetFileSize() const; // opens the file again and checks the size
virtual int16_t Print(ostream&)=0; // prints contents of the vector<TStorage>, not the fileContents string
const std::stringstream& GetLog() const;
const std::string& GetComment() const;
const std::string& GetFileContents() const;
bool IsFileOpened() const;
const std::string& GetFilePath() const;
std::vector<TStorage>& GetStorage();
void SetVerbose(int v);
};
} /* namespace std */
#endif /* TASCIIFILEREADER_H_ */