blob: 67ba895e51d17d9749ebd20f6957567aff61a4fa [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,
Ryan Mitchell83a37ad2018-08-06 16:32:24 -070069
70 // Not a parsed type. It is only used when loading resource tables that may have modified type
71 // names
72 kUnknown,
73
Adam Lesinskicacb28f2016-10-19 12:18:14 -070074 kXml,
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080075};
76
Adam Lesinski93190b72017-11-03 15:20:17 -070077android::StringPiece to_string(ResourceType type);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080078
79/**
Adam Lesinski93190b72017-11-03 15:20:17 -070080 * Returns a pointer to a valid ResourceType, or nullptr if the string was invalid.
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080081 */
Adam Lesinskid5083f62017-01-16 15:07:21 -080082const ResourceType* ParseResourceType(const android::StringPiece& str);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080083
84/**
85 * A resource's name. This can uniquely identify
86 * a resource in the ResourceTable.
87 */
88struct ResourceName {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070089 std::string package;
Adam Lesinskice5e56e2016-10-21 17:56:45 -070090 ResourceType type = ResourceType::kRaw;
Adam Lesinskicacb28f2016-10-19 12:18:14 -070091 std::string entry;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080092
Adam Lesinskice5e56e2016-10-21 17:56:45 -070093 ResourceName() = default;
Adam Lesinskid5083f62017-01-16 15:07:21 -080094 ResourceName(const android::StringPiece& p, ResourceType t, const android::StringPiece& e);
Adam Lesinski9ba47d82015-10-13 11:37:10 -070095
Adam Lesinskicacb28f2016-10-19 12:18:14 -070096 int compare(const ResourceName& other) const;
Adam Lesinski8197cc462016-08-19 12:16:49 -070097
Adam Lesinskice5e56e2016-10-21 17:56:45 -070098 bool is_valid() const;
Adam Lesinski93190b72017-11-03 15:20:17 -070099 std::string to_string() const;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800100};
101
102/**
103 * Same as ResourceName, but uses StringPieces instead.
104 * Use this if you need to avoid copying and know that
105 * the lifetime of this object is shorter than that
106 * of the original string.
107 */
108struct ResourceNameRef {
Adam Lesinskid5083f62017-01-16 15:07:21 -0800109 android::StringPiece package;
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700110 ResourceType type = ResourceType::kRaw;
Adam Lesinskid5083f62017-01-16 15:07:21 -0800111 android::StringPiece entry;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800112
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700113 ResourceNameRef() = default;
114 ResourceNameRef(const ResourceNameRef&) = default;
115 ResourceNameRef(ResourceNameRef&&) = default;
Chih-Hung Hsieh1fc78e12018-12-20 13:37:44 -0800116 ResourceNameRef(const ResourceName& rhs); // NOLINT(google-explicit-constructor)
Adam Lesinskid5083f62017-01-16 15:07:21 -0800117 ResourceNameRef(const android::StringPiece& p, ResourceType t, const android::StringPiece& e);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700118 ResourceNameRef& operator=(const ResourceNameRef& rhs) = default;
119 ResourceNameRef& operator=(ResourceNameRef&& rhs) = default;
120 ResourceNameRef& operator=(const ResourceName& rhs);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800121
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700122 bool is_valid() const;
Adam Lesinski93190b72017-11-03 15:20:17 -0700123
124 ResourceName ToResourceName() const;
125 std::string to_string() const;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800126};
127
Adam Lesinskib5dc4bd2017-02-22 19:29:29 -0800128constexpr const uint8_t kAppPackageId = 0x7fu;
129constexpr const uint8_t kFrameworkPackageId = 0x01u;
130
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800131/**
132 * A binary identifier representing a resource. Internally it
133 * is a 32bit integer split as follows:
134 *
135 * 0xPPTTEEEE
136 *
137 * PP: 8 bit package identifier. 0x01 is reserved for system
138 * and 0x7f is reserved for the running app.
139 * TT: 8 bit type identifier. 0x00 is invalid.
140 * EEEE: 16 bit entry identifier.
141 */
142struct ResourceId {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700143 uint32_t id;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800144
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700145 ResourceId();
146 ResourceId(const ResourceId& rhs);
Chih-Hung Hsieh1fc78e12018-12-20 13:37:44 -0800147 ResourceId(uint32_t res_id); // NOLINT(google-explicit-constructor)
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700148 ResourceId(uint8_t p, uint8_t t, uint16_t e);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800149
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700150 bool is_valid() const;
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800151
152 // Returns true if the ID is a valid ID or dynamic ID (package ID can be 0).
153 bool is_valid_dynamic() const;
154
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700155 uint8_t package_id() const;
156 uint8_t type_id() const;
157 uint16_t entry_id() const;
Adam Lesinski93190b72017-11-03 15:20:17 -0700158
159 std::string to_string() const;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800160};
161
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700162struct SourcedResourceName {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700163 ResourceName name;
164 size_t line;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700165};
166
167struct ResourceFile {
Adam Lesinski00451162017-10-03 07:44:08 -0700168 enum class Type {
169 kUnknown,
170 kPng,
171 kBinaryXml,
172 kProtoXml,
173 };
174
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700175 // Name
176 ResourceName name;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700177
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700178 // Configuration
MÃ¥rten Kongstad24c9aa62018-06-20 08:46:41 +0200179 android::ConfigDescription config;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700180
Adam Lesinski00451162017-10-03 07:44:08 -0700181 // Type
182 Type type;
183
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700184 // Source
185 Source source;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700186
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700187 // Exported symbols
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700188 std::vector<SourcedResourceName> exported_symbols;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700189};
190
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800191/**
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700192 * Useful struct used as a key to represent a unique resource in associative
193 * containers.
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800194 */
195struct ResourceKey {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700196 ResourceName name;
MÃ¥rten Kongstad24c9aa62018-06-20 08:46:41 +0200197 android::ConfigDescription config;
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800198};
199
200bool operator<(const ResourceKey& a, const ResourceKey& b);
201
202/**
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700203 * Useful struct used as a key to represent a unique resource in associative
204 * containers.
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800205 * Holds a reference to the name, so that name better live longer than this key!
206 */
207struct ResourceKeyRef {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700208 ResourceNameRef name;
MÃ¥rten Kongstad24c9aa62018-06-20 08:46:41 +0200209 android::ConfigDescription config;
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800210
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700211 ResourceKeyRef() = default;
MÃ¥rten Kongstad24c9aa62018-06-20 08:46:41 +0200212 ResourceKeyRef(const ResourceNameRef& n, const android::ConfigDescription& c)
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700213 : name(n), config(c) {}
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800214
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700215 /**
216 * Prevent taking a reference to a temporary. This is bad.
217 */
MÃ¥rten Kongstad24c9aa62018-06-20 08:46:41 +0200218 ResourceKeyRef(ResourceName&& n, const android::ConfigDescription& c) = delete;
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800219};
220
221bool operator<(const ResourceKeyRef& a, const ResourceKeyRef& b);
222
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800223//
224// ResourceId implementation.
225//
226
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700227inline ResourceId::ResourceId() : id(0) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800228
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700229inline ResourceId::ResourceId(const ResourceId& rhs) : id(rhs.id) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800230
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700231inline ResourceId::ResourceId(uint32_t res_id) : id(res_id) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800232
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700233inline ResourceId::ResourceId(uint8_t p, uint8_t t, uint16_t e)
234 : id((p << 24) | (t << 16) | e) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800235
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700236inline bool ResourceId::is_valid() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700237 return (id & 0xff000000u) != 0 && (id & 0x00ff0000u) != 0;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800238}
239
Adam Lesinski93190b72017-11-03 15:20:17 -0700240inline bool ResourceId::is_valid_dynamic() const {
241 return (id & 0x00ff0000u) != 0;
242}
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800243
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700244inline uint8_t ResourceId::package_id() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700245 return static_cast<uint8_t>(id >> 24);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800246}
247
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700248inline uint8_t ResourceId::type_id() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700249 return static_cast<uint8_t>(id >> 16);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800250}
251
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700252inline uint16_t ResourceId::entry_id() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700253 return static_cast<uint16_t>(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 Lesinski6f6ceb72014-11-14 14:48:12 -0800258}
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 Lesinski24aad162015-04-24 19:19:30 -0700262}
263
Adam Lesinski74605cd2016-03-03 15:39:50 -0800264inline 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
268inline bool operator!=(const ResourceId& lhs, const ResourceId& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700269 return lhs.id != rhs.id;
Adam Lesinski74605cd2016-03-03 15:39:50 -0800270}
271
Adam Lesinski93190b72017-11-03 15:20:17 -0700272inline ::std::ostream& operator<<(::std::ostream& out, const ResourceId& res_id) {
273 return out << res_id.to_string();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800274}
275
Adam Lesinskia693c4a2017-11-09 11:29:39 -0800276// For generic code to call 'using std::to_string; to_string(T);'.
277inline std::string to_string(const ResourceId& id) {
278 return id.to_string();
279}
280
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800281//
282// ResourceType implementation.
283//
284
Adam Lesinski93190b72017-11-03 15:20:17 -0700285inline ::std::ostream& operator<<(::std::ostream& out, const ResourceType& val) {
286 return out << to_string(val);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800287}
288
289//
290// ResourceName implementation.
291//
292
Adam Lesinskid5083f62017-01-16 15:07:21 -0800293inline ResourceName::ResourceName(const android::StringPiece& p, ResourceType t,
294 const android::StringPiece& e)
295 : package(p.to_string()), type(t), entry(e.to_string()) {}
Adam Lesinski9ba47d82015-10-13 11:37:10 -0700296
Adam Lesinski8197cc462016-08-19 12:16:49 -0700297inline int ResourceName::compare(const ResourceName& other) const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700298 int cmp = package.compare(other.package);
299 if (cmp != 0) return cmp;
300 cmp = static_cast<int>(type) - static_cast<int>(other.type);
301 if (cmp != 0) return cmp;
302 cmp = entry.compare(other.entry);
303 return cmp;
Adam Lesinski8197cc462016-08-19 12:16:49 -0700304}
305
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700306inline bool ResourceName::is_valid() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700307 return !package.empty() && !entry.empty();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800308}
309
Adam Lesinski74605cd2016-03-03 15:39:50 -0800310inline bool operator<(const ResourceName& lhs, const ResourceName& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700311 return std::tie(lhs.package, lhs.type, lhs.entry) <
312 std::tie(rhs.package, rhs.type, rhs.entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800313}
314
Adam Lesinski74605cd2016-03-03 15:39:50 -0800315inline bool operator==(const ResourceName& lhs, const ResourceName& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700316 return std::tie(lhs.package, lhs.type, lhs.entry) ==
317 std::tie(rhs.package, rhs.type, rhs.entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800318}
319
Adam Lesinski74605cd2016-03-03 15:39:50 -0800320inline bool operator!=(const ResourceName& lhs, const ResourceName& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700321 return std::tie(lhs.package, lhs.type, lhs.entry) !=
322 std::tie(rhs.package, rhs.type, rhs.entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800323}
324
Adam Lesinski93190b72017-11-03 15:20:17 -0700325inline ::std::ostream& operator<<(::std::ostream& out, const ResourceName& name) {
326 return out << name.to_string();
Adam Lesinskid0f116b2016-07-08 15:00:32 -0700327}
Adam Lesinski769de982015-04-10 19:43:55 -0700328
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800329//
330// ResourceNameRef implementation.
331//
332
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700333inline ResourceNameRef::ResourceNameRef(const ResourceName& rhs)
334 : package(rhs.package), type(rhs.type), entry(rhs.entry) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800335
Adam Lesinskid5083f62017-01-16 15:07:21 -0800336inline ResourceNameRef::ResourceNameRef(const android::StringPiece& p, ResourceType t,
337 const android::StringPiece& e)
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700338 : package(p), type(t), entry(e) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800339
340inline ResourceNameRef& ResourceNameRef::operator=(const ResourceName& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700341 package = rhs.package;
342 type = rhs.type;
343 entry = rhs.entry;
344 return *this;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800345}
346
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700347inline ResourceName ResourceNameRef::ToResourceName() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700348 return ResourceName(package, type, entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800349}
350
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700351inline bool ResourceNameRef::is_valid() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700352 return !package.empty() && !entry.empty();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800353}
354
Adam Lesinski74605cd2016-03-03 15:39:50 -0800355inline bool operator<(const ResourceNameRef& lhs, const ResourceNameRef& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700356 return std::tie(lhs.package, lhs.type, lhs.entry) <
357 std::tie(rhs.package, rhs.type, rhs.entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800358}
359
Adam Lesinski74605cd2016-03-03 15:39:50 -0800360inline bool operator==(const ResourceNameRef& lhs, const ResourceNameRef& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700361 return std::tie(lhs.package, lhs.type, lhs.entry) ==
362 std::tie(rhs.package, rhs.type, rhs.entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800363}
364
Adam Lesinski74605cd2016-03-03 15:39:50 -0800365inline bool operator!=(const ResourceNameRef& lhs, const ResourceNameRef& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700366 return std::tie(lhs.package, lhs.type, lhs.entry) !=
367 std::tie(rhs.package, rhs.type, rhs.entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800368}
369
Adam Lesinski93190b72017-11-03 15:20:17 -0700370inline ::std::ostream& operator<<(::std::ostream& out, const ResourceNameRef& name) {
371 return out << name.to_string();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800372}
373
Adam Lesinski74605cd2016-03-03 15:39:50 -0800374inline bool operator<(const ResourceName& lhs, const ResourceNameRef& b) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700375 return ResourceNameRef(lhs) < b;
Adam Lesinski74605cd2016-03-03 15:39:50 -0800376}
377
378inline bool operator!=(const ResourceName& lhs, const ResourceNameRef& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700379 return ResourceNameRef(lhs) != rhs;
Adam Lesinski74605cd2016-03-03 15:39:50 -0800380}
381
Adam Lesinski93190b72017-11-03 15:20:17 -0700382inline bool operator==(const SourcedResourceName& lhs, const SourcedResourceName& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700383 return lhs.name == rhs.name && lhs.line == rhs.line;
Adam Lesinski74605cd2016-03-03 15:39:50 -0800384}
385
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700386} // namespace aapt
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800387
Adam Lesinskibf0bd0f2016-06-01 15:31:50 -0700388namespace std {
389
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700390template <>
391struct hash<aapt::ResourceName> {
392 size_t operator()(const aapt::ResourceName& name) const {
393 android::hash_t h = 0;
Adam Lesinskic744ae82017-05-17 19:28:38 -0700394 h = android::JenkinsHashMix(h, static_cast<uint32_t>(hash<string>()(name.package)));
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700395 h = android::JenkinsHashMix(h, static_cast<uint32_t>(name.type));
Adam Lesinskic744ae82017-05-17 19:28:38 -0700396 h = android::JenkinsHashMix(h, static_cast<uint32_t>(hash<string>()(name.entry)));
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700397 return static_cast<size_t>(h);
398 }
Adam Lesinskibf0bd0f2016-06-01 15:31:50 -0700399};
400
Adam Lesinskic744ae82017-05-17 19:28:38 -0700401template <>
402struct hash<aapt::ResourceId> {
403 size_t operator()(const aapt::ResourceId& id) const {
404 return id.id;
405 }
406};
407
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700408} // namespace std
Adam Lesinskibf0bd0f2016-06-01 15:31:50 -0700409
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700410#endif // AAPT_RESOURCE_H