blob: 87b986784961a53773a463f01daf1899602c9664 [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
Adam Lesinskid5083f62017-01-16 15:07:21 -080027#include "androidfw/StringPiece.h"
Adam Lesinskice5e56e2016-10-21 17:56:45 -070028#include "utils/JenkinsHash.h"
29
30#include "ConfigDescription.h"
31#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 Lesinskid5083f62017-01-16 15:07:21 -080072android::StringPiece ToString(ResourceType type);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080073
74/**
75 * Returns a pointer to a valid ResourceType, or nullptr if
76 * the string was invalid.
77 */
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;
95 std::string ToString() 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;
112 ResourceNameRef(const ResourceName& rhs); // NOLINT(implicit)
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 ResourceName ToResourceName() const;
119 bool is_valid() const;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800120};
121
Adam Lesinskib5dc4bd2017-02-22 19:29:29 -0800122constexpr const uint8_t kAppPackageId = 0x7fu;
123constexpr const uint8_t kFrameworkPackageId = 0x01u;
124
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800125/**
126 * A binary identifier representing a resource. Internally it
127 * is a 32bit integer split as follows:
128 *
129 * 0xPPTTEEEE
130 *
131 * PP: 8 bit package identifier. 0x01 is reserved for system
132 * and 0x7f is reserved for the running app.
133 * TT: 8 bit type identifier. 0x00 is invalid.
134 * EEEE: 16 bit entry identifier.
135 */
136struct ResourceId {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700137 uint32_t id;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800138
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700139 ResourceId();
140 ResourceId(const ResourceId& rhs);
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700141 ResourceId(uint32_t res_id); // NOLINT(implicit)
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700142 ResourceId(uint8_t p, uint8_t t, uint16_t e);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800143
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700144 bool is_valid() const;
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800145
146 // Returns true if the ID is a valid ID or dynamic ID (package ID can be 0).
147 bool is_valid_dynamic() const;
148
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700149 uint8_t package_id() const;
150 uint8_t type_id() const;
151 uint16_t entry_id() const;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800152};
153
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700154struct SourcedResourceName {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700155 ResourceName name;
156 size_t line;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700157};
158
159struct ResourceFile {
Adam Lesinski00451162017-10-03 07:44:08 -0700160 enum class Type {
161 kUnknown,
162 kPng,
163 kBinaryXml,
164 kProtoXml,
165 };
166
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700167 // Name
168 ResourceName name;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700169
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700170 // Configuration
171 ConfigDescription config;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700172
Adam Lesinski00451162017-10-03 07:44:08 -0700173 // Type
174 Type type;
175
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700176 // Source
177 Source source;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700178
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700179 // Exported symbols
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700180 std::vector<SourcedResourceName> exported_symbols;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700181};
182
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800183/**
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700184 * Useful struct used as a key to represent a unique resource in associative
185 * containers.
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800186 */
187struct ResourceKey {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700188 ResourceName name;
189 ConfigDescription config;
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800190};
191
192bool operator<(const ResourceKey& a, const ResourceKey& b);
193
194/**
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700195 * Useful struct used as a key to represent a unique resource in associative
196 * containers.
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800197 * Holds a reference to the name, so that name better live longer than this key!
198 */
199struct ResourceKeyRef {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700200 ResourceNameRef name;
201 ConfigDescription config;
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800202
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700203 ResourceKeyRef() = default;
204 ResourceKeyRef(const ResourceNameRef& n, const ConfigDescription& c)
205 : name(n), config(c) {}
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800206
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700207 /**
208 * Prevent taking a reference to a temporary. This is bad.
209 */
210 ResourceKeyRef(ResourceName&& n, const ConfigDescription& c) = delete;
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800211};
212
213bool operator<(const ResourceKeyRef& a, const ResourceKeyRef& b);
214
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800215//
216// ResourceId implementation.
217//
218
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700219inline ResourceId::ResourceId() : id(0) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800220
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700221inline ResourceId::ResourceId(const ResourceId& rhs) : id(rhs.id) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800222
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700223inline ResourceId::ResourceId(uint32_t res_id) : id(res_id) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800224
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700225inline ResourceId::ResourceId(uint8_t p, uint8_t t, uint16_t e)
226 : id((p << 24) | (t << 16) | e) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800227
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700228inline bool ResourceId::is_valid() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700229 return (id & 0xff000000u) != 0 && (id & 0x00ff0000u) != 0;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800230}
231
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800232inline bool ResourceId::is_valid_dynamic() const { return (id & 0x00ff0000u) != 0; }
233
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700234inline uint8_t ResourceId::package_id() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700235 return static_cast<uint8_t>(id >> 24);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800236}
237
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700238inline uint8_t ResourceId::type_id() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700239 return static_cast<uint8_t>(id >> 16);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800240}
241
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700242inline uint16_t ResourceId::entry_id() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700243 return static_cast<uint16_t>(id);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800244}
245
Adam Lesinski74605cd2016-03-03 15:39:50 -0800246inline bool operator<(const ResourceId& lhs, const ResourceId& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700247 return lhs.id < rhs.id;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800248}
249
Adam Lesinski74605cd2016-03-03 15:39:50 -0800250inline bool operator>(const ResourceId& lhs, const ResourceId& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700251 return lhs.id > rhs.id;
Adam Lesinski24aad162015-04-24 19:19:30 -0700252}
253
Adam Lesinski74605cd2016-03-03 15:39:50 -0800254inline bool operator==(const ResourceId& lhs, const ResourceId& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700255 return lhs.id == rhs.id;
Adam Lesinski74605cd2016-03-03 15:39:50 -0800256}
257
258inline bool operator!=(const ResourceId& lhs, const ResourceId& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700259 return lhs.id != rhs.id;
Adam Lesinski74605cd2016-03-03 15:39:50 -0800260}
261
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700262inline ::std::ostream& operator<<(::std::ostream& out,
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700263 const ResourceId& res_id) {
264 std::ios_base::fmtflags old_flags = out.flags();
265 char old_fill = out.fill();
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700266 out << "0x" << std::internal << std::setfill('0') << std::setw(8) << std::hex
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700267 << res_id.id;
268 out.flags(old_flags);
269 out.fill(old_fill);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700270 return out;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800271}
272
273//
274// ResourceType implementation.
275//
276
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700277inline ::std::ostream& operator<<(::std::ostream& out,
278 const ResourceType& val) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700279 return out << ToString(val);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800280}
281
282//
283// ResourceName implementation.
284//
285
Adam Lesinskid5083f62017-01-16 15:07:21 -0800286inline ResourceName::ResourceName(const android::StringPiece& p, ResourceType t,
287 const android::StringPiece& e)
288 : package(p.to_string()), type(t), entry(e.to_string()) {}
Adam Lesinski9ba47d82015-10-13 11:37:10 -0700289
Adam Lesinski8197cc462016-08-19 12:16:49 -0700290inline int ResourceName::compare(const ResourceName& other) const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700291 int cmp = package.compare(other.package);
292 if (cmp != 0) return cmp;
293 cmp = static_cast<int>(type) - static_cast<int>(other.type);
294 if (cmp != 0) return cmp;
295 cmp = entry.compare(other.entry);
296 return cmp;
Adam Lesinski8197cc462016-08-19 12:16:49 -0700297}
298
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700299inline bool ResourceName::is_valid() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700300 return !package.empty() && !entry.empty();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800301}
302
Adam Lesinski74605cd2016-03-03 15:39:50 -0800303inline bool operator<(const ResourceName& lhs, const ResourceName& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700304 return std::tie(lhs.package, lhs.type, lhs.entry) <
305 std::tie(rhs.package, rhs.type, rhs.entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800306}
307
Adam Lesinski74605cd2016-03-03 15:39:50 -0800308inline bool operator==(const ResourceName& lhs, const ResourceName& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700309 return std::tie(lhs.package, lhs.type, lhs.entry) ==
310 std::tie(rhs.package, rhs.type, rhs.entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800311}
312
Adam Lesinski74605cd2016-03-03 15:39:50 -0800313inline bool operator!=(const ResourceName& lhs, const ResourceName& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700314 return std::tie(lhs.package, lhs.type, lhs.entry) !=
315 std::tie(rhs.package, rhs.type, rhs.entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800316}
317
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700318inline ::std::ostream& operator<<(::std::ostream& out,
319 const ResourceName& name) {
320 if (!name.package.empty()) {
321 out << name.package << ":";
322 }
323 return out << name.type << "/" << name.entry;
Adam Lesinski769de982015-04-10 19:43:55 -0700324}
325
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700326inline std::string ResourceName::ToString() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700327 std::stringstream stream;
328 stream << *this;
329 return stream.str();
Adam Lesinskid0f116b2016-07-08 15:00:32 -0700330}
Adam Lesinski769de982015-04-10 19:43:55 -0700331
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800332//
333// ResourceNameRef implementation.
334//
335
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700336inline ResourceNameRef::ResourceNameRef(const ResourceName& rhs)
337 : package(rhs.package), type(rhs.type), entry(rhs.entry) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800338
Adam Lesinskid5083f62017-01-16 15:07:21 -0800339inline ResourceNameRef::ResourceNameRef(const android::StringPiece& p, ResourceType t,
340 const android::StringPiece& e)
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700341 : package(p), type(t), entry(e) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800342
343inline ResourceNameRef& ResourceNameRef::operator=(const ResourceName& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700344 package = rhs.package;
345 type = rhs.type;
346 entry = rhs.entry;
347 return *this;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800348}
349
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700350inline ResourceName ResourceNameRef::ToResourceName() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700351 return ResourceName(package, type, entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800352}
353
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700354inline bool ResourceNameRef::is_valid() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700355 return !package.empty() && !entry.empty();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800356}
357
Adam Lesinski74605cd2016-03-03 15:39:50 -0800358inline bool operator<(const ResourceNameRef& lhs, const ResourceNameRef& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700359 return std::tie(lhs.package, lhs.type, lhs.entry) <
360 std::tie(rhs.package, rhs.type, rhs.entry);
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 Lesinskicacb28f2016-10-19 12:18:14 -0700373inline ::std::ostream& operator<<(::std::ostream& out,
374 const ResourceNameRef& name) {
375 if (!name.package.empty()) {
376 out << name.package << ":";
377 }
378 return out << name.type << "/" << name.entry;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800379}
380
Adam Lesinski74605cd2016-03-03 15:39:50 -0800381inline bool operator<(const ResourceName& lhs, const ResourceNameRef& b) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700382 return ResourceNameRef(lhs) < b;
Adam Lesinski74605cd2016-03-03 15:39:50 -0800383}
384
385inline bool operator!=(const ResourceName& lhs, const ResourceNameRef& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700386 return ResourceNameRef(lhs) != rhs;
Adam Lesinski74605cd2016-03-03 15:39:50 -0800387}
388
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700389inline bool operator==(const SourcedResourceName& lhs,
390 const SourcedResourceName& rhs) {
391 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