Beatmup
asset.h
Go to the documentation of this file.
1 /*
2  Beatmup image and signal processing library
3  Copyright (C) 2020, lnstadrum
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 
21 #include "../input_stream.h"
22 #include "../chunkfile.h"
23 #include <android/asset_manager.h>
24 #include <vector>
25 #include <string>
26 
27 namespace Beatmup {
28  namespace Android {
29 
30  /**
31  Path to assets in Android
32  Used to reach a specific location.
33  */
34  class AssetPath {
35  private:
36  AAssetManager *manager;
37  std::vector<AAssetDir*> path;
38  public:
39  static const char PATH_DELIMITER = '/';
40 
41  AssetPath(AAssetManager* manager, const char* path = "");
42  ~AssetPath();
43 
44  void follow(const char* path);
45 
46  /**
47  Goes one level up ("..") from the current asset folder
48  */
49  bool up();
50 
51  /**
52  Lists files in the current folder
53  \param[out] files A list of strings the names of files in the current folder are appended to
54  \return number of files in the current folder.
55  */
56  msize listFiles(std::vector<std::string>& files);
57  };
58 
59 
60  /**
61  Android assets reader.
62  Implements InputStream interface enabling access to Android assets.
63  */
64  class Asset : public InputStream {
65  private:
66  AAsset* asset;
67  public:
68  Asset(AAssetManager* manager, const char* path);
69  ~Asset();
70 
71  bool operator()(void * buffer, msize bytes);
72  bool seek(msize pos);
73  bool eof() const;
74  };
75 
76 
77  /**
78  Asset containing chunks.
79  */
80  class ChunkAsset : public ChunkStream {
81  private:
83  public:
84  /**
85  Creates a read-only chunk collection from an asset.
86  \param[in] manager AAssetManager instance
87  \param[in] filename The asset file name / path
88  */
89  ChunkAsset(AAssetManager* manager, const std::string& filename);
90  inline void open() {}
91  inline void close() {}
92  };
93  }
94 }
Path to assets in Android Used to reach a specific location.
Definition: asset.h:34
AAssetManager * manager
Definition: asset.h:36
static const char PATH_DELIMITER
Definition: asset.h:39
AssetPath(AAssetManager *manager, const char *path="")
Definition: asset.cpp:25
bool up()
Goes one level up ("..") from the current asset folder.
Definition: asset.cpp:64
std::vector< AAssetDir * > path
Definition: asset.h:37
void follow(const char *path)
Definition: asset.cpp:35
msize listFiles(std::vector< std::string > &files)
Lists files in the current folder.
Definition: asset.cpp:51
Android assets reader.
Definition: asset.h:64
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)...
Definition: asset.cpp:94
bool operator()(void *buffer, msize bytes)
Reads a given number of bytes into a specific memory location.
Definition: asset.cpp:83
bool seek(msize pos)
Moves the read pointer to a given position in the stream.
Definition: asset.cpp:89
Asset(AAssetManager *manager, const char *path)
Definition: asset.cpp:73
Asset containing chunks.
Definition: asset.h:80
void open()
Opens the collection to read chunks from it.
Definition: asset.h:90
void close()
Closes the collection after a reading session.
Definition: asset.h:91
ChunkAsset(AAssetManager *manager, const std::string &filename)
Creates a read-only chunk collection from an asset.
Definition: asset.cpp:99
Stream of chunks.
Definition: chunkfile.h:132
Minimal input stream interface.
Definition: input_stream.h:27
uint32_t msize
memory size
Definition: basic_types.h:30
JNIEnv jlong jstring filename