blob: 8fe0eb3b51bfd96cfecf1f9a0d2c5f795c982881 [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,
60 kMenu,
61 kMipmap,
Adam Lesinski3b841242017-07-25 17:15:42 -070062 kNavigation,
Adam Lesinskicacb28f2016-10-19 12:18:14 -070063 kPlurals,
64 kRaw,
65 kString,
66 kStyle,
67 kStyleable,
68 kTransition,
69 kXml,
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080070};
71
Adam Lesinski93190b72017-11-03 15:20:17 -070072android::StringPiece to_string(ResourceType type);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080073
74/**
Adam Lesinski93190b72017-11-03 15:20:17 -070075 * Returns a pointer to a valid ResourceType, or nullptr if the string was invalid.
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080076 */
Adam Lesinskid5083f62017-01-16 15:07:21 -080077const ResourceType* ParseResourceType(const android::StringPiece& str);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080078
79/**
80 * A resource's name. This can uniquely identify
81 * a resource in the ResourceTable.
82 */
83struct ResourceName {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070084 std::string package;
Adam Lesinskice5e56e2016-10-21 17:56:45 -070085 ResourceType type = ResourceType::kRaw;
Adam Lesinskicacb28f2016-10-19 12:18:14 -070086 std::string entry;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080087
Adam Lesinskice5e56e2016-10-21 17:56:45 -070088 ResourceName() = default;
Adam Lesinskid5083f62017-01-16 15:07:21 -080089 ResourceName(const android::StringPiece& p, ResourceType t, const android::StringPiece& e);
Adam Lesinski9ba47d82015-10-13 11:37:10 -070090
Adam Lesinskicacb28f2016-10-19 12:18:14 -070091 int compare(const ResourceName& other) const;
Adam Lesinski8197cc462016-08-19 12:16:49 -070092
Adam Lesinskice5e56e2016-10-21 17:56:45 -070093 bool is_valid() const;
Adam Lesinski93190b72017-11-03 15:20:17 -070094 std::string to_string() const;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080095};
96
97/**
98 * Same as ResourceName, but uses StringPieces instead.
99 * Use this if you need to avoid copying and know that
100 * the lifetime of this object is shorter than that
101 * of the original string.
102 */
103struct ResourceNameRef {
Adam Lesinskid5083f62017-01-16 15:07:21 -0800104 android::StringPiece package;
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700105 ResourceType type = ResourceType::kRaw;
Adam Lesinskid5083f62017-01-16 15:07:21 -0800106 android::StringPiece entry;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800107
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700108 ResourceNameRef() = default;
109 ResourceNameRef(const ResourceNameRef&) = default;
110 ResourceNameRef(ResourceNameRef&&) = default;
Chih-Hung Hsieh1fc78e12018-12-20 13:37:44 -0800111 ResourceNameRef(const ResourceName& rhs); // NOLINT(google-explicit-constructor)
Adam Lesinskid5083f62017-01-16 15:07:21 -0800112 ResourceNameRef(const android::StringPiece& p, ResourceType t, const android::StringPiece& e);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700113 ResourceNameRef& operator=(const ResourceNameRef& rhs) = default;
114 ResourceNameRef& operator=(ResourceNameRef&& rhs) = default;
115 ResourceNameRef& operator=(const ResourceName& rhs);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800116
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700117 bool is_valid() const;
Adam Lesinski93190b72017-11-03 15:20:17 -0700118
119 ResourceName ToResourceName() const;
120 std::string to_string() const;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800121};
122
Adam Lesinskib5dc4bd2017-02-22 19:29:29 -0800123constexpr const uint8_t kAppPackageId = 0x7fu;
124constexpr const uint8_t kFrameworkPackageId = 0x01u;
125
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800126/**
127 * A binary identifier representing a resource. Internally it
128 * is a 32bit integer split as follows:
129 *
130 * 0xPPTTEEEE
131 *
132 * PP: 8 bit package identifier. 0x01 is reserved for system
133 * and 0x7f is reserved for the running app.
134 * TT: 8 bit type identifier. 0x00 is invalid.
135 * EEEE: 16 bit entry identifier.
136 */
137struct ResourceId {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700138 uint32_t id;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800139
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700140 ResourceId();
141 ResourceId(const ResourceId& rhs);
Chih-Hung Hsieh1fc78e12018-12-20 13:37:44 -0800142 ResourceId(uint32_t res_id); // NOLINT(google-explicit-constructor)
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700143 ResourceId(uint8_t p, uint8_t t, uint16_t e);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800144
Ryan Mitchellcd78feb2019-12-18 15:20:48 -0800145 // Returns true if the ID is a valid ID that is not dynamic (package ID cannot be 0)
146 bool is_valid_static() const;
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800147
148 // Returns true if the ID is a valid ID or dynamic ID (package ID can be 0).
Ryan Mitchellcd78feb2019-12-18 15:20:48 -0800149 bool is_valid() const;
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800150
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700151 uint8_t package_id() const;
152 uint8_t type_id() const;
153 uint16_t entry_id() const;
Adam Lesinski93190b72017-11-03 15:20:17 -0700154
155 std::string to_string() const;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800156};
157
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700158struct SourcedResourceName {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700159 ResourceName name;
160 size_t line;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700161};
162
163struct ResourceFile {
Adam Lesinski00451162017-10-03 07:44:08 -0700164 enum class Type {
165 kUnknown,
166 kPng,
167 kBinaryXml,
168 kProtoXml,
169 };
170
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700171 // Name
172 ResourceName name;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700173
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700174 // Configuration
MÃ¥rten Kongstad24c9aa62018-06-20 08:46:41 +0200175 android::ConfigDescription config;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700176
Adam Lesinski00451162017-10-03 07:44:08 -0700177 // Type
178 Type type;
179
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700180 // Source
181 Source source;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700182
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700183 // Exported symbols
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700184 std::vector<SourcedResourceName> exported_symbols;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700185};
186
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800187/**
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700188 * Useful struct used as a key to represent a unique resource in associative
189 * containers.
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800190 */
191struct ResourceKey {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700192 ResourceName name;
MÃ¥rten Kongstad24c9aa62018-06-20 08:46:41 +0200193 android::ConfigDescription config;
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800194};
195
196bool operator<(const ResourceKey& a, const ResourceKey& b);
197
198/**
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700199 * Useful struct used as a key to represent a unique resource in associative
200 * containers.
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800201 * Holds a reference to the name, so that name better live longer than this key!
202 */
203struct ResourceKeyRef {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700204 ResourceNameRef name;
MÃ¥rten Kongstad24c9aa62018-06-20 08:46:41 +0200205 android::ConfigDescription config;
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800206
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700207 ResourceKeyRef() = default;
MÃ¥rten Kongstad24c9aa62018-06-20 08:46:41 +0200208 ResourceKeyRef(const ResourceNameRef& n, const android::ConfigDescription& c)
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700209 : name(n), config(c) {}
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800210
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700211 /**
212 * Prevent taking a reference to a temporary. This is bad.
213 */
MÃ¥rten Kongstad24c9aa62018-06-20 08:46:41 +0200214 ResourceKeyRef(ResourceName&& n, const android::ConfigDescription& c) = delete;
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800215};
216
217bool operator<(const ResourceKeyRef& a, const ResourceKeyRef& b);
218
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800219//
220// ResourceId implementation.
221//
222
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700223inline ResourceId::ResourceId() : id(0) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800224
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700225inline ResourceId::ResourceId(const ResourceId& rhs) : id(rhs.id) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800226
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700227inline ResourceId::ResourceId(uint32_t res_id) : id(res_id) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800228
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700229inline ResourceId::ResourceId(uint8_t p, uint8_t t, uint16_t e)
230 : id((p << 24) | (t << 16) | e) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800231
Ryan Mitchellcd78feb2019-12-18 15:20:48 -0800232inline bool ResourceId::is_valid_static() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700233 return (id & 0xff000000u) != 0 && (id & 0x00ff0000u) != 0;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800234}
235
Ryan Mitchellcd78feb2019-12-18 15:20:48 -0800236inline bool ResourceId::is_valid() const {
Adam Lesinski93190b72017-11-03 15:20:17 -0700237 return (id & 0x00ff0000u) != 0;
238}
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800239
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700240inline uint8_t ResourceId::package_id() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700241 return static_cast<uint8_t>(id >> 24);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800242}
243
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700244inline uint8_t ResourceId::type_id() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700245 return static_cast<uint8_t>(id >> 16);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800246}
247
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700248inline uint16_t ResourceId::entry_id() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700249 return static_cast<uint16_t>(id);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800250}
251
Adam Lesinski74605cd2016-03-03 15:39:50 -0800252inline bool operator<(const ResourceId& lhs, const ResourceId& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700253 return lhs.id < rhs.id;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800254}
255
Adam Lesinski74605cd2016-03-03 15:39:50 -0800256inline bool operator>(const ResourceId& lhs, const ResourceId& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700257 return lhs.id > rhs.id;
Adam Lesinski24aad162015-04-24 19:19:30 -0700258}
259
Adam Lesinski74605cd2016-03-03 15:39:50 -0800260inline bool operator==(const ResourceId& lhs, const ResourceId& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700261 return lhs.id == rhs.id;
Adam Lesinski74605cd2016-03-03 15:39:50 -0800262}
263
264inline bool operator!=(const ResourceId& lhs, const ResourceId& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700265 return lhs.id != rhs.id;
Adam Lesinski74605cd2016-03-03 15:39:50 -0800266}
267
Adam Lesinski93190b72017-11-03 15:20:17 -0700268inline ::std::ostream& operator<<(::std::ostream& out, const ResourceId& res_id) {
269 return out << res_id.to_string();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800270}
271
Adam Lesinskia693c4a2017-11-09 11:29:39 -0800272// For generic code to call 'using std::to_string; to_string(T);'.
273inline std::string to_string(const ResourceId& id) {
274 return id.to_string();
275}
276
Clark DuVall8f51d6b2020-04-22 13:19:28 -0700277// Helper to compare resource IDs, moving dynamic IDs after framework IDs.
278inline bool cmp_ids_dynamic_after_framework(const ResourceId& a, const ResourceId& b) {
279 // If one of a and b is from the framework package (package ID 0x01), and the
280 // other is a dynamic ID (package ID 0x00), then put the dynamic ID after the
281 // framework ID. This ensures that when AssetManager resolves the dynamic IDs,
282 // they will be in sorted order as expected by AssetManager.
283 if ((a.package_id() == kFrameworkPackageId && b.package_id() == 0x00) ||
284 (a.package_id() == 0x00 && b.package_id() == kFrameworkPackageId)) {
285 return b < a;
286 }
287 return a < b;
288}
289
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800290//
291// ResourceType implementation.
292//
293
Adam Lesinski93190b72017-11-03 15:20:17 -0700294inline ::std::ostream& operator<<(::std::ostream& out, const ResourceType& val) {
295 return out << to_string(val);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800296}
297
298//
299// ResourceName implementation.
300//
301
Adam Lesinskid5083f62017-01-16 15:07:21 -0800302inline ResourceName::ResourceName(const android::StringPiece& p, ResourceType t,
303 const android::StringPiece& e)
304 : package(p.to_string()), type(t), entry(e.to_string()) {}
Adam Lesinski9ba47d82015-10-13 11:37:10 -0700305
Adam Lesinski8197cc462016-08-19 12:16:49 -0700306inline int ResourceName::compare(const ResourceName& other) const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700307 int cmp = package.compare(other.package);
308 if (cmp != 0) return cmp;
309 cmp = static_cast<int>(type) - static_cast<int>(other.type);
310 if (cmp != 0) return cmp;
311 cmp = entry.compare(other.entry);
312 return cmp;
Adam Lesinski8197cc462016-08-19 12:16:49 -0700313}
314
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700315inline bool ResourceName::is_valid() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700316 return !package.empty() && !entry.empty();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800317}
318
Adam Lesinski74605cd2016-03-03 15:39:50 -0800319inline bool operator<(const ResourceName& lhs, const ResourceName& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700320 return std::tie(lhs.package, lhs.type, lhs.entry) <
321 std::tie(rhs.package, rhs.type, rhs.entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800322}
323
Adam Lesinski74605cd2016-03-03 15:39:50 -0800324inline bool operator==(const ResourceName& lhs, const ResourceName& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700325 return std::tie(lhs.package, lhs.type, lhs.entry) ==
326 std::tie(rhs.package, rhs.type, rhs.entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800327}
328
Adam Lesinski74605cd2016-03-03 15:39:50 -0800329inline bool operator!=(const ResourceName& lhs, const ResourceName& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700330 return std::tie(lhs.package, lhs.type, lhs.entry) !=
331 std::tie(rhs.package, rhs.type, rhs.entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800332}
333
Adam Lesinski93190b72017-11-03 15:20:17 -0700334inline ::std::ostream& operator<<(::std::ostream& out, const ResourceName& name) {
335 return out << name.to_string();
Adam Lesinskid0f116b2016-07-08 15:00:32 -0700336}
Adam Lesinski769de982015-04-10 19:43:55 -0700337
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800338//
339// ResourceNameRef implementation.
340//
341
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700342inline ResourceNameRef::ResourceNameRef(const ResourceName& rhs)
343 : package(rhs.package), type(rhs.type), entry(rhs.entry) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800344
Adam Lesinskid5083f62017-01-16 15:07:21 -0800345inline ResourceNameRef::ResourceNameRef(const android::StringPiece& p, ResourceType t,
346 const android::StringPiece& e)
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700347 : package(p), type(t), entry(e) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800348
349inline ResourceNameRef& ResourceNameRef::operator=(const ResourceName& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700350 package = rhs.package;
351 type = rhs.type;
352 entry = rhs.entry;
353 return *this;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800354}
355
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700356inline ResourceName ResourceNameRef::ToResourceName() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700357 return ResourceName(package, type, entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800358}
359
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700360inline bool ResourceNameRef::is_valid() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700361 return !package.empty() && !entry.empty();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800362}
363
Adam Lesinski74605cd2016-03-03 15:39:50 -0800364inline bool operator<(const ResourceNameRef& lhs, const ResourceNameRef& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700365 return std::tie(lhs.package, lhs.type, lhs.entry) <
366 std::tie(rhs.package, rhs.type, rhs.entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800367}
368
Adam Lesinski74605cd2016-03-03 15:39:50 -0800369inline bool operator==(const ResourceNameRef& lhs, const ResourceNameRef& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700370 return std::tie(lhs.package, lhs.type, lhs.entry) ==
371 std::tie(rhs.package, rhs.type, rhs.entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800372}
373
Adam Lesinski74605cd2016-03-03 15:39:50 -0800374inline bool operator!=(const ResourceNameRef& lhs, const ResourceNameRef& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700375 return std::tie(lhs.package, lhs.type, lhs.entry) !=
376 std::tie(rhs.package, rhs.type, rhs.entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800377}
378
Adam Lesinski93190b72017-11-03 15:20:17 -0700379inline ::std::ostream& operator<<(::std::ostream& out, const ResourceNameRef& name) {
380 return out << name.to_string();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800381}
382
Adam Lesinski74605cd2016-03-03 15:39:50 -0800383inline bool operator<(const ResourceName& lhs, const ResourceNameRef& b) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700384 return ResourceNameRef(lhs) < b;
Adam Lesinski74605cd2016-03-03 15:39:50 -0800385}
386
387inline bool operator!=(const ResourceName& lhs, const ResourceNameRef& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700388 return ResourceNameRef(lhs) != rhs;
Adam Lesinski74605cd2016-03-03 15:39:50 -0800389}
390
Adam Lesinski93190b72017-11-03 15:20:17 -0700391inline bool operator==(const SourcedResourceName& lhs, const SourcedResourceName& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700392 return lhs.name == rhs.name && lhs.line == rhs.line;
Adam Lesinski74605cd2016-03-03 15:39:50 -0800393}
394
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700395} // namespace aapt
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800396
Adam Lesinskibf0bd0f2016-06-01 15:31:50 -0700397namespace std {
398
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700399template <>
400struct hash<aapt::ResourceName> {
401 size_t operator()(const aapt::ResourceName& name) const {
402 android::hash_t h = 0;
Adam Lesinskic744ae82017-05-17 19:28:38 -0700403 h = android::JenkinsHashMix(h, static_cast<uint32_t>(hash<string>()(name.package)));
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700404 h = android::JenkinsHashMix(h, static_cast<uint32_t>(name.type));
Adam Lesinskic744ae82017-05-17 19:28:38 -0700405 h = android::JenkinsHashMix(h, static_cast<uint32_t>(hash<string>()(name.entry)));
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700406 return static_cast<size_t>(h);
407 }
Adam Lesinskibf0bd0f2016-06-01 15:31:50 -0700408};
409
Adam Lesinskic744ae82017-05-17 19:28:38 -0700410template <>
411struct hash<aapt::ResourceId> {
412 size_t operator()(const aapt::ResourceId& id) const {
413 return id.id;
414 }
415};
416
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700417} // namespace std
Adam Lesinskibf0bd0f2016-06-01 15:31:50 -0700418
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700419#endif // AAPT_RESOURCE_H