• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_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 
26 namespace aapt {
27 namespace 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  */
33 class IFile {
34 public:
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 class IFileCollectionIterator {
56 public:
57     virtual ~IFileCollectionIterator() = default;
58 
59     virtual bool hasNext() = 0;
60     virtual IFile* next() = 0;
61 };
62 
63 /**
64  * Interface for a collection of files, all of which share a common source. That source may
65  * simply be the filesystem, or a ZIP archive.
66  */
67 class IFileCollection {
68 public:
69     virtual ~IFileCollection() = default;
70 
71     virtual IFile* findFile(const StringPiece& path) = 0;
72     virtual std::unique_ptr<IFileCollectionIterator> iterator() = 0;
73 };
74 
75 } // namespace io
76 } // namespace aapt
77 
78 #endif /* AAPT_IO_FILE_H */
79