Adam Lesinski | a40e972 | 2015-11-24 19:11:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 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 |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 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. |
| 15 | */ |
| 16 | |
| 17 | #ifndef AAPT_IO_FILESYSTEM_H |
| 18 | #define AAPT_IO_FILESYSTEM_H |
| 19 | |
| 20 | #include "io/File.h" |
Adam Lesinski | a6fe345 | 2015-12-09 15:20:52 -0800 | [diff] [blame^] | 21 | |
| 22 | #include <map> |
Adam Lesinski | a40e972 | 2015-11-24 19:11:46 -0800 | [diff] [blame] | 23 | |
| 24 | namespace aapt { |
| 25 | namespace io { |
| 26 | |
| 27 | /** |
| 28 | * A regular file from the file system. Uses mmap to open the data. |
| 29 | */ |
| 30 | class RegularFile : public IFile { |
| 31 | public: |
Adam Lesinski | a6fe345 | 2015-12-09 15:20:52 -0800 | [diff] [blame^] | 32 | RegularFile(const Source& source); |
Adam Lesinski | a40e972 | 2015-11-24 19:11:46 -0800 | [diff] [blame] | 33 | |
Adam Lesinski | a6fe345 | 2015-12-09 15:20:52 -0800 | [diff] [blame^] | 34 | std::unique_ptr<IData> openAsData() override; |
| 35 | const Source& getSource() const override; |
Adam Lesinski | a40e972 | 2015-11-24 19:11:46 -0800 | [diff] [blame] | 36 | |
| 37 | private: |
| 38 | Source mSource; |
| 39 | }; |
| 40 | |
Adam Lesinski | a6fe345 | 2015-12-09 15:20:52 -0800 | [diff] [blame^] | 41 | class FileCollection; |
| 42 | |
| 43 | class FileCollectionIterator : public IFileCollectionIterator { |
| 44 | public: |
| 45 | FileCollectionIterator(FileCollection* collection); |
| 46 | |
| 47 | bool hasNext() override; |
| 48 | io::IFile* next() override; |
| 49 | |
| 50 | private: |
| 51 | std::map<std::string, std::unique_ptr<IFile>>::const_iterator mCurrent, mEnd; |
| 52 | }; |
| 53 | |
Adam Lesinski | a40e972 | 2015-11-24 19:11:46 -0800 | [diff] [blame] | 54 | /** |
| 55 | * An IFileCollection representing the file system. |
| 56 | */ |
| 57 | class FileCollection : public IFileCollection { |
| 58 | public: |
| 59 | /** |
| 60 | * Adds a file located at path. Returns the IFile representation of that file. |
| 61 | */ |
Adam Lesinski | a6fe345 | 2015-12-09 15:20:52 -0800 | [diff] [blame^] | 62 | IFile* insertFile(const StringPiece& path); |
| 63 | IFile* findFile(const StringPiece& path) override; |
| 64 | std::unique_ptr<IFileCollectionIterator> iterator() override; |
Adam Lesinski | a40e972 | 2015-11-24 19:11:46 -0800 | [diff] [blame] | 65 | |
| 66 | private: |
Adam Lesinski | a6fe345 | 2015-12-09 15:20:52 -0800 | [diff] [blame^] | 67 | friend class FileCollectionIterator; |
| 68 | std::map<std::string, std::unique_ptr<IFile>> mFiles; |
Adam Lesinski | a40e972 | 2015-11-24 19:11:46 -0800 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | } // namespace io |
| 72 | } // namespace aapt |
| 73 | |
| 74 | #endif // AAPT_IO_FILESYSTEM_H |