Beatmup
Beatmup::Android::Asset Class Reference

Android assets reader. More...

#include <asset.h>

Inheritance diagram for Beatmup::Android::Asset:
Beatmup::InputStream

Public Member Functions

 Asset (AAssetManager *manager, const char *path)
 
 ~Asset ()
 
bool operator() (void *buffer, msize bytes)
 Reads a given number of bytes into a specific memory location. More...
 
bool seek (msize pos)
 Moves the read pointer to a given position in the stream. More...
 
bool eof () const
 Returns true, if the end of the stream is reached (i.e., all the data is read or the stream is empty). More...
 

Private Attributes

AAsset * asset
 

Detailed Description

Android assets reader.

Implements InputStream interface enabling access to Android assets.

Definition at line 64 of file asset.h.

Constructor & Destructor Documentation

◆ Asset()

Asset::Asset ( AAssetManager *  manager,
const char *  path 
)

Definition at line 73 of file asset.cpp.

73  {
74  asset = AAssetManager_open(manager, path, AASSET_MODE_STREAMING);
75  if (!asset)
76  throw IOError(path, "Cannot access the asset");
77 }

◆ ~Asset()

Asset::~Asset ( )

Definition at line 79 of file asset.cpp.

79  {
80  AAsset_close(asset);
81 }

Member Function Documentation

◆ operator()()

bool Asset::operator() ( void *  buffer,
msize  bytes 
)
virtual

Reads a given number of bytes into a specific memory location.

Parameters
[in]bufferThe address to store the data to
[in]bytesNumber of bytes to read
Returns
true on success.

Implements Beatmup::InputStream.

Definition at line 83 of file asset.cpp.

83  {
84  if (bytes == 0)
85  return true;
86  return AAsset_read(asset, buffer, bytes) > 0;
87 }

◆ seek()

bool Asset::seek ( msize  pos)
virtual

Moves the read pointer to a given position in the stream.

Parameters
posThe position in bytes from the beginning of the stream
Returns
true on success.

Implements Beatmup::InputStream.

Definition at line 89 of file asset.cpp.

89  {
90  auto result = AAsset_seek64(asset, pos, SEEK_SET);
91  return result != (off64_t) -1;
92 }
Beatmup::IntPoint result

◆ eof()

bool Asset::eof ( ) const
virtual

Returns true, if the end of the stream is reached (i.e., all the data is read or the stream is empty).

Implements Beatmup::InputStream.

Definition at line 94 of file asset.cpp.

94  {
95  return AAsset_getRemainingLength(asset) <= 0;
96 }

Member Data Documentation

◆ asset

AAsset* Beatmup::Android::Asset::asset
private

Definition at line 66 of file asset.h.


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