blob: 83818c256a945fc5c35cb66154ff9845639d5677 [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
48 virtual const std::u16string& getDefaultPackage() const override;
49
50 virtual Maybe<ResourceId> findId(const ResourceName& name) override;
51
52 virtual Maybe<Entry> findAttribute(const ResourceName& name) override;
53
54 virtual Maybe<ResourceName> findName(ResourceId resId) override;
55
56 const android::ResTable& getResTable() const;
57
58private:
59 struct CacheEntry {
60 ResourceId id;
61 std::unique_ptr<Attribute> attr;
62 };
63
64 const CacheEntry* buildCacheEntry(const ResourceName& name);
65
66 std::shared_ptr<const ResourceTable> mTable;
67 std::shared_ptr<const android::AssetManager> mSources;
68 std::map<ResourceName, CacheEntry> mCache;
69 std::unordered_set<std::u16string> mIncludedPackages;
70};
71
72inline const std::u16string& ResourceTableResolver::getDefaultPackage() const {
73 return mTable->getPackage();
74}
75
76inline const android::ResTable& ResourceTableResolver::getResTable() const {
77 return mSources->getResources(false);
78}
79
80} // namespace aapt
81
82#endif // AAPT_RESOURCE_TABLE_RESOLVER_H