35 lines
741 B
C++
35 lines
741 B
C++
|
//
|
||
|
// Created by quentin on 8/4/22.
|
||
|
//
|
||
|
|
||
|
|
||
|
#include "data.h"
|
||
|
|
||
|
#include <utility>
|
||
|
#include <fstream>
|
||
|
#include <vector>
|
||
|
|
||
|
|
||
|
template<class T>
|
||
|
Data<T>::Data(std::string file) : fileName(std::move(file)) {
|
||
|
// Create file if it doesnt exist
|
||
|
std::fstream fstream(getFilePath(), std::ios::out | std::ios::app);
|
||
|
fstream.close();
|
||
|
|
||
|
std::ifstream ifstream(getFilePath(), std::ios::in | std::ios::binary | std::ios::ate);
|
||
|
std::ifstream::pos_type fileSize = ifstream.tellg();
|
||
|
ifstream.seekg(0, std::ios::beg);
|
||
|
|
||
|
std::vector<char> bytes(fileSize);
|
||
|
ifstream.read(bytes.data(), fileSize);
|
||
|
|
||
|
document.Parse(std::string(bytes.data(), fileSize).c_str());
|
||
|
|
||
|
ifstream.close();
|
||
|
}
|
||
|
|
||
|
template<class T>
|
||
|
std::string Data<T>::getFilePath() {
|
||
|
return fileName;
|
||
|
}
|