30.11.2010 - initial commit

This commit is contained in:
peri4
2010-11-30 08:11:27 +03:00
commit 2925e4d786
24 changed files with 2403 additions and 0 deletions

57
pifile.cpp Normal file
View File

@@ -0,0 +1,57 @@
#include "pifile.h"
bool PIFile::open(const string & path_, Flags<Mode> 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;
}