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_RESOURCE_H |
| 18 | #define AAPT_RESOURCE_H |
| 19 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 20 | #include <iomanip> |
Adam Lesinski | ca2fc35 | 2015-04-03 12:08:26 -0700 | [diff] [blame] | 21 | #include <limits> |
Iurii Makhno | dfbac39 | 2022-02-15 20:02:52 +0000 | [diff] [blame] | 22 | #include <optional> |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 23 | #include <sstream> |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 24 | #include <string> |
| 25 | #include <tuple> |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 26 | #include <vector> |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 27 | |
MÃ¥rten Kongstad | 24c9aa6 | 2018-06-20 08:46:41 +0200 | [diff] [blame] | 28 | #include "androidfw/ConfigDescription.h" |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 29 | #include "androidfw/Source.h" |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 30 | #include "androidfw/StringPiece.h" |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 31 | #include "utils/JenkinsHash.h" |
| 32 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 33 | namespace aapt { |
| 34 | |
| 35 | /** |
Iurii Makhno | dfbac39 | 2022-02-15 20:02:52 +0000 | [diff] [blame] | 36 | * The various types of resource types available. |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 37 | */ |
| 38 | enum class ResourceType { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 39 | kAnim, |
| 40 | kAnimator, |
| 41 | kArray, |
| 42 | kAttr, |
| 43 | kAttrPrivate, |
| 44 | kBool, |
| 45 | kColor, |
Adam Lesinski | 86d67df | 2017-01-31 13:47:27 -0800 | [diff] [blame] | 46 | |
| 47 | // Not really a type, but it shows up in some CTS tests and |
| 48 | // we need to continue respecting it. |
| 49 | kConfigVarying, |
| 50 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 51 | kDimen, |
| 52 | kDrawable, |
Adam Lesinski | c0c3663 | 2016-10-19 18:37:53 -0700 | [diff] [blame] | 53 | kFont, |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 54 | kFraction, |
| 55 | kId, |
| 56 | kInteger, |
| 57 | kInterpolator, |
| 58 | kLayout, |
Ryan Mitchell | 326e35ff | 2021-04-12 07:50:42 -0700 | [diff] [blame] | 59 | kMacro, |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 60 | kMenu, |
| 61 | kMipmap, |
Adam Lesinski | 3b84124 | 2017-07-25 17:15:42 -0700 | [diff] [blame] | 62 | kNavigation, |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 63 | kPlurals, |
| 64 | kRaw, |
| 65 | kString, |
| 66 | kStyle, |
| 67 | kStyleable, |
| 68 | kTransition, |
| 69 | kXml, |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 70 | }; |
| 71 | |
Jeremy Meyer | 211bec2 | 2024-06-04 14:22:03 -0700 | [diff] [blame] | 72 | enum class FlagStatus { NoFlag = 0, Disabled = 1, Enabled = 2 }; |
| 73 | |
Jeremy Meyer | 3d8d4a1 | 2024-08-23 17:29:03 -0700 | [diff] [blame] | 74 | struct FeatureFlagAttribute { |
| 75 | std::string name; |
| 76 | bool negated = false; |
| 77 | |
| 78 | std::string ToString() { |
| 79 | return (negated ? "!" : "") + name; |
| 80 | } |
| 81 | |
| 82 | bool operator==(const FeatureFlagAttribute& o) const = default; |
| 83 | }; |
| 84 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 85 | android::StringPiece to_string(ResourceType type); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 86 | |
| 87 | /** |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 88 | * Returns a pointer to a valid ResourceType, or nullptr if the string was invalid. |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 89 | */ |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 90 | const ResourceType* ParseResourceType(android::StringPiece str); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 91 | |
| 92 | /** |
Iurii Makhno | dfbac39 | 2022-02-15 20:02:52 +0000 | [diff] [blame] | 93 | * Pair of type name as in ResourceTable and actual resource type. |
| 94 | * Corresponds to the 'type' in package:type/entry. |
| 95 | * |
| 96 | * This is to support resource types with custom names inside resource tables. |
| 97 | */ |
| 98 | struct ResourceNamedType { |
| 99 | std::string name; |
| 100 | ResourceType type = ResourceType::kRaw; |
| 101 | |
| 102 | ResourceNamedType() = default; |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 103 | ResourceNamedType(android::StringPiece n, ResourceType t); |
Iurii Makhno | dfbac39 | 2022-02-15 20:02:52 +0000 | [diff] [blame] | 104 | |
| 105 | int compare(const ResourceNamedType& other) const; |
| 106 | |
| 107 | const std::string& to_string() const; |
| 108 | }; |
| 109 | |
| 110 | /** |
| 111 | * Same as ResourceNamedType, but uses StringPieces instead. |
| 112 | * Use this if you need to avoid copying and know that |
| 113 | * the lifetime of this object is shorter than that |
| 114 | * of the original string. |
| 115 | */ |
| 116 | struct ResourceNamedTypeRef { |
| 117 | android::StringPiece name; |
| 118 | ResourceType type = ResourceType::kRaw; |
| 119 | |
| 120 | ResourceNamedTypeRef() = default; |
| 121 | ResourceNamedTypeRef(const ResourceNamedTypeRef&) = default; |
| 122 | ResourceNamedTypeRef(ResourceNamedTypeRef&&) = default; |
| 123 | ResourceNamedTypeRef(const ResourceNamedType& rhs); // NOLINT(google-explicit-constructor) |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 124 | ResourceNamedTypeRef(android::StringPiece n, ResourceType t); |
Iurii Makhno | dfbac39 | 2022-02-15 20:02:52 +0000 | [diff] [blame] | 125 | ResourceNamedTypeRef& operator=(const ResourceNamedTypeRef& rhs) = default; |
| 126 | ResourceNamedTypeRef& operator=(ResourceNamedTypeRef&& rhs) = default; |
| 127 | ResourceNamedTypeRef& operator=(const ResourceNamedType& rhs); |
| 128 | |
| 129 | ResourceNamedType ToResourceNamedType() const; |
| 130 | |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 131 | std::string_view to_string() const; |
Iurii Makhno | dfbac39 | 2022-02-15 20:02:52 +0000 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | ResourceNamedTypeRef ResourceNamedTypeWithDefaultName(ResourceType t); |
| 135 | |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 136 | std::optional<ResourceNamedTypeRef> ParseResourceNamedType(android::StringPiece s); |
Iurii Makhno | dfbac39 | 2022-02-15 20:02:52 +0000 | [diff] [blame] | 137 | |
| 138 | /** |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 139 | * A resource's name. This can uniquely identify |
| 140 | * a resource in the ResourceTable. |
| 141 | */ |
| 142 | struct ResourceName { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 143 | std::string package; |
Iurii Makhno | cff10ce | 2022-02-15 19:33:50 +0000 | [diff] [blame] | 144 | ResourceNamedType type; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 145 | std::string entry; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 146 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 147 | ResourceName() = default; |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 148 | ResourceName(android::StringPiece p, const ResourceNamedTypeRef& t, android::StringPiece e); |
| 149 | ResourceName(android::StringPiece p, ResourceType t, android::StringPiece e); |
Adam Lesinski | 9ba47d8 | 2015-10-13 11:37:10 -0700 | [diff] [blame] | 150 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 151 | int compare(const ResourceName& other) const; |
Adam Lesinski | 8197cc46 | 2016-08-19 12:16:49 -0700 | [diff] [blame] | 152 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 153 | bool is_valid() const; |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 154 | std::string to_string() const; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 155 | }; |
| 156 | |
| 157 | /** |
| 158 | * Same as ResourceName, but uses StringPieces instead. |
| 159 | * Use this if you need to avoid copying and know that |
| 160 | * the lifetime of this object is shorter than that |
| 161 | * of the original string. |
| 162 | */ |
| 163 | struct ResourceNameRef { |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 164 | android::StringPiece package; |
Iurii Makhno | cff10ce | 2022-02-15 19:33:50 +0000 | [diff] [blame] | 165 | ResourceNamedTypeRef type; |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 166 | android::StringPiece entry; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 167 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 168 | ResourceNameRef() = default; |
| 169 | ResourceNameRef(const ResourceNameRef&) = default; |
| 170 | ResourceNameRef(ResourceNameRef&&) = default; |
Chih-Hung Hsieh | 1fc78e1 | 2018-12-20 13:37:44 -0800 | [diff] [blame] | 171 | ResourceNameRef(const ResourceName& rhs); // NOLINT(google-explicit-constructor) |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 172 | ResourceNameRef(android::StringPiece p, const ResourceNamedTypeRef& t, android::StringPiece e); |
| 173 | ResourceNameRef(android::StringPiece p, ResourceType t, android::StringPiece e); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 174 | ResourceNameRef& operator=(const ResourceNameRef& rhs) = default; |
| 175 | ResourceNameRef& operator=(ResourceNameRef&& rhs) = default; |
| 176 | ResourceNameRef& operator=(const ResourceName& rhs); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 177 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 178 | bool is_valid() const; |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 179 | |
| 180 | ResourceName ToResourceName() const; |
| 181 | std::string to_string() const; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 182 | }; |
| 183 | |
Adam Lesinski | b5dc4bd | 2017-02-22 19:29:29 -0800 | [diff] [blame] | 184 | constexpr const uint8_t kAppPackageId = 0x7fu; |
| 185 | constexpr const uint8_t kFrameworkPackageId = 0x01u; |
| 186 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 187 | /** |
| 188 | * A binary identifier representing a resource. Internally it |
| 189 | * is a 32bit integer split as follows: |
| 190 | * |
| 191 | * 0xPPTTEEEE |
| 192 | * |
| 193 | * PP: 8 bit package identifier. 0x01 is reserved for system |
| 194 | * and 0x7f is reserved for the running app. |
| 195 | * TT: 8 bit type identifier. 0x00 is invalid. |
| 196 | * EEEE: 16 bit entry identifier. |
| 197 | */ |
| 198 | struct ResourceId { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 199 | uint32_t id; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 200 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 201 | ResourceId(); |
Ryan Mitchell | 9634efb | 2021-03-19 14:53:17 -0700 | [diff] [blame] | 202 | ResourceId(const ResourceId& rhs) = default; |
Chih-Hung Hsieh | 1fc78e1 | 2018-12-20 13:37:44 -0800 | [diff] [blame] | 203 | ResourceId(uint32_t res_id); // NOLINT(google-explicit-constructor) |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 204 | ResourceId(uint8_t p, uint8_t t, uint16_t e); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 205 | |
Ryan Mitchell | cd78feb | 2019-12-18 15:20:48 -0800 | [diff] [blame] | 206 | // Returns true if the ID is a valid ID that is not dynamic (package ID cannot be 0) |
| 207 | bool is_valid_static() const; |
Adam Lesinski | ceb9b2f | 2017-02-16 12:05:42 -0800 | [diff] [blame] | 208 | |
| 209 | // Returns true if the ID is a valid ID or dynamic ID (package ID can be 0). |
Ryan Mitchell | cd78feb | 2019-12-18 15:20:48 -0800 | [diff] [blame] | 210 | bool is_valid() const; |
Adam Lesinski | ceb9b2f | 2017-02-16 12:05:42 -0800 | [diff] [blame] | 211 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 212 | uint8_t package_id() const; |
| 213 | uint8_t type_id() const; |
| 214 | uint16_t entry_id() const; |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 215 | |
| 216 | std::string to_string() const; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 217 | }; |
| 218 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 219 | struct SourcedResourceName { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 220 | ResourceName name; |
| 221 | size_t line; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 222 | }; |
| 223 | |
| 224 | struct ResourceFile { |
Adam Lesinski | 0045116 | 2017-10-03 07:44:08 -0700 | [diff] [blame] | 225 | enum class Type { |
| 226 | kUnknown, |
| 227 | kPng, |
| 228 | kBinaryXml, |
| 229 | kProtoXml, |
| 230 | }; |
| 231 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 232 | // Name |
| 233 | ResourceName name; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 234 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 235 | // Configuration |
MÃ¥rten Kongstad | 24c9aa6 | 2018-06-20 08:46:41 +0200 | [diff] [blame] | 236 | android::ConfigDescription config; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 237 | |
Adam Lesinski | 0045116 | 2017-10-03 07:44:08 -0700 | [diff] [blame] | 238 | // Type |
| 239 | Type type; |
| 240 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 241 | // Source |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame] | 242 | android::Source source; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 243 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 244 | // Exported symbols |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 245 | std::vector<SourcedResourceName> exported_symbols; |
Jeremy Meyer | e08e037 | 2024-09-17 12:45:26 -0700 | [diff] [blame] | 246 | |
| 247 | // Flag status |
| 248 | FlagStatus flag_status = FlagStatus::NoFlag; |
| 249 | |
| 250 | // Flag |
| 251 | std::optional<FeatureFlagAttribute> flag; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 252 | }; |
| 253 | |
Adam Lesinski | a6fe345 | 2015-12-09 15:20:52 -0800 | [diff] [blame] | 254 | /** |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 255 | * Useful struct used as a key to represent a unique resource in associative |
| 256 | * containers. |
Adam Lesinski | a6fe345 | 2015-12-09 15:20:52 -0800 | [diff] [blame] | 257 | */ |
| 258 | struct ResourceKey { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 259 | ResourceName name; |
MÃ¥rten Kongstad | 24c9aa6 | 2018-06-20 08:46:41 +0200 | [diff] [blame] | 260 | android::ConfigDescription config; |
Adam Lesinski | a6fe345 | 2015-12-09 15:20:52 -0800 | [diff] [blame] | 261 | }; |
| 262 | |
| 263 | bool operator<(const ResourceKey& a, const ResourceKey& b); |
| 264 | |
| 265 | /** |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 266 | * Useful struct used as a key to represent a unique resource in associative |
| 267 | * containers. |
Adam Lesinski | a6fe345 | 2015-12-09 15:20:52 -0800 | [diff] [blame] | 268 | * Holds a reference to the name, so that name better live longer than this key! |
| 269 | */ |
| 270 | struct ResourceKeyRef { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 271 | ResourceNameRef name; |
MÃ¥rten Kongstad | 24c9aa6 | 2018-06-20 08:46:41 +0200 | [diff] [blame] | 272 | android::ConfigDescription config; |
Adam Lesinski | a6fe345 | 2015-12-09 15:20:52 -0800 | [diff] [blame] | 273 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 274 | ResourceKeyRef() = default; |
MÃ¥rten Kongstad | 24c9aa6 | 2018-06-20 08:46:41 +0200 | [diff] [blame] | 275 | ResourceKeyRef(const ResourceNameRef& n, const android::ConfigDescription& c) |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 276 | : name(n), config(c) {} |
Adam Lesinski | a6fe345 | 2015-12-09 15:20:52 -0800 | [diff] [blame] | 277 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 278 | /** |
| 279 | * Prevent taking a reference to a temporary. This is bad. |
| 280 | */ |
MÃ¥rten Kongstad | 24c9aa6 | 2018-06-20 08:46:41 +0200 | [diff] [blame] | 281 | ResourceKeyRef(ResourceName&& n, const android::ConfigDescription& c) = delete; |
Adam Lesinski | a6fe345 | 2015-12-09 15:20:52 -0800 | [diff] [blame] | 282 | }; |
| 283 | |
| 284 | bool operator<(const ResourceKeyRef& a, const ResourceKeyRef& b); |
| 285 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 286 | // |
| 287 | // ResourceId implementation. |
| 288 | // |
| 289 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 290 | inline ResourceId::ResourceId() : id(0) {} |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 291 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 292 | inline ResourceId::ResourceId(uint32_t res_id) : id(res_id) {} |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 293 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 294 | inline ResourceId::ResourceId(uint8_t p, uint8_t t, uint16_t e) |
| 295 | : id((p << 24) | (t << 16) | e) {} |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 296 | |
Ryan Mitchell | cd78feb | 2019-12-18 15:20:48 -0800 | [diff] [blame] | 297 | inline bool ResourceId::is_valid_static() const { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 298 | return (id & 0xff000000u) != 0 && (id & 0x00ff0000u) != 0; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 299 | } |
| 300 | |
Ryan Mitchell | cd78feb | 2019-12-18 15:20:48 -0800 | [diff] [blame] | 301 | inline bool ResourceId::is_valid() const { |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 302 | return (id & 0x00ff0000u) != 0; |
| 303 | } |
Adam Lesinski | ceb9b2f | 2017-02-16 12:05:42 -0800 | [diff] [blame] | 304 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 305 | inline uint8_t ResourceId::package_id() const { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 306 | return static_cast<uint8_t>(id >> 24); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 307 | } |
| 308 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 309 | inline uint8_t ResourceId::type_id() const { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 310 | return static_cast<uint8_t>(id >> 16); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 311 | } |
| 312 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 313 | inline uint16_t ResourceId::entry_id() const { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 314 | return static_cast<uint16_t>(id); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 315 | } |
| 316 | |
Adam Lesinski | 74605cd | 2016-03-03 15:39:50 -0800 | [diff] [blame] | 317 | inline bool operator<(const ResourceId& lhs, const ResourceId& rhs) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 318 | return lhs.id < rhs.id; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 319 | } |
| 320 | |
Adam Lesinski | 74605cd | 2016-03-03 15:39:50 -0800 | [diff] [blame] | 321 | inline bool operator>(const ResourceId& lhs, const ResourceId& rhs) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 322 | return lhs.id > rhs.id; |
Adam Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 323 | } |
| 324 | |
Adam Lesinski | 74605cd | 2016-03-03 15:39:50 -0800 | [diff] [blame] | 325 | inline bool operator==(const ResourceId& lhs, const ResourceId& rhs) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 326 | return lhs.id == rhs.id; |
Adam Lesinski | 74605cd | 2016-03-03 15:39:50 -0800 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | inline bool operator!=(const ResourceId& lhs, const ResourceId& rhs) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 330 | return lhs.id != rhs.id; |
Adam Lesinski | 74605cd | 2016-03-03 15:39:50 -0800 | [diff] [blame] | 331 | } |
| 332 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 333 | inline ::std::ostream& operator<<(::std::ostream& out, const ResourceId& res_id) { |
| 334 | return out << res_id.to_string(); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 335 | } |
| 336 | |
Adam Lesinski | a693c4a | 2017-11-09 11:29:39 -0800 | [diff] [blame] | 337 | // For generic code to call 'using std::to_string; to_string(T);'. |
| 338 | inline std::string to_string(const ResourceId& id) { |
| 339 | return id.to_string(); |
| 340 | } |
| 341 | |
Clark DuVall | 8f51d6b | 2020-04-22 13:19:28 -0700 | [diff] [blame] | 342 | // Helper to compare resource IDs, moving dynamic IDs after framework IDs. |
| 343 | inline bool cmp_ids_dynamic_after_framework(const ResourceId& a, const ResourceId& b) { |
| 344 | // If one of a and b is from the framework package (package ID 0x01), and the |
| 345 | // other is a dynamic ID (package ID 0x00), then put the dynamic ID after the |
| 346 | // framework ID. This ensures that when AssetManager resolves the dynamic IDs, |
| 347 | // they will be in sorted order as expected by AssetManager. |
| 348 | if ((a.package_id() == kFrameworkPackageId && b.package_id() == 0x00) || |
| 349 | (a.package_id() == 0x00 && b.package_id() == kFrameworkPackageId)) { |
| 350 | return b < a; |
| 351 | } |
| 352 | return a < b; |
| 353 | } |
| 354 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 355 | // |
| 356 | // ResourceType implementation. |
| 357 | // |
| 358 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 359 | inline ::std::ostream& operator<<(::std::ostream& out, const ResourceType& val) { |
| 360 | return out << to_string(val); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | // |
Iurii Makhno | dfbac39 | 2022-02-15 20:02:52 +0000 | [diff] [blame] | 364 | // ResourceNamedType implementation. |
| 365 | // |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 366 | inline ResourceNamedType::ResourceNamedType(android::StringPiece n, ResourceType t) |
| 367 | : name(n), type(t) { |
Iurii Makhno | dfbac39 | 2022-02-15 20:02:52 +0000 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | inline int ResourceNamedType::compare(const ResourceNamedType& other) const { |
| 371 | int cmp = static_cast<int>(type) - static_cast<int>(other.type); |
| 372 | if (cmp != 0) return cmp; |
| 373 | cmp = name.compare(other.name); |
| 374 | return cmp; |
| 375 | } |
| 376 | |
| 377 | inline const std::string& ResourceNamedType::to_string() const { |
| 378 | return name; |
| 379 | } |
| 380 | |
| 381 | inline bool operator<(const ResourceNamedType& lhs, const ResourceNamedType& rhs) { |
| 382 | return lhs.compare(rhs) < 0; |
| 383 | } |
| 384 | |
| 385 | inline bool operator==(const ResourceNamedType& lhs, const ResourceNamedType& rhs) { |
| 386 | return lhs.compare(rhs) == 0; |
| 387 | } |
| 388 | |
| 389 | inline bool operator!=(const ResourceNamedType& lhs, const ResourceNamedType& rhs) { |
| 390 | return lhs.compare(rhs) != 0; |
| 391 | } |
| 392 | |
| 393 | inline ::std::ostream& operator<<(::std::ostream& out, const ResourceNamedType& val) { |
| 394 | return out << val.to_string(); |
| 395 | } |
| 396 | |
| 397 | // |
| 398 | // ResourceNamedTypeRef implementation. |
| 399 | // |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 400 | inline ResourceNamedTypeRef::ResourceNamedTypeRef(android::StringPiece n, ResourceType t) |
Iurii Makhno | dfbac39 | 2022-02-15 20:02:52 +0000 | [diff] [blame] | 401 | : name(n), type(t) { |
| 402 | } |
| 403 | |
| 404 | inline ResourceNamedTypeRef::ResourceNamedTypeRef(const ResourceNamedType& rhs) |
| 405 | : name(rhs.name), type(rhs.type) { |
| 406 | } |
| 407 | |
| 408 | inline ResourceNamedTypeRef& ResourceNamedTypeRef::operator=(const ResourceNamedType& rhs) { |
| 409 | name = rhs.name; |
| 410 | type = rhs.type; |
| 411 | return *this; |
| 412 | } |
| 413 | |
| 414 | inline ResourceNamedType ResourceNamedTypeRef::ToResourceNamedType() const { |
| 415 | return ResourceNamedType(name, type); |
| 416 | } |
| 417 | |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 418 | inline std::string_view ResourceNamedTypeRef::to_string() const { |
| 419 | return name; |
Iurii Makhno | dfbac39 | 2022-02-15 20:02:52 +0000 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | inline bool operator<(const ResourceNamedTypeRef& lhs, const ResourceNamedTypeRef& rhs) { |
| 423 | return std::tie(lhs.type, lhs.name) < std::tie(rhs.type, rhs.name); |
| 424 | } |
| 425 | |
| 426 | inline bool operator==(const ResourceNamedTypeRef& lhs, const ResourceNamedTypeRef& rhs) { |
| 427 | return std::tie(lhs.type, lhs.name) == std::tie(rhs.type, rhs.name); |
| 428 | } |
| 429 | |
| 430 | inline bool operator!=(const ResourceNamedTypeRef& lhs, const ResourceNamedTypeRef& rhs) { |
| 431 | return std::tie(lhs.type, lhs.name) != std::tie(rhs.type, rhs.name); |
| 432 | } |
| 433 | |
| 434 | inline ::std::ostream& operator<<(::std::ostream& out, const ResourceNamedTypeRef& val) { |
| 435 | return out << val.name; |
| 436 | } |
| 437 | |
| 438 | // |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 439 | // ResourceName implementation. |
| 440 | // |
| 441 | |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 442 | inline ResourceName::ResourceName(android::StringPiece p, const ResourceNamedTypeRef& t, |
| 443 | android::StringPiece e) |
| 444 | : package(p), type(t.ToResourceNamedType()), entry(e) { |
Iurii Makhno | cff10ce | 2022-02-15 19:33:50 +0000 | [diff] [blame] | 445 | } |
| 446 | |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 447 | inline ResourceName::ResourceName(android::StringPiece p, ResourceType t, android::StringPiece e) |
Iurii Makhno | cff10ce | 2022-02-15 19:33:50 +0000 | [diff] [blame] | 448 | : ResourceName(p, ResourceNamedTypeWithDefaultName(t), e) { |
| 449 | } |
Adam Lesinski | 9ba47d8 | 2015-10-13 11:37:10 -0700 | [diff] [blame] | 450 | |
Adam Lesinski | 8197cc46 | 2016-08-19 12:16:49 -0700 | [diff] [blame] | 451 | inline int ResourceName::compare(const ResourceName& other) const { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 452 | int cmp = package.compare(other.package); |
| 453 | if (cmp != 0) return cmp; |
Iurii Makhno | cff10ce | 2022-02-15 19:33:50 +0000 | [diff] [blame] | 454 | cmp = type.compare(other.type); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 455 | if (cmp != 0) return cmp; |
| 456 | cmp = entry.compare(other.entry); |
| 457 | return cmp; |
Adam Lesinski | 8197cc46 | 2016-08-19 12:16:49 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 460 | inline bool ResourceName::is_valid() const { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 461 | return !package.empty() && !entry.empty(); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 462 | } |
| 463 | |
Adam Lesinski | 74605cd | 2016-03-03 15:39:50 -0800 | [diff] [blame] | 464 | inline bool operator<(const ResourceName& lhs, const ResourceName& rhs) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 465 | return std::tie(lhs.package, lhs.type, lhs.entry) < |
| 466 | std::tie(rhs.package, rhs.type, rhs.entry); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 467 | } |
| 468 | |
Adam Lesinski | 74605cd | 2016-03-03 15:39:50 -0800 | [diff] [blame] | 469 | inline bool operator==(const ResourceName& lhs, const ResourceName& rhs) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 470 | return std::tie(lhs.package, lhs.type, lhs.entry) == |
| 471 | std::tie(rhs.package, rhs.type, rhs.entry); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 472 | } |
| 473 | |
Adam Lesinski | 74605cd | 2016-03-03 15:39:50 -0800 | [diff] [blame] | 474 | inline bool operator!=(const ResourceName& lhs, const ResourceName& rhs) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 475 | return std::tie(lhs.package, lhs.type, lhs.entry) != |
| 476 | std::tie(rhs.package, rhs.type, rhs.entry); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 477 | } |
| 478 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 479 | inline ::std::ostream& operator<<(::std::ostream& out, const ResourceName& name) { |
| 480 | return out << name.to_string(); |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 481 | } |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 482 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 483 | // |
| 484 | // ResourceNameRef implementation. |
| 485 | // |
| 486 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 487 | inline ResourceNameRef::ResourceNameRef(const ResourceName& rhs) |
| 488 | : package(rhs.package), type(rhs.type), entry(rhs.entry) {} |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 489 | |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 490 | inline ResourceNameRef::ResourceNameRef(android::StringPiece p, const ResourceNamedTypeRef& t, |
| 491 | android::StringPiece e) |
Iurii Makhno | cff10ce | 2022-02-15 19:33:50 +0000 | [diff] [blame] | 492 | : package(p), type(t), entry(e) { |
| 493 | } |
| 494 | |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 495 | inline ResourceNameRef::ResourceNameRef(android::StringPiece p, ResourceType t, |
| 496 | android::StringPiece e) |
Iurii Makhno | cff10ce | 2022-02-15 19:33:50 +0000 | [diff] [blame] | 497 | : ResourceNameRef(p, ResourceNamedTypeWithDefaultName(t), e) { |
| 498 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 499 | |
| 500 | inline ResourceNameRef& ResourceNameRef::operator=(const ResourceName& rhs) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 501 | package = rhs.package; |
| 502 | type = rhs.type; |
| 503 | entry = rhs.entry; |
| 504 | return *this; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 505 | } |
| 506 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 507 | inline ResourceName ResourceNameRef::ToResourceName() const { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 508 | return ResourceName(package, type, entry); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 509 | } |
| 510 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 511 | inline bool ResourceNameRef::is_valid() const { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 512 | return !package.empty() && !entry.empty(); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 513 | } |
| 514 | |
Adam Lesinski | 74605cd | 2016-03-03 15:39:50 -0800 | [diff] [blame] | 515 | inline bool operator<(const ResourceNameRef& lhs, const ResourceNameRef& rhs) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 516 | return std::tie(lhs.package, lhs.type, lhs.entry) < |
| 517 | std::tie(rhs.package, rhs.type, rhs.entry); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 518 | } |
| 519 | |
Adam Lesinski | 74605cd | 2016-03-03 15:39:50 -0800 | [diff] [blame] | 520 | inline bool operator==(const ResourceNameRef& lhs, const ResourceNameRef& rhs) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 521 | return std::tie(lhs.package, lhs.type, lhs.entry) == |
| 522 | std::tie(rhs.package, rhs.type, rhs.entry); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 523 | } |
| 524 | |
Adam Lesinski | 74605cd | 2016-03-03 15:39:50 -0800 | [diff] [blame] | 525 | inline bool operator!=(const ResourceNameRef& lhs, const ResourceNameRef& rhs) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 526 | return std::tie(lhs.package, lhs.type, lhs.entry) != |
| 527 | std::tie(rhs.package, rhs.type, rhs.entry); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 528 | } |
| 529 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 530 | inline ::std::ostream& operator<<(::std::ostream& out, const ResourceNameRef& name) { |
| 531 | return out << name.to_string(); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 532 | } |
| 533 | |
Adam Lesinski | 74605cd | 2016-03-03 15:39:50 -0800 | [diff] [blame] | 534 | inline bool operator<(const ResourceName& lhs, const ResourceNameRef& b) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 535 | return ResourceNameRef(lhs) < b; |
Adam Lesinski | 74605cd | 2016-03-03 15:39:50 -0800 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | inline bool operator!=(const ResourceName& lhs, const ResourceNameRef& rhs) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 539 | return ResourceNameRef(lhs) != rhs; |
Adam Lesinski | 74605cd | 2016-03-03 15:39:50 -0800 | [diff] [blame] | 540 | } |
| 541 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 542 | inline bool operator==(const SourcedResourceName& lhs, const SourcedResourceName& rhs) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 543 | return lhs.name == rhs.name && lhs.line == rhs.line; |
Adam Lesinski | 74605cd | 2016-03-03 15:39:50 -0800 | [diff] [blame] | 544 | } |
| 545 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 546 | } // namespace aapt |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 547 | |
Adam Lesinski | bf0bd0f | 2016-06-01 15:31:50 -0700 | [diff] [blame] | 548 | namespace std { |
| 549 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 550 | template <> |
| 551 | struct hash<aapt::ResourceName> { |
| 552 | size_t operator()(const aapt::ResourceName& name) const { |
| 553 | android::hash_t h = 0; |
Adam Lesinski | c744ae8 | 2017-05-17 19:28:38 -0700 | [diff] [blame] | 554 | h = android::JenkinsHashMix(h, static_cast<uint32_t>(hash<string>()(name.package))); |
Iurii Makhno | cff10ce | 2022-02-15 19:33:50 +0000 | [diff] [blame] | 555 | h = android::JenkinsHashMix(h, static_cast<uint32_t>(hash<string>()(name.type.name))); |
Adam Lesinski | c744ae8 | 2017-05-17 19:28:38 -0700 | [diff] [blame] | 556 | h = android::JenkinsHashMix(h, static_cast<uint32_t>(hash<string>()(name.entry))); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 557 | return static_cast<size_t>(h); |
| 558 | } |
Adam Lesinski | bf0bd0f | 2016-06-01 15:31:50 -0700 | [diff] [blame] | 559 | }; |
| 560 | |
Adam Lesinski | c744ae8 | 2017-05-17 19:28:38 -0700 | [diff] [blame] | 561 | template <> |
| 562 | struct hash<aapt::ResourceId> { |
| 563 | size_t operator()(const aapt::ResourceId& id) const { |
| 564 | return id.id; |
| 565 | } |
| 566 | }; |
| 567 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 568 | } // namespace std |
Adam Lesinski | bf0bd0f | 2016-06-01 15:31:50 -0700 | [diff] [blame] | 569 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 570 | #endif // AAPT_RESOURCE_H |