diff --git a/pcsx2/DataBase_Loader.h b/pcsx2/DataBase_Loader.h index cf303ae6c0..91d8f2babc 100644 --- a/pcsx2/DataBase_Loader.h +++ b/pcsx2/DataBase_Loader.h @@ -74,7 +74,7 @@ public: class DataBase_Loader { private: - template string toString(T value) { + template string toString(const T& value) { stringstream ss(ios_base::in | ios_base::out); string tString; ss << value; diff --git a/pcsx2/File_Reader.h b/pcsx2/File_Reader.h index 1d0f9b0849..f9ed829ddc 100644 --- a/pcsx2/File_Reader.h +++ b/pcsx2/File_Reader.h @@ -1,143 +1,141 @@ -/* PCSX2 - PS2 Emulator for PCs - * Copyright (C) 2002-2010 PCSX2 Dev Team - * - * 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- - * 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; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * 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. - * If not, see . - */ - -#pragma once - -using namespace std; - -class File_Reader { -private: - char buff[2048]; - template T _read() { - if (fs->eof()) throw 1; - T t; (*fs) >> t; - if (fs->fail()) throw 1; - return t; - } -public: - fstream* fs; - File_Reader(string filename) { - fs = new fstream(filename.c_str(), ios_base::in); - } - ~File_Reader() { - if (fs) fs->close(); - delete fs; - } - template void read(T &t) { - long pos = fs->tellp(); - string s = _read(); - if (s.length() >= 2) { - if (s[0] == '/' && s[1] == '/') { - fs->seekp(pos); - fs->getline(buff, 1024); - read(t); - return; - } - } - fs->seekp(pos); - t = _read(); - } - void readRaw(void* ptr, int size) { - u8* p = (u8*)ptr; - for (int i = 0; i < size; i++) { - p[i] = _read(); - } - } - void ignoreLine() { - fs->getline(buff, sizeof(buff)); - } - string getLine() { - if (fs->eof()) throw 1; - fs->getline(buff, sizeof(buff)); +/* PCSX2 - PS2 Emulator for PCs + * Copyright (C) 2002-2010 PCSX2 Dev Team + * + * 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- + * 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; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * 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. + * If not, see . + */ + +#pragma once + +using namespace std; + +class File_Reader { +private: + char buff[2048]; + template T _read() { + if (fs->eof()) throw 1; + T t; (*fs) >> t; + if (fs->fail()) throw 1; + return t; + } +public: + fstream* fs; + File_Reader(const string& filename) { + fs = new fstream(filename.c_str(), ios_base::in); + } + virtual ~File_Reader() throw() { + if (fs) fs->close(); + delete fs; + } + template void read(T &t) { + long pos = fs->tellp(); + string s( _read() ); + if (s.length() >= 2) { + if (s[0] == '/' && s[1] == '/') { + fs->seekp(pos); + fs->getline(buff, 1024); + read(t); + return; + } + } + fs->seekp(pos); + t = _read(); + } + void readRaw(void* ptr, int size) { + u8* p = (u8*)ptr; + for (int i = 0; i < size; i++) { + p[i] = _read(); + } + } + void ignoreLine() { + fs->getline(buff, sizeof(buff)); + } + string getLine() { + if (fs->eof()) throw 1; + fs->getline(buff, sizeof(buff)); if (fs->fail()) throw 1; string ret(buff); int eol = ret.rfind("\r"); if (eol != string::npos) ret = ret.substr(0, eol); - - return ret; - } - template void readLine(T& str) { - if (fs->eof()) throw 1; - fs->getline(buff, sizeof(buff)); - if (fs->fail()) throw 1; - string t(buff); - str = t; - } -}; - -class File_Writer { -public: - fstream* fs; - File_Writer(string filename) { - fs = new fstream(filename.c_str(), ios_base::out); - } - ~File_Writer() { - if (fs) fs->close(); - delete fs; - } - template void write(T t) { - (*fs) << t; - } - void writeRaw(void* ptr, int size) { - u8* p = (u8*)ptr; - for (int i = 0; i < size; i++) { - write(p[i]); - } - } -}; - -class String_Stream { -private: - char buff[2048]; -public: - stringstream* ss; - String_Stream() { - ss = new stringstream(stringstream::in | stringstream::out); - } - String_Stream(string& str) { - ss = new stringstream(str, stringstream::in | stringstream::out); - } - ~String_Stream() { - delete ss; - } - template void write(T t) { - (*ss) << t; - } - template void read(T &t) { - (*ss) >> t; - } - string toString() { - return ss->str(); - } - string getLine() { - ss->getline(buff, sizeof(buff)); - return string(buff); - } - wxString getLineWX() { - ss->getline(buff, sizeof(buff)); - return wxString(fromUTF8(buff)); - } - bool finished() { - return ss->eof() || ss->fail(); - } -}; - -static bool fileExists(string file) { - FILE *f = fopen(file.c_str(), "r"); - if (!f) return false; - fclose(f); - return true; -} + + return ret; + } + template void readLine(T& str) { + if (fs->eof()) throw 1; + fs->getline(buff, sizeof(buff)); + if (fs->fail()) throw 1; + string t(buff); + str = t; + } +}; + +class File_Writer { +public: + ScopedPtr fs; + File_Writer(const string& filename) { + fs = new fstream(filename.c_str(), ios_base::out); + } + virtual ~File_Writer() throw() { } + + template void write(const T& t) { + (*fs) << t; + } + void writeRaw(const void* ptr, int size) { + const u8* p = (u8*)ptr; + for (int i = 0; i < size; i++) { + write(p[i]); + } + } +}; + +class String_Stream { +private: + char buff[2048]; +public: + stringstream* ss; + String_Stream() { + ss = new stringstream(stringstream::in | stringstream::out); + } + String_Stream(const string& str) { + ss = new stringstream(str, stringstream::in | stringstream::out); + } + virtual ~String_Stream() throw() { + delete ss; + } + template void write(const T& t) { + (*ss) << t; + } + template void read(T& t) { + (*ss) >> t; + } + string toString() { + return ss->str(); + } + string getLine() { + ss->getline(buff, sizeof(buff)); + return buff; + } + wxString getLineWX() { + ss->getline(buff, sizeof(buff)); + return wxString(fromUTF8(buff)); + } + bool finished() { + return ss->eof() || ss->fail(); + } +}; + +static bool fileExists(const string& file) { + FILE *f = fopen(file.c_str(), "r"); + if (!f) return false; + fclose(f); + return true; +}