From b716ee668087fbe3bb1bc0afb77fcba6907b2b22 Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Thu, 27 Nov 2003 07:46:36 +0000 Subject: [PATCH] RageFile class --- stepmania/src/RageFile.cpp | 97 +++++++++++++++++++++++++++++--------- stepmania/src/RageFile.h | 32 +++++++++++++ 2 files changed, 108 insertions(+), 21 deletions(-) diff --git a/stepmania/src/RageFile.cpp b/stepmania/src/RageFile.cpp index b48db6a556..671af67b40 100644 --- a/stepmania/src/RageFile.cpp +++ b/stepmania/src/RageFile.cpp @@ -1,46 +1,101 @@ #include "global.h" /* ------------------------------------------------------------------------------ + ----------------------------------------------------------------------------- Class: RageFile - + Desc: See header. - + Copyright (c) 2001-2003 by the person(s) listed below. All rights reserved. Chris Danford ------------------------------------------------------------------------------ -*/ + Steve Checkoway + ----------------------------------------------------------------------------- + */ +#include "global.h" #include "RageFile.h" #include "RageUtil.h" void FixSlashesInPlace( CString &sPath ) { - sPath.Replace( "/", SLASH ); - sPath.Replace( "\\", SLASH ); + sPath.Replace( "/", SLASH ); + sPath.Replace( "\\", SLASH ); } CString FixSlashes( CString sPath ) { - sPath.Replace( "/", SLASH ); - sPath.Replace( "\\", SLASH ); - return sPath; + sPath.Replace( "/", SLASH ); + sPath.Replace( "\\", SLASH ); + return sPath; } void CollapsePath( CString &sPath ) { - CStringArray as; - split( sPath, SLASH, as ); - - for( unsigned i=0; i +#include using namespace std; // using "std::ifstream" causes problems below in VC6. Why?!? // call FixSlashes on any path that came from the user @@ -22,4 +24,34 @@ CString FixSlashes( CString sPath ); void CollapsePath( CString &sPath ); +class RageFile +{ +private: + FILE *mFP; + CString mPath; + +public: + RageFile() : mPath("") { mFP = NULL; } + RageFile(const CString& path, const char *mode = "r") { Open(path, mode); } + ~RageFile() { Close(); } + + bool Open(const CString& path, const char *mode = "r"); + void Close(); + + bool IsOpen() { return (mFP == NULL); } + bool AtEOF() { return feof(mFP); } + int GetError() { return ferror(mFP); } + FILE *GetFilePointer() { return mFP; } + + long Tell() { return ftell(mFP); } + bool Seek(long offset, int origin = SEEK_CUR) { return !fseek(mFP, offset, origin); } + void Rewind() { rewind(mFP); } + + // GetLine() strips new lines + CString GetLine(); + bool PutString(const CString& string) { return fputs(string, mFP) >= 0; } + size_t Read(void *buffer, size_t bytes); + size_t Write(const void *buffer, size_t bytes); +}; + #endif