29.07.2011 - fundamental new

This commit is contained in:
peri4
2011-07-29 08:17:24 +04:00
parent b21a0496cd
commit 29190ea465
49 changed files with 4704 additions and 1052 deletions

View File

@@ -1,7 +1,7 @@
#include "pifile.h"
bool PIFile::open(const PIString & path_, Flags<Mode> mode_) {
bool PIFile::open(const PIString & path_, PIFlags<Mode> mode_) {
cpath = path_;
cmode = mode_;
string st = cpath.stdString();
@@ -18,7 +18,26 @@ bool PIFile::open(const PIString & path_, Flags<Mode> mode_) {
PIString PIFile::readLine() {
char * buff = new char[4096];
stream.getline(buff, 4096);
return string(buff);
return PIString(buff);
}
int PIFile::readAll(void * data) {
int cp = pos(), s = size();
stream.seekg(0);
stream.read((char * )data, s);
seek(cp);
return s;
}
PIByteArray PIFile::readAll() {
int s = size();
if (s < 0) return PIByteArray();
PIByteArray a(s);
s = readAll(a.data());
if (s >= 0) a.resize(s);
return a;
}
@@ -26,17 +45,11 @@ int PIFile::size() {
int s, cp = stream.tellg();
stream.seekg(0, fstream::end);
s = stream.tellg();
stream.seekg(cp);
stream.seekg(cp, fstream::beg);
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;
@@ -56,3 +69,10 @@ int PIFile::pos() {
if (cmode[Write]) return stream.tellp();
return -1;
}
PIFile PIFile::openTemporary(PIFlags<PIFile::Mode> mode) {
char * rc;
rc = tmpnam(0);
return PIFile(PIString(rc), mode);
}