blob: 9fca3980d964e3a0f572c68bdc89aaa5e74968c2 [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_FILE_H
18#define AAPT_IO_FILE_H
19
20#include "Source.h"
21#include "io/Data.h"
22
23#include <memory>
24#include <vector>
25
26namespace aapt {
27namespace io {
28
29/**
30 * Interface for a file, which could be a real file on the file system, or a file inside
31 * a ZIP archive.
32 */
33class IFile {
34public:
35 virtual ~IFile() = default;
36
37 /**
38 * Open the file and return it as a block of contiguous memory. How this occurs is
39 * implementation dependent. For example, if this is a file on the file system, it may
40 * simply mmap the contents. If this file represents a compressed file in a ZIP archive,
41 * it may need to inflate it to memory, incurring a copy.
42 *
43 * Returns nullptr on failure.
44 */
45 virtual std::unique_ptr<IData> openAsData() = 0;
46
47 /**
48 * Returns the source of this file. This is for presentation to the user and may not be a
49 * valid file system path (for example, it may contain a '@' sign to separate the files within
50 * a ZIP archive from the path to the containing ZIP archive.
51 */
52 virtual const Source& getSource() const = 0;
53};
54
55/**
56 * Interface for a collection of files, all of which share a common source. That source may
57 * simply be the filesystem, or a ZIP archive.
58 */
59class IFileCollection {
60public:
61 virtual ~IFileCollection() = default;
62
63 using const_iterator = std::vector<std::unique_ptr<IFile>>::const_iterator;
64
65 virtual const_iterator begin() const = 0;
66 virtual const_iterator end() const = 0;
67};
68
69} // namespace io
70} // namespace aapt
71
72#endif /* AAPT_IO_FILE_H */