blob: 307c21d9dc965b3856f3a05b4b29d53bcac3de96 [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_RESOURCE_H
18#define AAPT_RESOURCE_H
19
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080020#include <iomanip>
Adam Lesinskica2fc352015-04-03 12:08:26 -070021#include <limits>
Adam Lesinskid0f116b2016-07-08 15:00:32 -070022#include <sstream>
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080023#include <string>
24#include <tuple>
Adam Lesinski1ab598f2015-08-14 14:26:04 -070025#include <vector>
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080026
MÃ¥rten Kongstad24c9aa62018-06-20 08:46:41 +020027#include "androidfw/ConfigDescription.h"
Adam Lesinskid5083f62017-01-16 15:07:21 -080028#include "androidfw/StringPiece.h"
Adam Lesinskice5e56e2016-10-21 17:56:45 -070029#include "utils/JenkinsHash.h"
30
Adam Lesinskice5e56e2016-10-21 17:56:45 -070031#include "Source.h"
Adam Lesinskice5e56e2016-10-21 17:56:45 -070032
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080033namespace aapt {
34
35/**
36 * The various types of resource types available. Corresponds
37 * to the 'type' in package:type/entry.
38 */
39enum class ResourceType {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070040 kAnim,
41 kAnimator,
42 kArray,
43 kAttr,
44 kAttrPrivate,
45 kBool,
46 kColor,
Adam Lesinski86d67df2017-01-31 13:47:27 -080047
48 // Not really a type, but it shows up in some CTS tests and
49 // we need to continue respecting it.
50 kConfigVarying,
51
Adam Lesinskicacb28f2016-10-19 12:18:14 -070052 kDimen,
53 kDrawable,
Adam Lesinskic0c36632016-10-19 18:37:53 -070054 kFont,
Adam Lesinskicacb28f2016-10-19 12:18:14 -070055 kFraction,
56 kId,
57 kInteger,
58 kInterpolator,
59 kLayout,
Ryan Mitchell326e35ff2021-04-12 07:50:42 -070060 kMacro,
Adam Lesinskicacb28f2016-10-19 12:18:14 -070061 kMenu,
62 kMipmap,
Adam Lesinski3b841242017-07-25 17:15:42 -070063 kNavigation,
Adam Lesinskicacb28f2016-10-19 12:18:14 -070064 kPlurals,
65 kRaw,
66 kString,
67 kStyle,
68 kStyleable,
69 kTransition,
70 kXml,
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080071};
72
Adam Lesinski93190b72017-11-03 15:20:17 -070073android::StringPiece to_string(ResourceType type);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080074
75/**
Adam Lesinski93190b72017-11-03 15:20:17 -070076 * Returns a pointer to a valid ResourceType, or nullptr if the string was invalid.
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080077 */
Adam Lesinskid5083f62017-01-16 15:07:21 -080078const ResourceType* ParseResourceType(const android::StringPiece& str);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080079
80/**
81 * A resource's name. This can uniquely identify
82 * a resource in the ResourceTable.
83 */
84struct ResourceName {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070085 std::string package;
Adam Lesinskice5e56e2016-10-21 17:56:45 -070086 ResourceType type = ResourceType::kRaw;
Adam Lesinskicacb28f2016-10-19 12:18:14 -070087 std::string entry;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080088
Adam Lesinskice5e56e2016-10-21 17:56:45 -070089 ResourceName() = default;
Adam Lesinskid5083f62017-01-16 15:07:21 -080090 ResourceName(const android::StringPiece& p, ResourceType t, const android::StringPiece& e);
Adam Lesinski9ba47d82015-10-13 11:37:10 -070091
Adam Lesinskicacb28f2016-10-19 12:18:14 -070092 int compare(const ResourceName& other) const;
Adam Lesinski8197cc462016-08-19 12:16:49 -070093
Adam Lesinskice5e56e2016-10-21 17:56:45 -070094 bool is_valid() const;
Adam Lesinski93190b72017-11-03 15:20:17 -070095 std::string to_string() const;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080096};
97
98/**
99 * Same as ResourceName, but uses StringPieces instead.
100 * Use this if you need to avoid copying and know that
101 * the lifetime of this object is shorter than that
102 * of the original string.
103 */
104struct ResourceNameRef {
Adam Lesinskid5083f62017-01-16 15:07:21 -0800105 android::StringPiece package;
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700106 ResourceType type = ResourceType::kRaw;
Adam Lesinskid5083f62017-01-16 15:07:21 -0800107 android::StringPiece entry;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800108
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700109 ResourceNameRef() = default;
110 ResourceNameRef(const ResourceNameRef&) = default;
111 ResourceNameRef(ResourceNameRef&&) = default;
Chih-Hung Hsieh1fc78e12018-12-20 13:37:44 -0800112 ResourceNameRef(const ResourceName& rhs); // NOLINT(google-explicit-constructor)
Adam Lesinskid5083f62017-01-16 15:07:21 -0800113 ResourceNameRef(const android::StringPiece& p, ResourceType t, const android::StringPiece& e);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700114 ResourceNameRef& operator=(const ResourceNameRef& rhs) = default;
115 ResourceNameRef& operator=(ResourceNameRef&& rhs) = default;
116 ResourceNameRef& operator=(const ResourceName& rhs);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800117
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700118 bool is_valid() const;
Adam Lesinski93190b72017-11-03 15:20:17 -0700119
120 ResourceName ToResourceName() const;
121 std::string to_string() const;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800122};
123
Adam Lesinskib5dc4bd2017-02-22 19:29:29 -0800124constexpr const uint8_t kAppPackageId = 0x7fu;
125constexpr const uint8_t kFrameworkPackageId = 0x01u;
126
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800127/**
128 * A binary identifier representing a resource. Internally it
129 * is a 32bit integer split as follows:
130 *
131 * 0xPPTTEEEE
132 *
133 * PP: 8 bit package identifier. 0x01 is reserved for system
134 * and 0x7f is reserved for the running app.
135 * TT: 8 bit type identifier. 0x00 is invalid.
136 * EEEE: 16 bit entry identifier.
137 */
138struct ResourceId {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700139 uint32_t id;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800140
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700141 ResourceId();
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700142 ResourceId(const ResourceId& rhs) = default;
Chih-Hung Hsieh1fc78e12018-12-20 13:37:44 -0800143 ResourceId(uint32_t res_id); // NOLINT(google-explicit-constructor)
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700144 ResourceId(uint8_t p, uint8_t t, uint16_t e);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800145
Ryan Mitchellcd78feb2019-12-18 15:20:48 -0800146 // Returns true if the ID is a valid ID that is not dynamic (package ID cannot be 0)
147 bool is_valid_static() const;
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800148
149 // Returns true if the ID is a valid ID or dynamic ID (package ID can be 0).
Ryan Mitchellcd78feb2019-12-18 15:20:48 -0800150 bool is_valid() const;
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800151
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700152 uint8_t package_id() const;
153 uint8_t type_id() const;
154 uint16_t entry_id() const;
Adam Lesinski93190b72017-11-03 15:20:17 -0700155
156 std::string to_string() const;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800157};
158
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700159struct SourcedResourceName {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700160 ResourceName name;
161 size_t line;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700162};
163
164struct ResourceFile {
Adam Lesinski00451162017-10-03 07:44:08 -0700165 enum class Type {
166 kUnknown,
167 kPng,
168 kBinaryXml,
169 kProtoXml,
170 };
171
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700172 // Name
173 ResourceName name;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700174
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700175 // Configuration
MÃ¥rten Kongstad24c9aa62018-06-20 08:46:41 +0200176 android::ConfigDescription config;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700177
Adam Lesinski00451162017-10-03 07:44:08 -0700178 // Type
179 Type type;
180
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700181 // Source
182 Source source;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700183
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700184 // Exported symbols
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700185 std::vector<SourcedResourceName> exported_symbols;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700186};
187
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800188/**
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700189 * Useful struct used as a key to represent a unique resource in associative
190 * containers.
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800191 */
192struct ResourceKey {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700193 ResourceName name;
MÃ¥rten Kongstad24c9aa62018-06-20 08:46:41 +0200194 android::ConfigDescription config;
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800195};
196
197bool operator<(const ResourceKey& a, const ResourceKey& b);
198
199/**
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700200 * Useful struct used as a key to represent a unique resource in associative
201 * containers.
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800202 * Holds a reference to the name, so that name better live longer than this key!
203 */
204struct ResourceKeyRef {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700205 ResourceNameRef name;
MÃ¥rten Kongstad24c9aa62018-06-20 08:46:41 +0200206 android::ConfigDescription config;
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800207
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700208 ResourceKeyRef() = default;
MÃ¥rten Kongstad24c9aa62018-06-20 08:46:41 +0200209 ResourceKeyRef(const ResourceNameRef& n, const android::ConfigDescription& c)
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700210 : name(n), config(c) {}
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800211
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700212 /**
213 * Prevent taking a reference to a temporary. This is bad.
214 */
MÃ¥rten Kongstad24c9aa62018-06-20 08:46:41 +0200215 ResourceKeyRef(ResourceName&& n, const android::ConfigDescription& c) = delete;
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800216};
217
218bool operator<(const ResourceKeyRef& a, const ResourceKeyRef& b);
219
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800220//
221// ResourceId implementation.
222//
223
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700224inline ResourceId::ResourceId() : id(0) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800225
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700226inline ResourceId::ResourceId(uint32_t res_id) : id(res_id) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800227
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700228inline ResourceId::ResourceId(uint8_t p, uint8_t t, uint16_t e)
229 : id((p << 24) | (t << 16) | e) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800230
Ryan Mitchellcd78feb2019-12-18 15:20:48 -0800231inline bool ResourceId::is_valid_static() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700232 return (id & 0xff000000u) != 0 && (id & 0x00ff0000u) != 0;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800233}
234
Ryan Mitchellcd78feb2019-12-18 15:20:48 -0800235inline bool ResourceId::is_valid() const {
Adam Lesinski93190b72017-11-03 15:20:17 -0700236 return (id & 0x00ff0000u) != 0;
237}
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800238
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700239inline uint8_t ResourceId::package_id() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700240 return static_cast<uint8_t>(id >> 24);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800241}
242
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700243inline uint8_t ResourceId::type_id() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700244 return static_cast<uint8_t>(id >> 16);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800245}
246
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700247inline uint16_t ResourceId::entry_id() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700248 return static_cast<uint16_t>(id);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800249}
250
Adam Lesinski74605cd2016-03-03 15:39:50 -0800251inline bool operator<(const ResourceId& lhs, const ResourceId& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700252 return lhs.id < rhs.id;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800253}
254
Adam Lesinski74605cd2016-03-03 15:39:50 -0800255inline bool operator>(const ResourceId& lhs, const ResourceId& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700256 return lhs.id > rhs.id;
Adam Lesinski24aad162015-04-24 19:19:30 -0700257}
258
Adam Lesinski74605cd2016-03-03 15:39:50 -0800259inline bool operator==(const ResourceId& lhs, const ResourceId& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700260 return lhs.id == rhs.id;
Adam Lesinski74605cd2016-03-03 15:39:50 -0800261}
262
263inline bool operator!=(const ResourceId& lhs, const ResourceId& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700264 return lhs.id != rhs.id;
Adam Lesinski74605cd2016-03-03 15:39:50 -0800265}
266
Adam Lesinski93190b72017-11-03 15:20:17 -0700267inline ::std::ostream& operator<<(::std::ostream& out, const ResourceId& res_id) {
268 return out << res_id.to_string();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800269}
270
Adam Lesinskia693c4a2017-11-09 11:29:39 -0800271// For generic code to call 'using std::to_string; to_string(T);'.
272inline std::string to_string(const ResourceId& id) {
273 return id.to_string();
274}
275
Clark DuVall8f51d6b2020-04-22 13:19:28 -0700276// Helper to compare resource IDs, moving dynamic IDs after framework IDs.
277inline bool cmp_ids_dynamic_after_framework(const ResourceId& a, const ResourceId& b) {
278 // If one of a and b is from the framework package (package ID 0x01), and the
279 // other is a dynamic ID (package ID 0x00), then put the dynamic ID after the
280 // framework ID. This ensures that when AssetManager resolves the dynamic IDs,
281 // they will be in sorted order as expected by AssetManager.
282 if ((a.package_id() == kFrameworkPackageId && b.package_id() == 0x00) ||
283 (a.package_id() == 0x00 && b.package_id() == kFrameworkPackageId)) {
284 return b < a;
285 }
286 return a < b;
287}
288
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800289//
290// ResourceType implementation.
291//
292
Adam Lesinski93190b72017-11-03 15:20:17 -0700293inline ::std::ostream& operator<<(::std::ostream& out, const ResourceType& val) {
294 return out << to_string(val);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800295}
296
297//
298// ResourceName implementation.
299//
300
Adam Lesinskid5083f62017-01-16 15:07:21 -0800301inline ResourceName::ResourceName(const android::StringPiece& p, ResourceType t,
302 const android::StringPiece& e)
303 : package(p.to_string()), type(t), entry(e.to_string()) {}
Adam Lesinski9ba47d82015-10-13 11:37:10 -0700304
Adam Lesinski8197cc462016-08-19 12:16:49 -0700305inline int ResourceName::compare(const ResourceName& other) const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700306 int cmp = package.compare(other.package);
307 if (cmp != 0) return cmp;
308 cmp = static_cast<int>(type) - static_cast<int>(other.type);
309 if (cmp != 0) return cmp;
310 cmp = entry.compare(other.entry);
311 return cmp;
Adam Lesinski8197cc462016-08-19 12:16:49 -0700312}
313
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700314inline bool ResourceName::is_valid() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700315 return !package.empty() && !entry.empty();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800316}
317
Adam Lesinski74605cd2016-03-03 15:39:50 -0800318inline bool operator<(const ResourceName& lhs, const ResourceName& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700319 return std::tie(lhs.package, lhs.type, lhs.entry) <
320 std::tie(rhs.package, rhs.type, rhs.entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800321}
322
Adam Lesinski74605cd2016-03-03 15:39:50 -0800323inline bool operator==(const ResourceName& lhs, const ResourceName& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700324 return std::tie(lhs.package, lhs.type, lhs.entry) ==
325 std::tie(rhs.package, rhs.type, rhs.entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800326}
327
Adam Lesinski74605cd2016-03-03 15:39:50 -0800328inline bool operator!=(const ResourceName& lhs, const ResourceName& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700329 return std::tie(lhs.package, lhs.type, lhs.entry) !=
330 std::tie(rhs.package, rhs.type, rhs.entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800331}
332
Adam Lesinski93190b72017-11-03 15:20:17 -0700333inline ::std::ostream& operator<<(::std::ostream& out, const ResourceName& name) {
334 return out << name.to_string();
Adam Lesinskid0f116b2016-07-08 15:00:32 -0700335}
Adam Lesinski769de982015-04-10 19:43:55 -0700336
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800337//
338// ResourceNameRef implementation.
339//
340
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700341inline ResourceNameRef::ResourceNameRef(const ResourceName& rhs)
342 : package(rhs.package), type(rhs.type), entry(rhs.entry) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800343
Adam Lesinskid5083f62017-01-16 15:07:21 -0800344inline ResourceNameRef::ResourceNameRef(const android::StringPiece& p, ResourceType t,
345 const android::StringPiece& e)
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700346 : package(p), type(t), entry(e) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800347
348inline ResourceNameRef& ResourceNameRef::operator=(const ResourceName& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700349 package = rhs.package;
350 type = rhs.type;
351 entry = rhs.entry;
352 return *this;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800353}
354
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700355inline ResourceName ResourceNameRef::ToResourceName() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700356 return ResourceName(package, type, entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800357}
358
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700359inline bool ResourceNameRef::is_valid() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700360 return !package.empty() && !entry.empty();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800361}
362
Adam Lesinski74605cd2016-03-03 15:39:50 -0800363inline bool operator<(const ResourceNameRef& lhs, const ResourceNameRef& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700364 return std::tie(lhs.package, lhs.type, lhs.entry) <
365 std::tie(rhs.package, rhs.type, rhs.entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800366}
367
Adam Lesinski74605cd2016-03-03 15:39:50 -0800368inline bool operator==(const ResourceNameRef& lhs, const ResourceNameRef& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700369 return std::tie(lhs.package, lhs.type, lhs.entry) ==
370 std::tie(rhs.package, rhs.type, rhs.entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800371}
372
Adam Lesinski74605cd2016-03-03 15:39:50 -0800373inline bool operator!=(const ResourceNameRef& lhs, const ResourceNameRef& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700374 return std::tie(lhs.package, lhs.type, lhs.entry) !=
375 std::tie(rhs.package, rhs.type, rhs.entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800376}
377
Adam Lesinski93190b72017-11-03 15:20:17 -0700378inline ::std::ostream& operator<<(::std::ostream& out, const ResourceNameRef& name) {
379 return out << name.to_string();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800380}
381
Adam Lesinski74605cd2016-03-03 15:39:50 -0800382inline bool operator<(const ResourceName& lhs, const ResourceNameRef& b) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700383 return ResourceNameRef(lhs) < b;
Adam Lesinski74605cd2016-03-03 15:39:50 -0800384}
385
386inline bool operator!=(const ResourceName& lhs, const ResourceNameRef& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700387 return ResourceNameRef(lhs) != rhs;
Adam Lesinski74605cd2016-03-03 15:39:50 -0800388}
389
Adam Lesinski93190b72017-11-03 15:20:17 -0700390inline bool operator==(const SourcedResourceName& lhs, const SourcedResourceName& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700391 return lhs.name == rhs.name && lhs.line == rhs.line;
Adam Lesinski74605cd2016-03-03 15:39:50 -0800392}
393
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700394} // namespace aapt
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800395
Adam Lesinskibf0bd0f2016-06-01 15:31:50 -0700396namespace std {
397
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700398template <>
399struct hash<aapt::ResourceName> {
400 size_t operator()(const aapt::ResourceName& name) const {
401 android::hash_t h = 0;
Adam Lesinskic744ae82017-05-17 19:28:38 -0700402 h = android::JenkinsHashMix(h, static_cast<uint32_t>(hash<string>()(name.package)));
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700403 h = android::JenkinsHashMix(h, static_cast<uint32_t>(name.type));
Adam Lesinskic744ae82017-05-17 19:28:38 -0700404 h = android::JenkinsHashMix(h, static_cast<uint32_t>(hash<string>()(name.entry)));
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700405 return static_cast<size_t>(h);
406 }
Adam Lesinskibf0bd0f2016-06-01 15:31:50 -0700407};
408
Adam Lesinskic744ae82017-05-17 19:28:38 -0700409template <>
410struct hash<aapt::ResourceId> {
411 size_t operator()(const aapt::ResourceId& id) const {
412 return id.id;
413 }
414};
415
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700416} // namespace std
Adam Lesinskibf0bd0f2016-06-01 15:31:50 -0700417
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700418#endif // AAPT_RESOURCE_H