Files
itgmania212121/stepmania/src/RageFile.h
T
Glenn Maynard 33a04b79de beginning GPL->X11 license transition
The conventions I'm using are to put the entire copyright notice at the bottom
of each file, and to put the summary of the source file's use at the top of the
header.

Putting the license text in each file avoids confusion, and is normal practice
for many projects.  Putting it at the bottom gets it out of the way; it's a
ton of clutter to put at the top.

The description is in the header.  People who don't know what a class is for,
or how to use it, are probably looking at the header to see the interface,
not the implementation, so let's put the description in there.  Keep it brief
(one line); any substantial implementation notes should go in the source file.
2004-05-06 00:42:06 +00:00

95 lines
2.3 KiB
C++

/*
* RageFile: high-level file abstraction
*/
#ifndef RAGE_FILE_H
#define RAGE_FILE_H
class RageFileObj;
class RageFile
{
friend class RageFileObj;
public:
enum
{
READ = 0x1,
WRITE = 0x2,
/* Always write directly to the destination file; don't do a safe write. (for logs) */
STREAMED = 0x4,
/* Flush the file to disk on close. Combined with not streaming, this results
* in very safe writes, but is slow. */
SLOW_FLUSH = 0x8
};
RageFile();
RageFile( const CString& path, int mode = READ );
~RageFile() { Close(); }
RageFile( const RageFile &cpy );
/* Use GetRealPath to get the path this file was opened with; use that if you
* want a path that will probably get you the same file again.
*
* GetPath can be overridden by drivers. Use it to get a path for display;
* it may give more information, such as the name of the archive the file
* is in. It has no parsable meaning. */
const CString &GetRealPath() const { return m_Path; }
CString GetPath() const;
bool Open( const CString& path, int mode = READ );
void Close();
bool IsOpen() const { return m_File != NULL; }
int GetOpenMode() const { return m_Mode; }
bool AtEOF() const { return m_EOF; }
CString GetError() const { return m_Error; }
void ClearError() { m_Error = ""; }
int Tell() const { return m_FilePos; }
int Seek( int offset );
int SeekCur( int offset );
int GetFileSize() const;
void Rewind();
/* Raw I/O: */
int Read( void *buffer, size_t bytes );
int Read( CString &buffer, int bytes = -1 );
int Write( const void *buffer, size_t bytes );
int Write( const CString& string ) { return Write( string.data(), string.size() ); }
int Flush();
/* These are just here to make wrappers (eg. vorbisfile, SDL_rwops) easier. */
int Write( const void *buffer, size_t bytes, int nmemb );
int Read( void *buffer, size_t bytes, int nmemb );
int Seek( int offset, int whence );
/* Line-based I/O: */
CString GetLine();
int GetLine( CString &out );
int PutLine( const CString &str );
protected:
void SetError( const CString &err ) { m_Error = err; } /* called by RageFileObj::SetError */
private:
void ResetBuf();
RageFileObj *m_File;
CString m_Path;
int m_Mode;
CString m_Error;
bool m_EOF;
int m_FilePos;
enum { BSIZE = 256 };
char m_Buffer[BSIZE];
char *m_pBuf;
int m_BufUsed;
};
#endif