Panda3D
Loading...
Searching...
No Matches
virtualFileMountAndroidAsset.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file virtualFileMountAndroidAsset.h
10 * @author rdb
11 * @date 2013-01-21
12 */
13
14#ifndef VIRTUALFILEMOUNTANDROIDASSET_H
15#define VIRTUALFILEMOUNTANDROIDASSET_H
16
17#ifdef ANDROID
18
19#include "pandabase.h"
20
21#include "virtualFileMount.h"
22#include "multifile.h"
23#include "pointerTo.h"
24
25#include <android/asset_manager.h>
26
27/**
28 * Maps a Multifile's contents into the VirtualFileSystem.
29 */
30class EXPCL_PANDA_EXPRESS VirtualFileMountAndroidAsset : public VirtualFileMount {
31PUBLISHED:
32 INLINE VirtualFileMountAndroidAsset(AAssetManager *mgr, const std::string &apk_path);
33 virtual ~VirtualFileMountAndroidAsset();
34
35public:
36 int get_fd(const Filename &file, off_t *start, off_t *end) const;
37
38 virtual bool has_file(const Filename &file) const;
39 virtual bool is_directory(const Filename &file) const;
40 virtual bool is_regular_file(const Filename &file) const;
41
42 virtual bool read_file(const Filename &file, bool do_uncompress,
43 vector_uchar &result) const;
44
45 virtual std::istream *open_read_file(const Filename &file) const;
46 virtual std::streamsize get_file_size(const Filename &file, std::istream *stream) const;
47 virtual std::streamsize get_file_size(const Filename &file) const;
48 virtual time_t get_timestamp(const Filename &file) const;
49 virtual bool get_system_info(const Filename &file, SubfileInfo &info);
50
51 virtual bool scan_directory(vector_string &contents,
52 const Filename &dir) const;
53
54private:
55 AAssetManager *_asset_mgr;
56 std::string _apk_path;
57
58 class AssetStream : public std::istream {
59 public:
60 INLINE AssetStream(AAsset *asset);
61 virtual ~AssetStream();
62 };
63
64 class AssetStreamBuf : public std::streambuf {
65 public:
66 AssetStreamBuf(AAsset *asset);
67 virtual ~AssetStreamBuf();
68
69 virtual std::streampos seekoff(std::streamoff off, ios_seekdir dir, ios_openmode which);
70 virtual std::streampos seekpos(std::streampos pos, ios_openmode which);
71
72 protected:
73 virtual int underflow();
74
75 private:
76 AAsset *_asset;
77 off_t _offset;
78
79 friend class VirtualFileMountAndroidAsset;
80 };
81
82public:
83 virtual TypeHandle get_type() const {
84 return get_class_type();
85 }
86 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
87 static TypeHandle get_class_type() {
88 return _type_handle;
89 }
90 static void init_type() {
91 VirtualFileMount::init_type();
92 register_type(_type_handle, "VirtualFileMountAndroidAsset",
93 VirtualFileMount::get_class_type());
94 }
95
96private:
97 static TypeHandle _type_handle;
98};
99
101
102#endif // ANDROID
103
104#endif
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
This class records a particular byte sub-range within an existing file on disk.
Definition subfileInfo.h:26
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
The abstract base class for a mount definition used within a VirtualFileSystem.
virtual bool read_file(const Filename &file, bool do_uncompress, vector_uchar &result) const
Fills up the indicated pvector with the contents of the file, if it is a regular file.
virtual bool get_system_info(const Filename &file, SubfileInfo &info)
Populates the SubfileInfo structure with the data representing where the file actually resides on dis...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.