/* Copyright (C) Teemu Suutari */ #include "onekpaq_common.h" #include "CacheFile.hpp" void CacheFile::clear(uint numBlocks) { _numBlocks=numBlocks; _combine.clear(); _header.clear(); } bool CacheFile::readFile(const std::string &fileName) { bool ret=false; std::ifstream file(fileName.c_str(),std::ios::in|std::ios::binary); if (file.is_open()) { _shift=readUint(file); _numBlocks=readUint(file); uint numCombinedBlocks=readUint(file); _combine.clear(); _header.clear(); for (uint i=0;file&&i(&ret),sizeof(ret)); return ret; } std::vector CacheFile::readVector(std::ifstream &stream) { std::vector ret; uint length=readUint(stream); if (stream&&length) { ret.resize(length); stream.read(reinterpret_cast(ret.data()),length); } return ret; } void CacheFile::writeUint(std::ofstream &stream,uint value) { if (!stream) return; // x86 only u32 tmp=value; stream.write(reinterpret_cast(&tmp),sizeof(tmp)); } void CacheFile::writeVector(std::ofstream &stream,const std::vector &vector) { writeUint(stream,uint(vector.size())); if (stream&&vector.size()) stream.write(reinterpret_cast(vector.data()),vector.size()); }