nCine 2022.04.r504-20bd01e
A cross-platform 2D game engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
ncine::AssetFile Class Reference

The class dealing with Android asset files. More...

#include <AssetFile.h>

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

Public Member Functions

 AssetFile (const char *filename)
 Constructs an asset file object.
 
void open (unsigned char mode) override
 Tries to open the asset file.
 
void close () override
 Closes the asset file.
 
long int seek (long int offset, int whence) const override
 Seeks in an opened file.
 
long int tell () const override
 Tells the seek position of an opened file.
 
unsigned long int read (void *buffer, unsigned long int bytes) const override
 Reads a certain amount of bytes from the file to a buffer.
 
unsigned long int write (const void *buffer, unsigned long int bytes) override
 Writes a certain amount of bytes from a buffer to the file.
 
bool isOpened () const override
 Returns true if the file has been sucessfully opened.
 
- Public Member Functions inherited from ncine::IFile
 IFile (const char *filename)
 Constructs a base file object.
 
FileType type () const
 Returns the file type (RTTI)
 
void setCloseOnDestruction (bool shouldCloseOnDestruction)
 Sets the close on destruction flag.
 
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 void initAssetManager (struct android_app *state)
 Sets the global pointer to the AAssetManager.
 
static const char * assetPath (const char *path)
 Returns the path of an Android asset without the prefix.
 
static bool tryOpen (const char *path)
 Checks if an asset path exists as a file or as a directory and can be opened.
 
static bool tryOpenFile (const char *path)
 Checks if an asset path exists and can be opened as a file.
 
static bool tryOpenDirectory (const char *path)
 Checks if an asset path exists and can be opened as a directory.
 
static off_t length (const char *path)
 Returns the total size of the asset data.
 
static AAssetDir * openDir (const char *dirName)
 
static void closeDir (AAssetDir *assetDir)
 
static void rewindDir (AAssetDir *assetDir)
 
static const char * nextFileName (AAssetDir *assetDir)
 
- Static Public Member Functions inherited from ncine::IFile
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.
 

Static Public Attributes

static const char * Prefix = "asset::"
 

Additional Inherited Members

- Public Types inherited from ncine::IFile
enum class  FileType { BASE = 0 , MEMORY , STANDARD , ASSET }
 File types.
 
- Protected Attributes inherited from ncine::IFile
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 inherited from ncine::IFile
static const unsigned int MaxFilenameLength = 256
 Maximum number of characters for a file name (path included)
 

Detailed Description

The class dealing with Android asset files.

Constructor & Destructor Documentation

◆ AssetFile()

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

Constructs an asset file object.

Parameters
filenameFile name including path relative to the assets directory

Member Function Documentation

◆ close()

void ncine::AssetFile::close ( )
overridevirtual

Closes the asset file.

This method will close a file both normally opened or fopened

Implements ncine::IFile.

◆ isOpened()

bool ncine::AssetFile::isOpened ( ) const
overridevirtual

Returns true if the file has been sucessfully opened.

Reimplemented from ncine::IFile.

◆ open()

void ncine::AssetFile::open ( unsigned char  mode)
overridevirtual

Tries to open the asset file.

Implements ncine::IFile.

◆ read()

unsigned long int ncine::AssetFile::read ( void *  buffer,
unsigned long int  bytes 
) const
overridevirtual

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

Returns
Number of bytes read

Implements ncine::IFile.

◆ seek()

long int ncine::AssetFile::seek ( long int  offset,
int  whence 
) const
overridevirtual

Seeks in an opened file.

Implements ncine::IFile.

◆ tell()

long int ncine::AssetFile::tell ( ) const
overridevirtual

Tells the seek position of an opened file.

Implements ncine::IFile.

◆ write()

unsigned long int ncine::AssetFile::write ( const void *  buffer,
unsigned long int  bytes 
)
inlineoverridevirtual

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

Returns
Number of bytes written

Implements ncine::IFile.


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