mirror of https://github.com/PCSX2/pcsx2.git
... do the same thing for File_Reader.h as I did for Database_Loader.h in r3101 (translation: added semi-important C++ redtape syntax).
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@3104 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
parent
81c35c9fcc
commit
15ac11b82e
|
@ -74,7 +74,7 @@ public:
|
||||||
|
|
||||||
class DataBase_Loader {
|
class DataBase_Loader {
|
||||||
private:
|
private:
|
||||||
template<class T> string toString(T value) {
|
template<class T> string toString(const T& value) {
|
||||||
stringstream ss(ios_base::in | ios_base::out);
|
stringstream ss(ios_base::in | ios_base::out);
|
||||||
string tString;
|
string tString;
|
||||||
ss << value;
|
ss << value;
|
||||||
|
|
|
@ -1,143 +1,141 @@
|
||||||
/* PCSX2 - PS2 Emulator for PCs
|
/* PCSX2 - PS2 Emulator for PCs
|
||||||
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
||||||
*
|
*
|
||||||
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
||||||
* of the GNU Lesser General Public License as published by the Free Software Found-
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
||||||
* ation, either version 3 of the License, or (at your option) any later version.
|
* ation, either version 3 of the License, or (at your option) any later version.
|
||||||
*
|
*
|
||||||
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||||
* PURPOSE. See the GNU General Public License for more details.
|
* PURPOSE. See the GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License along with PCSX2.
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
||||||
* If not, see <http://www.gnu.org/licenses/>.
|
* If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class File_Reader {
|
class File_Reader {
|
||||||
private:
|
private:
|
||||||
char buff[2048];
|
char buff[2048];
|
||||||
template<class T> T _read() {
|
template<class T> T _read() {
|
||||||
if (fs->eof()) throw 1;
|
if (fs->eof()) throw 1;
|
||||||
T t; (*fs) >> t;
|
T t; (*fs) >> t;
|
||||||
if (fs->fail()) throw 1;
|
if (fs->fail()) throw 1;
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
fstream* fs;
|
fstream* fs;
|
||||||
File_Reader(string filename) {
|
File_Reader(const string& filename) {
|
||||||
fs = new fstream(filename.c_str(), ios_base::in);
|
fs = new fstream(filename.c_str(), ios_base::in);
|
||||||
}
|
}
|
||||||
~File_Reader() {
|
virtual ~File_Reader() throw() {
|
||||||
if (fs) fs->close();
|
if (fs) fs->close();
|
||||||
delete fs;
|
delete fs;
|
||||||
}
|
}
|
||||||
template<class T> void read(T &t) {
|
template<class T> void read(T &t) {
|
||||||
long pos = fs->tellp();
|
long pos = fs->tellp();
|
||||||
string s = _read<string>();
|
string s( _read<string>() );
|
||||||
if (s.length() >= 2) {
|
if (s.length() >= 2) {
|
||||||
if (s[0] == '/' && s[1] == '/') {
|
if (s[0] == '/' && s[1] == '/') {
|
||||||
fs->seekp(pos);
|
fs->seekp(pos);
|
||||||
fs->getline(buff, 1024);
|
fs->getline(buff, 1024);
|
||||||
read(t);
|
read(t);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fs->seekp(pos);
|
fs->seekp(pos);
|
||||||
t = _read<T>();
|
t = _read<T>();
|
||||||
}
|
}
|
||||||
void readRaw(void* ptr, int size) {
|
void readRaw(void* ptr, int size) {
|
||||||
u8* p = (u8*)ptr;
|
u8* p = (u8*)ptr;
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
p[i] = _read<u8>();
|
p[i] = _read<u8>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ignoreLine() {
|
void ignoreLine() {
|
||||||
fs->getline(buff, sizeof(buff));
|
fs->getline(buff, sizeof(buff));
|
||||||
}
|
}
|
||||||
string getLine() {
|
string getLine() {
|
||||||
if (fs->eof()) throw 1;
|
if (fs->eof()) throw 1;
|
||||||
fs->getline(buff, sizeof(buff));
|
fs->getline(buff, sizeof(buff));
|
||||||
if (fs->fail()) throw 1;
|
if (fs->fail()) throw 1;
|
||||||
|
|
||||||
string ret(buff);
|
string ret(buff);
|
||||||
int eol = ret.rfind("\r");
|
int eol = ret.rfind("\r");
|
||||||
if (eol != string::npos) ret = ret.substr(0, eol);
|
if (eol != string::npos) ret = ret.substr(0, eol);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<class T> void readLine(T& str) {
|
template<class T> void readLine(T& str) {
|
||||||
if (fs->eof()) throw 1;
|
if (fs->eof()) throw 1;
|
||||||
fs->getline(buff, sizeof(buff));
|
fs->getline(buff, sizeof(buff));
|
||||||
if (fs->fail()) throw 1;
|
if (fs->fail()) throw 1;
|
||||||
string t(buff);
|
string t(buff);
|
||||||
str = t;
|
str = t;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class File_Writer {
|
class File_Writer {
|
||||||
public:
|
public:
|
||||||
fstream* fs;
|
ScopedPtr<fstream> fs;
|
||||||
File_Writer(string filename) {
|
File_Writer(const string& filename) {
|
||||||
fs = new fstream(filename.c_str(), ios_base::out);
|
fs = new fstream(filename.c_str(), ios_base::out);
|
||||||
}
|
}
|
||||||
~File_Writer() {
|
virtual ~File_Writer() throw() { }
|
||||||
if (fs) fs->close();
|
|
||||||
delete fs;
|
template<class T> void write(const T& t) {
|
||||||
}
|
(*fs) << t;
|
||||||
template<class T> void write(T t) {
|
}
|
||||||
(*fs) << t;
|
void writeRaw(const void* ptr, int size) {
|
||||||
}
|
const u8* p = (u8*)ptr;
|
||||||
void writeRaw(void* ptr, int size) {
|
for (int i = 0; i < size; i++) {
|
||||||
u8* p = (u8*)ptr;
|
write(p[i]);
|
||||||
for (int i = 0; i < size; i++) {
|
}
|
||||||
write(p[i]);
|
}
|
||||||
}
|
};
|
||||||
}
|
|
||||||
};
|
class String_Stream {
|
||||||
|
private:
|
||||||
class String_Stream {
|
char buff[2048];
|
||||||
private:
|
public:
|
||||||
char buff[2048];
|
stringstream* ss;
|
||||||
public:
|
String_Stream() {
|
||||||
stringstream* ss;
|
ss = new stringstream(stringstream::in | stringstream::out);
|
||||||
String_Stream() {
|
}
|
||||||
ss = new stringstream(stringstream::in | stringstream::out);
|
String_Stream(const string& str) {
|
||||||
}
|
ss = new stringstream(str, stringstream::in | stringstream::out);
|
||||||
String_Stream(string& str) {
|
}
|
||||||
ss = new stringstream(str, stringstream::in | stringstream::out);
|
virtual ~String_Stream() throw() {
|
||||||
}
|
delete ss;
|
||||||
~String_Stream() {
|
}
|
||||||
delete ss;
|
template<class T> void write(const T& t) {
|
||||||
}
|
(*ss) << t;
|
||||||
template<class T> void write(T t) {
|
}
|
||||||
(*ss) << t;
|
template<class T> void read(T& t) {
|
||||||
}
|
(*ss) >> t;
|
||||||
template<class T> void read(T &t) {
|
}
|
||||||
(*ss) >> t;
|
string toString() {
|
||||||
}
|
return ss->str();
|
||||||
string toString() {
|
}
|
||||||
return ss->str();
|
string getLine() {
|
||||||
}
|
ss->getline(buff, sizeof(buff));
|
||||||
string getLine() {
|
return buff;
|
||||||
ss->getline(buff, sizeof(buff));
|
}
|
||||||
return string(buff);
|
wxString getLineWX() {
|
||||||
}
|
ss->getline(buff, sizeof(buff));
|
||||||
wxString getLineWX() {
|
return wxString(fromUTF8(buff));
|
||||||
ss->getline(buff, sizeof(buff));
|
}
|
||||||
return wxString(fromUTF8(buff));
|
bool finished() {
|
||||||
}
|
return ss->eof() || ss->fail();
|
||||||
bool finished() {
|
}
|
||||||
return ss->eof() || ss->fail();
|
};
|
||||||
}
|
|
||||||
};
|
static bool fileExists(const string& file) {
|
||||||
|
FILE *f = fopen(file.c_str(), "r");
|
||||||
static bool fileExists(string file) {
|
if (!f) return false;
|
||||||
FILE *f = fopen(file.c_str(), "r");
|
fclose(f);
|
||||||
if (!f) return false;
|
return true;
|
||||||
fclose(f);
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue