blob: c8e8ab71237a7a1011215e96dc26f5303864d1ad [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>
27#include <androidfw/ResourceTypes.h>
28#include <memory>
29#include <vector>
30#include <unordered_set>
31
32namespace aapt {
33
34/**
35 * Encapsulates the search of library sources as well as the local ResourceTable.
36 */
37class ResourceTableResolver : public IResolver {
38public:
39 /**
40 * Creates a resolver with a local ResourceTable and an AssetManager
41 * loaded with library packages.
42 */
43 ResourceTableResolver(std::shared_ptr<const ResourceTable> table,
44 std::shared_ptr<const android::AssetManager> sources);
45
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
54 const android::ResTable& getResTable() const;
55
56private:
57 struct CacheEntry {
58 ResourceId id;
59 std::unique_ptr<Attribute> attr;
60 };
61
62 const CacheEntry* buildCacheEntry(const ResourceName& name);
63
64 std::shared_ptr<const ResourceTable> mTable;
65 std::shared_ptr<const android::AssetManager> mSources;
66 std::map<ResourceName, CacheEntry> mCache;
67 std::unordered_set<std::u16string> mIncludedPackages;
68};
69
Adam Lesinski24aad162015-04-24 19:19:30 -070070inline const android::ResTable& ResourceTableResolver::getResTable() const {
71 return mSources->getResources(false);
72}
73
74} // namespace aapt
75
76#endif // AAPT_RESOURCE_TABLE_RESOLVER_H