-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfileloader.h
55 lines (44 loc) · 1.3 KB
/
fileloader.h
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
#ifndef FILELOADER_H
#define FILELOADER_H
#include "QFileInfo"
#include "icacheitem.h"
#include "DataAllocator.h"
#include <iostream>
#include <fstream>
class FileLoader {
public:
FileLoader() { }
virtual ~FileLoader() { }
void SetFileInfo(const QFileInfo & fileInfo) {
this->fileInfo = fileInfo;
}
const std::wstring GetFullPath() const {
return fileInfo.absoluteFilePath().toStdWString();
}
//protected:
void LoadIntoMemory() {
std::ifstream file(GetFullPath(), std::ios::in | std::ios::binary);
if (!file.is_open()) {
throw new std::invalid_argument("Nemohu otevrit soubor");
}
int fileSize = GetFileSize(file);
FileData.AllocateDataMemory(fileSize);
std::shared_ptr<char> dataBuffer = FileData.GetAllocatedMemory();
file.read(dataBuffer.get(), fileSize);
file.close();
}
void ClearMemory() {
std::cout << "FileDelete" << std::endl;
FileData.FreeAllocatedMemory();
}
DataAllocator FileData;
private:
int GetFileSize(std::ifstream & ifstream_) {
ifstream_.seekg(0, std::ios::end);
std::streamoff size = ifstream_.tellg();
ifstream_.seekg(0);
return static_cast<int>(size);
}
QFileInfo fileInfo;
};
#endif // FILELOADER_H