Beatmup
Beatmup::Android::AssetPath Class Reference

Path to assets in Android Used to reach a specific location. More...

#include <asset.h>

Public Member Functions

 AssetPath (AAssetManager *manager, const char *path="")
 
 ~AssetPath ()
 
void follow (const char *path)
 
bool up ()
 Goes one level up ("..") from the current asset folder. More...
 
msize listFiles (std::vector< std::string > &files)
 Lists files in the current folder. More...
 

Static Public Attributes

static const char PATH_DELIMITER = '/'
 

Private Attributes

AAssetManager * manager
 
std::vector< AAssetDir * > path
 

Detailed Description

Path to assets in Android Used to reach a specific location.

Definition at line 34 of file asset.h.

Constructor & Destructor Documentation

◆ AssetPath()

AssetPath::AssetPath ( AAssetManager *  manager,
const char *  path = "" 
)

Definition at line 25 of file asset.cpp.

25  : manager(manager) {
26  follow(path_);
27 }
AAssetManager * manager
Definition: asset.h:36
void follow(const char *path)
Definition: asset.cpp:35

◆ ~AssetPath()

AssetPath::~AssetPath ( )

Definition at line 29 of file asset.cpp.

29  {
30  for (auto _ = path.rbegin(); _ != path.rend(); ++_) {
31  AAssetDir_close(*_);
32  }
33 }
std::vector< AAssetDir * > path
Definition: asset.h:37

Member Function Documentation

◆ follow()

void AssetPath::follow ( const char *  path)

Definition at line 35 of file asset.cpp.

35  {
36  size_t pos = 0;
37  std::string path(path_);
38  do {
39  size_t i = path.find(PATH_DELIMITER, pos);
40  if (i == std::string::npos)
41  i = path.length() + 1;
42  std::string dir(path.substr(pos, i - pos - 1));
43  if (dir == "..")
44  up();
45  else
46  this->path.push_back( AAssetManager_openDir(manager, dir.c_str()) );
47  pos = i + 1;
48  } while (pos < path.length());
49 }
static const char PATH_DELIMITER
Definition: asset.h:39
bool up()
Goes one level up ("..") from the current asset folder.
Definition: asset.cpp:64

◆ up()

bool AssetPath::up ( )

Goes one level up ("..") from the current asset folder.

Definition at line 64 of file asset.cpp.

64  {
65  if (path.size() <= 1)
66  return false;
67  AAssetDir_close(path.back());
68  path.pop_back();
69  return true;
70 }

◆ listFiles()

msize AssetPath::listFiles ( std::vector< std::string > &  files)

Lists files in the current folder.

Parameters
[out]filesA list of strings the names of files in the current folder are appended to
Returns
number of files in the current folder.

Definition at line 51 of file asset.cpp.

51  {
52  if (path.empty())
53  return (msize)0;
54  const char* filename = nullptr;
55  msize counter = 0;
56  while (( filename = AAssetDir_getNextFileName(path.back()) ) != nullptr) {
57  files.emplace_back(filename);
58  counter++;
59  }
60  AAssetDir_rewind(path.back());
61  return counter;
62 }
uint32_t msize
memory size
Definition: basic_types.h:30
JNIEnv jlong jstring filename

Member Data Documentation

◆ manager

AAssetManager* Beatmup::Android::AssetPath::manager
private

Definition at line 36 of file asset.h.

◆ path

std::vector<AAssetDir*> Beatmup::Android::AssetPath::path
private

Definition at line 37 of file asset.h.

◆ PATH_DELIMITER

const char Beatmup::Android::AssetPath::PATH_DELIMITER = '/'
static

Definition at line 39 of file asset.h.


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