Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

RageFile.h

Go to the documentation of this file.
00001 /* 00002 * RageFile: high-level file abstraction 00003 */ 00004 00005 #ifndef RAGE_FILE_H 00006 #define RAGE_FILE_H 00007 00008 #include "RageFileBasic.h" 00009 00010 /* This is the high-level interface, which interfaces with RageFileObj implementations 00011 * and RageFileManager. */ 00012 class RageFile: public RageFileBasic 00013 { 00014 public: 00015 enum 00016 { 00017 READ = 0x1, 00018 WRITE = 0x2, 00019 00020 /* Always write directly to the destination file; don't do a safe write. (for logs) */ 00021 STREAMED = 0x4, 00022 00023 /* Flush the file to disk on close. Combined with not streaming, this results 00024 * in very safe writes, but is slow. */ 00025 SLOW_FLUSH = 0x8 00026 }; 00027 00028 RageFile(); 00029 ~RageFile() { Close(); } 00030 RageFile( const RageFile &cpy ); 00031 RageFileBasic *Copy() const; 00032 00033 /* Use GetRealPath to get the path this file was opened with; use that if you 00034 * want a path that will probably get you the same file again. 00035 * 00036 * GetPath can be overridden by drivers. Use it to get a path for display; 00037 * it may give more information, such as the name of the archive the file 00038 * is in. It has no parsable meaning. */ 00039 const CString &GetRealPath() const { return m_Path; } 00040 CString GetPath() const; 00041 00042 bool Open( const CString& path, int mode = READ ); 00043 void Close(); 00044 bool IsOpen() const { return m_File != NULL; } 00045 00046 bool AtEOF() const; 00047 CString GetError() const; 00048 void ClearError(); 00049 bool IsGood() const { return IsOpen() && !AtEOF() && GetError().empty(); } 00050 00051 int Tell() const; 00052 int Seek( int offset ); 00053 int GetFileSize() const; 00054 00055 /* Raw I/O: */ 00056 int Read( void *buffer, size_t bytes ); 00057 int Read( CString &buffer, int bytes = -1 ); 00058 int Write( const void *buffer, size_t bytes ); 00059 int Write( const CString& string ) { return Write( string.data(), string.size() ); } 00060 int Flush(); 00061 00062 /* These are just here to make wrappers (eg. vorbisfile, SDL_rwops) easier. */ 00063 int Write( const void *buffer, size_t bytes, int nmemb ); 00064 int Read( void *buffer, size_t bytes, int nmemb ); 00065 int Seek( int offset, int whence ); 00066 00067 /* Line-based I/O: */ 00068 int GetLine( CString &out ); 00069 int PutLine( const CString &str ); 00070 00071 void EnableCRC32( bool on=true ); 00072 bool GetCRC32( uint32_t *iRet ); 00073 00074 protected: 00075 void SetError( const CString &err ); 00076 00077 private: 00078 RageFileBasic *m_File; 00079 CString m_Path; 00080 CString m_sError; 00081 int m_Mode; 00082 }; 00083 00084 /* Convenience wrappers for reading binary files. */ 00085 namespace FileReading 00086 { 00087 /* On error, these set sError to the error message. If sError is already 00088 * non-empty, nothing happens. */ 00089 void ReadBytes( RageFileBasic &f, void *buf, int size, CString &sError ); 00090 void SkipBytes( RageFileBasic &f, int size, CString &sError ); 00091 void Seek( RageFileBasic &f, int iOffset, CString &sError ); 00092 uint8_t read_8( RageFileBasic &f, CString &sError ); 00093 int16_t read_16_le( RageFileBasic &f, CString &sError ); 00094 uint16_t read_u16_le( RageFileBasic &f, CString &sError ); 00095 int32_t read_32_le( RageFileBasic &f, CString &sError ); 00096 uint32_t read_u32_le( RageFileBasic &f, CString &sError ); 00097 }; 00098 00099 #endif

Generated on Thu Jan 27 20:57:27 2005 for StepMania by doxygen 1.3.7