blob: cb9318e24917946075b466fe8472cb990d7ae9f8 [file] [log] [blame]
Adam Lesinski6f6ceb72014-11-14 14:48:12 -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_RESOLVER_H
18#define AAPT_RESOLVER_H
19
20#include "Maybe.h"
21#include "Resource.h"
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080022#include "ResourceValues.h"
23
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080024#include <androidfw/ResourceTypes.h>
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080025
26namespace aapt {
27
28/**
29 * Resolves symbolic references (package:type/entry) into resource IDs/objects.
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080030 */
Adam Lesinski24aad162015-04-24 19:19:30 -070031class IResolver {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080032public:
Adam Lesinski24aad162015-04-24 19:19:30 -070033 virtual ~IResolver() {};
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080034
35 /**
36 * Holds the result of a resource name lookup.
37 */
38 struct Entry {
39 /**
40 * The ID of the resource. ResourceId::isValid() may
41 * return false if the resource has not been assigned
42 * an ID.
43 */
44 ResourceId id;
45
46 /**
47 * If the resource is an attribute, this will point
48 * to a valid Attribute object, or else it will be
49 * nullptr.
50 */
51 const Attribute* attr;
52 };
53
54 /**
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080055 * Returns a ResourceID if the name is found. The ResourceID
56 * may not be valid if the resource was not assigned an ID.
57 */
Adam Lesinski24aad162015-04-24 19:19:30 -070058 virtual Maybe<ResourceId> findId(const ResourceName& name) = 0;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080059
60 /**
61 * Returns an Entry if the name is found. Entry::attr
62 * may be nullptr if the resource is not an attribute.
63 */
Adam Lesinski24aad162015-04-24 19:19:30 -070064 virtual Maybe<Entry> findAttribute(const ResourceName& name) = 0;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080065
Adam Lesinski24aad162015-04-24 19:19:30 -070066 /**
67 * Find a resource by ID. Resolvers may contain resources without
68 * resource IDs assigned to them.
69 */
70 virtual Maybe<ResourceName> findName(ResourceId resId) = 0;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080071};
72
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080073} // namespace aapt
74
75#endif // AAPT_RESOLVER_H