Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 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_RESOLVER_H |
| 18 | #define AAPT_RESOLVER_H |
| 19 | |
| 20 | #include "Maybe.h" |
| 21 | #include "Resource.h" |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 22 | #include "ResourceValues.h" |
| 23 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 24 | #include <androidfw/ResourceTypes.h> |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 25 | |
| 26 | namespace aapt { |
| 27 | |
| 28 | /** |
| 29 | * Resolves symbolic references (package:type/entry) into resource IDs/objects. |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 30 | */ |
Adam Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 31 | class IResolver { |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 32 | public: |
Adam Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 33 | virtual ~IResolver() {}; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 34 | |
| 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 Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 55 | * 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 Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 58 | virtual Maybe<ResourceId> findId(const ResourceName& name) = 0; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 59 | |
| 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 Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 64 | virtual Maybe<Entry> findAttribute(const ResourceName& name) = 0; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 65 | |
Adam Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 66 | /** |
| 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 Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 71 | }; |
| 72 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 73 | } // namespace aapt |
| 74 | |
| 75 | #endif // AAPT_RESOLVER_H |