#include "pifile.h" bool PIFile::open(const string & path_, Flags mode_) { cpath = path_; cmode = mode_; if (cmode[New]) { stream.open(cpath.c_str(), fstream::in | fstream::out | fstream::trunc); stream.close(); cmode &= ~New; stream.open(cpath.c_str(), (fstream::openmode)(int)cmode | fstream::binary); } else stream.open(cpath.c_str(), (fstream::openmode)(int)cmode | fstream::binary); return isOpened(); } string PIFile::readLine() { char * buff = new char[4096]; stream.getline(buff, 4096); return string(buff); } int PIFile::size() { int s, cp = stream.tellg(); stream.seekg(0, fstream::end); s = stream.tellg(); stream.seekg(cp); return s; } void PIFile::seek(int position) { if (cmode[Read]) stream.seekg(position); if (cmode[Write]) stream.seekp(position); } void PIFile::resize(int new_size, char fill_) { int ds = new_size - size(); if (ds == 0) return; if (ds > 0) { char * buff = new char[ds]; memset(buff, fill_, ds); stream.write(buff, ds); delete buff; return; } cout << "[PIFile] Downsize is not support yet :-(" << endl; } int PIFile::pos() { if (cmode[Read]) return stream.tellg(); if (cmode[Write]) return stream.tellp(); return -1; }