blob: 84f851ff694b93391bac26e8c68df8e17910f52c [file] [log] [blame]
Adam Lesinskia40e9722015-11-24 19:11:46 -08001/*
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
Adam Lesinskia6fe3452015-12-09 15:20:52 -080020#include <map>
Adam Lesinskia40e9722015-11-24 19:11:46 -080021
Adam Lesinskice5e56e2016-10-21 17:56:45 -070022#include "io/File.h"
23
Adam Lesinskia40e9722015-11-24 19:11:46 -080024namespace aapt {
25namespace io {
26
27/**
28 * A regular file from the file system. Uses mmap to open the data.
29 */
30class RegularFile : public IFile {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070031 public:
32 explicit RegularFile(const Source& source);
Adam Lesinskia40e9722015-11-24 19:11:46 -080033
Adam Lesinskice5e56e2016-10-21 17:56:45 -070034 std::unique_ptr<IData> OpenAsData() override;
35 const Source& GetSource() const override;
Adam Lesinskia40e9722015-11-24 19:11:46 -080036
Adam Lesinskicacb28f2016-10-19 12:18:14 -070037 private:
Adam Lesinskice5e56e2016-10-21 17:56:45 -070038 Source source_;
Adam Lesinskia40e9722015-11-24 19:11:46 -080039};
40
Adam Lesinskia6fe3452015-12-09 15:20:52 -080041class FileCollection;
42
43class FileCollectionIterator : public IFileCollectionIterator {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070044 public:
45 explicit FileCollectionIterator(FileCollection* collection);
Adam Lesinskia6fe3452015-12-09 15:20:52 -080046
Adam Lesinskice5e56e2016-10-21 17:56:45 -070047 bool HasNext() override;
48 io::IFile* Next() override;
Adam Lesinskia6fe3452015-12-09 15:20:52 -080049
Adam Lesinskicacb28f2016-10-19 12:18:14 -070050 private:
Adam Lesinskice5e56e2016-10-21 17:56:45 -070051 std::map<std::string, std::unique_ptr<IFile>>::const_iterator current_, end_;
Adam Lesinskia6fe3452015-12-09 15:20:52 -080052};
53
Adam Lesinskia40e9722015-11-24 19:11:46 -080054/**
55 * An IFileCollection representing the file system.
56 */
57class FileCollection : public IFileCollection {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070058 public:
59 /**
60 * Adds a file located at path. Returns the IFile representation of that file.
61 */
Adam Lesinskice5e56e2016-10-21 17:56:45 -070062 IFile* InsertFile(const StringPiece& path);
63 IFile* FindFile(const StringPiece& path) override;
64 std::unique_ptr<IFileCollectionIterator> Iterator() override;
Adam Lesinskia40e9722015-11-24 19:11:46 -080065
Adam Lesinskicacb28f2016-10-19 12:18:14 -070066 private:
67 friend class FileCollectionIterator;
Adam Lesinskice5e56e2016-10-21 17:56:45 -070068 std::map<std::string, std::unique_ptr<IFile>> files_;
Adam Lesinskia40e9722015-11-24 19:11:46 -080069};
70
Adam Lesinskicacb28f2016-10-19 12:18:14 -070071} // namespace io
72} // namespace aapt
Adam Lesinskia40e9722015-11-24 19:11:46 -080073
Adam Lesinskicacb28f2016-10-19 12:18:14 -070074#endif // AAPT_IO_FILESYSTEM_H