blob: 8f6b0b5993e46abf8765363086d1354450e3d45c [file] [log] [blame]
Adam Lesinski24aad162015-04-24 19:19:30 -07001/*
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_RESOURCE_TABLE_RESOLVER_H
18#define AAPT_RESOURCE_TABLE_RESOLVER_H
19
20#include "Maybe.h"
21#include "Resolver.h"
22#include "Resource.h"
23#include "ResourceTable.h"
24#include "ResourceValues.h"
25
26#include <androidfw/AssetManager.h>
Adam Lesinski24aad162015-04-24 19:19:30 -070027#include <memory>
28#include <vector>
29#include <unordered_set>
30
31namespace aapt {
32
33/**
34 * Encapsulates the search of library sources as well as the local ResourceTable.
35 */
36class ResourceTableResolver : public IResolver {
37public:
38 /**
39 * Creates a resolver with a local ResourceTable and an AssetManager
40 * loaded with library packages.
41 */
Adam Lesinski330edcd2015-05-04 17:40:56 -070042 ResourceTableResolver(
43 std::shared_ptr<const ResourceTable> table,
44 const std::vector<std::shared_ptr<const android::AssetManager>>& sources);
Adam Lesinski24aad162015-04-24 19:19:30 -070045
46 ResourceTableResolver(const ResourceTableResolver&) = delete; // Not copyable.
47
Adam Lesinski24aad162015-04-24 19:19:30 -070048 virtual Maybe<ResourceId> findId(const ResourceName& name) override;
49
50 virtual Maybe<Entry> findAttribute(const ResourceName& name) override;
51
52 virtual Maybe<ResourceName> findName(ResourceId resId) override;
53
Adam Lesinski24aad162015-04-24 19:19:30 -070054private:
55 struct CacheEntry {
56 ResourceId id;
57 std::unique_ptr<Attribute> attr;
58 };
59
60 const CacheEntry* buildCacheEntry(const ResourceName& name);
61
62 std::shared_ptr<const ResourceTable> mTable;
Adam Lesinski330edcd2015-05-04 17:40:56 -070063 std::vector<std::shared_ptr<const android::AssetManager>> mSources;
Adam Lesinski24aad162015-04-24 19:19:30 -070064 std::map<ResourceName, CacheEntry> mCache;
65 std::unordered_set<std::u16string> mIncludedPackages;
66};
67
Adam Lesinski24aad162015-04-24 19:19:30 -070068} // namespace aapt
69
70#endif // AAPT_RESOURCE_TABLE_RESOLVER_H