2 * Copyright (C) 2006 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 // Access a chunk of the asset hierarchy as if it were a single directory.
20 #ifndef __LIBS_ASSETDIR_H
21 #define __LIBS_ASSETDIR_H
23 #include <androidfw/misc.h>
24 #include <utils/String8.h>
25 #include <utils/Vector.h>
26 #include <utils/SortedVector.h>
27 #include <sys/types.h>
32 * This provides vector-style access to a directory. We do this rather
33 * than modeling opendir/readdir access because it's simpler and the
34 * nature of the operation requires us to have all data on hand anyway.
36 * The list of files will be sorted in ascending order by ASCII value.
38 * The contents are populated by our friend, the AssetManager.
45 virtual ~AssetDir(void) {
50 * Vector-style access.
52 size_t getFileCount(void) { return mFileInfo->size(); }
53 const String8& getFileName(int idx) {
54 return mFileInfo->itemAt(idx).getFileName();
56 const String8& getSourceName(int idx) {
57 return mFileInfo->itemAt(idx).getSourceName();
61 * Get the type of a file (usually regular or directory).
63 FileType getFileType(int idx) {
64 return mFileInfo->itemAt(idx).getFileType();
68 /* these operations are not implemented */
69 AssetDir(const AssetDir& src);
70 const AssetDir& operator=(const AssetDir& src);
72 friend class AssetManager;
75 * This holds information about files in the asset hierarchy.
80 FileInfo(const String8& path) // useful for e.g. svect.indexOf
81 : mFileName(path), mFileType(kFileTypeUnknown)
84 FileInfo(const FileInfo& src) {
87 const FileInfo& operator= (const FileInfo& src) {
93 void copyMembers(const FileInfo& src) {
94 mFileName = src.mFileName;
95 mFileType = src.mFileType;
96 mSourceName = src.mSourceName;
99 /* need this for SortedVector; must compare only on file name */
100 bool operator< (const FileInfo& rhs) const {
101 return mFileName < rhs.mFileName;
104 /* used by AssetManager */
105 bool operator== (const FileInfo& rhs) const {
106 return mFileName == rhs.mFileName;
109 void set(const String8& path, FileType type) {
114 const String8& getFileName(void) const { return mFileName; }
115 void setFileName(const String8& path) { mFileName = path; }
117 FileType getFileType(void) const { return mFileType; }
118 void setFileType(FileType type) { mFileType = type; }
120 const String8& getSourceName(void) const { return mSourceName; }
121 void setSourceName(const String8& path) { mSourceName = path; }
124 * Handy utility for finding an entry in a sorted vector of FileInfo.
125 * Returns the index of the matching entry, or -1 if none found.
127 static int findEntry(const SortedVector<FileInfo>* pVector,
128 const String8& fileName);
131 String8 mFileName; // filename only
132 FileType mFileType; // regular, directory, etc
134 String8 mSourceName; // currently debug-only
137 /* AssetManager uses this to initialize us */
138 void setFileList(SortedVector<FileInfo>* list) { mFileInfo = list; }
140 SortedVector<FileInfo>* mFileInfo;
143 }; // namespace android
145 #endif // __LIBS_ASSETDIR_H