UGDK  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ugdk::filesystem::File Class Referenceabstract

#include <ugdk/filesystem/file.h>

Public Member Functions

virtual ~File ()
 
virtual std::string filename () const =0
 
virtual int64 size () const =0
 
virtual int64 Seek (int64 offset, SeekPositions whence)=0
 
int64 Tell ()
 
virtual std::size_t ReadRaw (void *ptr, std::size_t size, std::size_t maxnum)=0
 
template<class T >
std::size_t Read (T *ptr, std::size_t maxnum=1)
 
virtual std::size_t WriteRaw (const void *ptr, std::size_t size, std::size_t num)=0
 
template<class T >
std::size_t Write (const T *ptr, std::size_t num=1)
 
virtual bool Close ()=0
 
std::string GetContents ()
 
bool CanSeek ()
 
int fgetc ()
 
char * fgets (char *str, int count)
 

Protected Member Functions

 File ()
 

Constructor & Destructor Documentation

virtual ugdk::filesystem::File::~File ( )
inlinevirtual
ugdk::filesystem::File::File ( )
inlineprotected

Member Function Documentation

bool ugdk::filesystem::File::CanSeek ( )
Returns
Whether this file can successfully seek.
virtual bool ugdk::filesystem::File::Close ( )
pure virtual

Flushes data and closes the file. Any operations on a closed file are undefined behaviour.

Returns
True on success, false on error.
int ugdk::filesystem::File::fgetc ( )

Reads the next character from the given input stream.

Returns
The obtained character on success or EOF on failure.
char* ugdk::filesystem::File::fgets ( char *  str,
int  count 
)

Reads at most count - 1 characters from the given file stream and stores them in str. The produced character string is always null-terminated. Parsing stops if end-of-file occurs or a newline character is found, in which case str will contain that newline character.

Parameters
strstring to read the characters to
countthe length of str
Returns
str on success, NULL on failure.
virtual std::string ugdk::filesystem::File::filename ( ) const
pure virtual

The name of the file this object represents. There's no guarantee a request to open a file with the name returned will succeed.

Returns
A string containing a filepath, or a special string for files that don't exist in the file system.
std::string ugdk::filesystem::File::GetContents ( )

Get the whole file in a string. Can only be used in files supporting seek.

Returns
A string containing the contents of the file.
template<class T >
std::size_t ugdk::filesystem::File::Read ( T *  ptr,
std::size_t  maxnum = 1 
)
inline

Reads up to maxnum objects of type T and save at ptr.

Parameters
ptrThe buffer where the objects will be saved.
maxnumThe maximum number of objects to be read.
Returns
The number of objects read, or 0 if end of file or error.
See also
ReadRaw
virtual std::size_t ugdk::filesystem::File::ReadRaw ( void *  ptr,
std::size_t  size,
std::size_t  maxnum 
)
pure virtual

Reads up to maxnum blocks of the given size and save at ptr.

Parameters
ptrThe buffer where the data will be saved.
sizeThe size of each memory block to be read, in bytes.
maxnumThe maximum number of blocks to be read.
Returns
The number of blocks read, or 0 if end of file or error.
virtual int64 ugdk::filesystem::File::Seek ( int64  offset,
SeekPositions  whence 
)
pure virtual

Seek to an offset of whence.

Parameters
offsetThe offset to the given location.
whenceOne of the SeekPositions.
Returns
The final offset in the file stream, relative to the start. -1 if an error occured.
virtual int64 ugdk::filesystem::File::size ( ) const
pure virtual
Returns
The size of this file, or -1 if unknown.
int64 ugdk::filesystem::File::Tell ( )
Returns
The current offset in the file stream, relative to the start.
See also
Seek
template<class T >
std::size_t ugdk::filesystem::File::Write ( const T *  ptr,
std::size_t  num = 1 
)
inline

Writes num objects of type T from ptr.

Parameters
ptrThe buffer from where the objects are read.
numThe number of objects to write.
Returns
The number of objects written, or 0 if end of file or error.
See also
WriteRaw
virtual std::size_t ugdk::filesystem::File::WriteRaw ( const void *  ptr,
std::size_t  size,
std::size_t  num 
)
pure virtual

Writes num blocks of the given size from ptr.

Parameters
ptrThe buffer from where the data is read.
sizeThe size of each memory block to be written, in bytes.
maxnumThe maximum number of blocks to be written.
Returns
The number of blocks written, or 0 if end of file or error.

The documentation for this class was generated from the following file: