nCine 2022.04.r504-96e4859
A cross-platform 2D game engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
ncine::IFile Class Referenceabstract

The interface class dealing with file operations. More...

#include <IFile.h>

Inheritance diagram for ncine::IFile:
Inheritance graph
[legend]
Collaboration diagram for ncine::IFile:
Collaboration graph
[legend]

Classes

struct  OpenMode
 Open mode bitmask. More...
 

Public Types

enum class  FileType { BASE = 0 , MEMORY , STANDARD , ASSET }
 File types.
 

Public Member Functions

 IFile (const char *filename)
 Constructs a base file object.
 
FileType type () const
 Returns the file type (RTTI)
 
virtual void open (unsigned char mode)=0
 Tries to open the file.
 
virtual void close ()=0
 Closes the file.
 
virtual long int seek (long int offset, int whence) const =0
 Seeks in an opened file.
 
virtual long int tell () const =0
 Tells the seek position of an opened file.
 
virtual unsigned long int read (void *buffer, unsigned long int bytes) const =0
 Reads a certain amount of bytes from the file to a buffer.
 
virtual unsigned long int write (const void *buffer, unsigned long int bytes)=0
 Writes a certain amount of bytes from a buffer to the file.
 
void setCloseOnDestruction (bool shouldCloseOnDestruction)
 Sets the close on destruction flag.
 
virtual bool isOpened () const
 Returns true if the file has been sucessfully opened.
 
const char * filename () const
 Returns file name with path.
 
int fd () const
 Returns file descriptor.
 
FILE * ptr () const
 Returns file stream pointer.
 
unsigned long int size () const
 Returns file size in bytes.
 
virtual const void * bufferPtr () const
 Returns the constant buffer pointer of a memory file or nullptr for other file types.
 
virtual void * bufferPtr ()
 Returns the buffer pointer of a memory file or nullptr for other file types.
 

Static Public Member Functions

static uint16_t int16FromLE (uint16_t number)
 Reads a little endian 16 bit unsigned integer.
 
static uint32_t int32FromLE (uint32_t number)
 Reads a little endian 32 bit unsigned integer.
 
static uint64_t int64FromLE (uint64_t number)
 Reads a little endian 64 bit unsigned integer.
 
static uint16_t int16FromBE (uint16_t number)
 Reads a big endian 16 bit unsigned integer.
 
static uint32_t int32FromBE (uint32_t number)
 Reads a big endian 32 bit unsigned integer.
 
static uint64_t int64FromBE (uint64_t number)
 Reads a big endian 64 bit unsigned integer.
 
static nctl::UniquePtr< IFilecreateFromMemory (const char *bufferName, unsigned char *bufferPtr, unsigned long int bufferSize)
 Returns a memory file with the specified name.
 
static nctl::UniquePtr< IFilecreateFromMemory (const char *bufferName, const unsigned char *bufferPtr, unsigned long int bufferSize)
 Returns a read-only memory file with the specified name.
 
static nctl::UniquePtr< IFilecreateFromMemory (unsigned char *bufferPtr, unsigned long int bufferSize)
 Returns a memory file.
 
static nctl::UniquePtr< IFilecreateFromMemory (const unsigned char *bufferPtr, unsigned long int bufferSize)
 Returns a read-only memory file.
 
static nctl::UniquePtr< IFilecreateFromMemory (const char *bufferName, unsigned long int bufferSize)
 Returns a memory file with the specified name, that allocates a buffer of the specified size.
 
static nctl::UniquePtr< IFilecreateFromMemory (unsigned long int bufferSize)
 Returns a memory file that allocates a buffer of the specified size.
 
static nctl::UniquePtr< IFilecreateFromMemory (const char *bufferName, nctl::UniquePtr< unsigned char[]> buffer, unsigned long int bufferSize)
 Returns a memory file with the specified name, that takes ownership of the specified buffer.
 
static nctl::UniquePtr< IFilecreateFromMemory (nctl::UniquePtr< unsigned char[]> buffer, unsigned long int bufferSize)
 Returns a memory file that takes ownership of the specified buffer.
 
static nctl::UniquePtr< IFilecreateFileHandle (const char *filename)
 Returns the proper file handle according to prepended tags.
 

Protected Attributes

FileType type_
 File type.
 
nctl::String filename_
 File name with path.
 
int fileDescriptor_
 File descriptor for open() and close()
 
FILE * filePointer_
 File pointer for fopen() and fclose()
 
bool shouldCloseOnDestruction_
 A flag indicating whether the destructor should also close the file.
 
unsigned long int fileSize_
 File size in bytes.
 

Static Protected Attributes

static const unsigned int MaxFilenameLength = 256
 Maximum number of characters for a file name (path included)
 

Friends

class TextureSaverPng
 The TextureSaverPng class needs to access the filePointer_
 

Detailed Description

The interface class dealing with file operations.

Constructor & Destructor Documentation

◆ IFile()

ncine::IFile::IFile ( const char *  filename)
explicit

Constructs a base file object.

Parameters
filenameFile name including its path

Member Function Documentation

◆ close()

virtual void ncine::IFile::close ( )
pure virtual

Closes the file.

Implemented in ncine::AssetFile.

◆ isOpened()

bool ncine::IFile::isOpened ( ) const
virtual

Returns true if the file has been sucessfully opened.

Reimplemented in ncine::AssetFile.

◆ open()

virtual void ncine::IFile::open ( unsigned char  mode)
pure virtual

Tries to open the file.

Implemented in ncine::AssetFile.

◆ read()

virtual unsigned long int ncine::IFile::read ( void *  buffer,
unsigned long int  bytes 
) const
pure virtual

Reads a certain amount of bytes from the file to a buffer.

Returns
Number of bytes read

Implemented in ncine::AssetFile.

◆ seek()

virtual long int ncine::IFile::seek ( long int  offset,
int  whence 
) const
pure virtual

Seeks in an opened file.

Implemented in ncine::AssetFile.

◆ setCloseOnDestruction()

void ncine::IFile::setCloseOnDestruction ( bool  shouldCloseOnDestruction)
inline

Sets the close on destruction flag.

If the flag is true the file is closed upon object destruction.

◆ tell()

virtual long int ncine::IFile::tell ( ) const
pure virtual

Tells the seek position of an opened file.

Implemented in ncine::AssetFile.

◆ write()

virtual unsigned long int ncine::IFile::write ( const void *  buffer,
unsigned long int  bytes 
)
pure virtual

Writes a certain amount of bytes from a buffer to the file.

Returns
Number of bytes written

Implemented in ncine::AssetFile.

Member Data Documentation

◆ shouldCloseOnDestruction_

bool ncine::IFile::shouldCloseOnDestruction_
protected

A flag indicating whether the destructor should also close the file.

Useful for ov_open()/ov_fopen() and ov_clear() functions of the Vorbisfile library.


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