7.12.2010 - add PIString

This commit is contained in:
peri4
2010-12-07 01:55:30 +03:00
parent e321b5187d
commit 08f214dbfa
10 changed files with 360 additions and 134 deletions

View File

@@ -3,6 +3,7 @@
#include <fstream>
#include "piincludes.h"
#include "pistring.h"
using std::fstream;
@@ -11,19 +12,19 @@ class PIFile
public:
PIFile() {;}
enum Mode {Read = fstream::in, Write = fstream::out, Truncate = fstream::trunc, New = fstream::app};
PIFile(const string & path, Flags<Mode> mode = Read | Write) {open(path, mode);}
PIFile(const PIString & path, Flags<Mode> mode = Read | Write) {open(path, mode);}
~PIFile() {if (isOpened()) close();}
bool open(const string & path, Flags<Mode> mode = Read | Write);
bool open(const PIString & path, Flags<Mode> mode = Read | Write);
void close() {stream.close();}
void clear() {close(); stream.open(cpath.c_str(), fstream::trunc | (fstream::openmode)(int)cmode);}
void clear() {close(); stream.open(cpath, fstream::trunc | (fstream::openmode)(int)cmode);}
void seek(int position);
void resize(int new_size, char fill = 0);
void fill(char c) {stream.fill(c);}
void flush() {stream.flush();}
string readLine();
PIString readLine();
string path() const {return cpath;}
PIString path() const {return cpath;}
Flags<Mode> mode() const {return cmode;}
int size();
int pos();
@@ -45,7 +46,8 @@ public:
PIFile & writeBinary(const double v) {stream.write((char * )&v, sizeof(v)); return *this;}
PIFile & operator <<(const char & v) {stream.write(&v, 1); return *this;}
PIFile & operator <<(const string & v) {stream.write(v.c_str(), v.size()); return *this;}
//PIFile & operator <<(const string & v) {stream.write(v.c_str(), v.size()); return *this;}
PIFile & operator <<(const PIString & v) {stream.write(v.data(), v.size()); return *this;}
PIFile & operator <<(const short & v) {stream << v; return *this;}
PIFile & operator <<(const int & v) {stream << v; return *this;}
PIFile & operator <<(const long & v) {stream << v; return *this;}
@@ -69,7 +71,7 @@ public:
private:
fstream stream;
string cpath;
PIString cpath;
Flags<Mode> cmode;
};