// // Created by quentin on 8/4/22. // #include "data.h" #include #include #include #include #include template Data::Data(std::string file) : fileName(std::move(file)) { // Create file if it doesnt exist std::ifstream chkExistIfs; chkExistIfs.open(getFilePath()); if (chkExistIfs) { // File exists, were not creating one chkExistIfs.close(); } else { // File doesnt exist we need to create one chkExistIfs.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 bytes(fileSize); ifstream.read(bytes.data(), fileSize); document.Parse(std::string(bytes.data(), fileSize).c_str()); ifstream.close(); } template std::string Data::getFilePath() { return fileName; } template void Data::flushToFile() { rapidjson::StringBuffer buffer; rapidjson::Writer writer(buffer); document.Accept(writer); std::ofstream file(getFilePath()); file << buffer.GetString(); file.close(); }