blob: cbcc8fb805aa1585d3fa034575b39b9b1d76ed01 [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 Lesinskiee0e4862017-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 Lesinskicacb28f2016-10-19 12:18:14 -0700160 // Name
161 ResourceName name;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700162
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700163 // Configuration
164 ConfigDescription config;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700165
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700166 // Source
167 Source source;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700168
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700169 // Exported symbols
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700170 std::vector<SourcedResourceName> exported_symbols;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700171};
172
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800173/**
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700174 * Useful struct used as a key to represent a unique resource in associative
175 * containers.
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800176 */
177struct ResourceKey {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700178 ResourceName name;
179 ConfigDescription config;
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800180};
181
182bool operator<(const ResourceKey& a, const ResourceKey& b);
183
184/**
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700185 * Useful struct used as a key to represent a unique resource in associative
186 * containers.
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800187 * Holds a reference to the name, so that name better live longer than this key!
188 */
189struct ResourceKeyRef {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700190 ResourceNameRef name;
191 ConfigDescription config;
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800192
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700193 ResourceKeyRef() = default;
194 ResourceKeyRef(const ResourceNameRef& n, const ConfigDescription& c)
195 : name(n), config(c) {}
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800196
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700197 /**
198 * Prevent taking a reference to a temporary. This is bad.
199 */
200 ResourceKeyRef(ResourceName&& n, const ConfigDescription& c) = delete;
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800201};
202
203bool operator<(const ResourceKeyRef& a, const ResourceKeyRef& b);
204
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800205//
206// ResourceId implementation.
207//
208
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700209inline ResourceId::ResourceId() : id(0) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800210
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700211inline ResourceId::ResourceId(const ResourceId& rhs) : id(rhs.id) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800212
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700213inline ResourceId::ResourceId(uint32_t res_id) : id(res_id) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800214
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700215inline ResourceId::ResourceId(uint8_t p, uint8_t t, uint16_t e)
216 : id((p << 24) | (t << 16) | e) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800217
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700218inline bool ResourceId::is_valid() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700219 return (id & 0xff000000u) != 0 && (id & 0x00ff0000u) != 0;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800220}
221
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800222inline bool ResourceId::is_valid_dynamic() const { return (id & 0x00ff0000u) != 0; }
223
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700224inline uint8_t ResourceId::package_id() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700225 return static_cast<uint8_t>(id >> 24);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800226}
227
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700228inline uint8_t ResourceId::type_id() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700229 return static_cast<uint8_t>(id >> 16);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800230}
231
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700232inline uint16_t ResourceId::entry_id() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700233 return static_cast<uint16_t>(id);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800234}
235
Adam Lesinski74605cd2016-03-03 15:39:50 -0800236inline bool operator<(const ResourceId& lhs, const ResourceId& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700237 return lhs.id < rhs.id;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800238}
239
Adam Lesinski74605cd2016-03-03 15:39:50 -0800240inline bool operator>(const ResourceId& lhs, const ResourceId& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700241 return lhs.id > rhs.id;
Adam Lesinski24aad162015-04-24 19:19:30 -0700242}
243
Adam Lesinski74605cd2016-03-03 15:39:50 -0800244inline bool operator==(const ResourceId& lhs, const ResourceId& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700245 return lhs.id == rhs.id;
Adam Lesinski74605cd2016-03-03 15:39:50 -0800246}
247
248inline bool operator!=(const ResourceId& lhs, const ResourceId& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700249 return lhs.id != rhs.id;
Adam Lesinski74605cd2016-03-03 15:39:50 -0800250}
251
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700252inline ::std::ostream& operator<<(::std::ostream& out,
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700253 const ResourceId& res_id) {
254 std::ios_base::fmtflags old_flags = out.flags();
255 char old_fill = out.fill();
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700256 out << "0x" << std::internal << std::setfill('0') << std::setw(8) << std::hex
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700257 << res_id.id;
258 out.flags(old_flags);
259 out.fill(old_fill);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700260 return out;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800261}
262
263//
264// ResourceType implementation.
265//
266
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700267inline ::std::ostream& operator<<(::std::ostream& out,
268 const ResourceType& val) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700269 return out << ToString(val);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800270}
271
272//
273// ResourceName implementation.
274//
275
Adam Lesinskid5083f62017-01-16 15:07:21 -0800276inline ResourceName::ResourceName(const android::StringPiece& p, ResourceType t,
277 const android::StringPiece& e)
278 : package(p.to_string()), type(t), entry(e.to_string()) {}
Adam Lesinski9ba47d82015-10-13 11:37:10 -0700279
Adam Lesinski8197cc462016-08-19 12:16:49 -0700280inline int ResourceName::compare(const ResourceName& other) const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700281 int cmp = package.compare(other.package);
282 if (cmp != 0) return cmp;
283 cmp = static_cast<int>(type) - static_cast<int>(other.type);
284 if (cmp != 0) return cmp;
285 cmp = entry.compare(other.entry);
286 return cmp;
Adam Lesinski8197cc462016-08-19 12:16:49 -0700287}
288
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700289inline bool ResourceName::is_valid() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700290 return !package.empty() && !entry.empty();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800291}
292
Adam Lesinski74605cd2016-03-03 15:39:50 -0800293inline bool operator<(const ResourceName& lhs, const ResourceName& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700294 return std::tie(lhs.package, lhs.type, lhs.entry) <
295 std::tie(rhs.package, rhs.type, rhs.entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800296}
297
Adam Lesinski74605cd2016-03-03 15:39:50 -0800298inline bool operator==(const ResourceName& lhs, const ResourceName& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700299 return std::tie(lhs.package, lhs.type, lhs.entry) ==
300 std::tie(rhs.package, rhs.type, rhs.entry);
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 Lesinskicacb28f2016-10-19 12:18:14 -0700308inline ::std::ostream& operator<<(::std::ostream& out,
309 const ResourceName& name) {
310 if (!name.package.empty()) {
311 out << name.package << ":";
312 }
313 return out << name.type << "/" << name.entry;
Adam Lesinski769de982015-04-10 19:43:55 -0700314}
315
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700316inline std::string ResourceName::ToString() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700317 std::stringstream stream;
318 stream << *this;
319 return stream.str();
Adam Lesinskid0f116b2016-07-08 15:00:32 -0700320}
Adam Lesinski769de982015-04-10 19:43:55 -0700321
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800322//
323// ResourceNameRef implementation.
324//
325
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700326inline ResourceNameRef::ResourceNameRef(const ResourceName& rhs)
327 : package(rhs.package), type(rhs.type), entry(rhs.entry) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800328
Adam Lesinskid5083f62017-01-16 15:07:21 -0800329inline ResourceNameRef::ResourceNameRef(const android::StringPiece& p, ResourceType t,
330 const android::StringPiece& e)
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700331 : package(p), type(t), entry(e) {}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800332
333inline ResourceNameRef& ResourceNameRef::operator=(const ResourceName& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700334 package = rhs.package;
335 type = rhs.type;
336 entry = rhs.entry;
337 return *this;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800338}
339
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700340inline ResourceName ResourceNameRef::ToResourceName() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700341 return ResourceName(package, type, entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800342}
343
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700344inline bool ResourceNameRef::is_valid() const {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700345 return !package.empty() && !entry.empty();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800346}
347
Adam Lesinski74605cd2016-03-03 15:39:50 -0800348inline bool operator<(const ResourceNameRef& lhs, const ResourceNameRef& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700349 return std::tie(lhs.package, lhs.type, lhs.entry) <
350 std::tie(rhs.package, rhs.type, rhs.entry);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800351}
352
Adam Lesinski74605cd2016-03-03 15:39:50 -0800353inline bool operator==(const ResourceNameRef& lhs, const ResourceNameRef& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700354 return std::tie(lhs.package, lhs.type, lhs.entry) ==
355 std::tie(rhs.package, rhs.type, rhs.entry);
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 Lesinskicacb28f2016-10-19 12:18:14 -0700363inline ::std::ostream& operator<<(::std::ostream& out,
364 const ResourceNameRef& name) {
365 if (!name.package.empty()) {
366 out << name.package << ":";
367 }
368 return out << name.type << "/" << name.entry;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800369}
370
Adam Lesinski74605cd2016-03-03 15:39:50 -0800371inline bool operator<(const ResourceName& lhs, const ResourceNameRef& b) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700372 return ResourceNameRef(lhs) < b;
Adam Lesinski74605cd2016-03-03 15:39:50 -0800373}
374
375inline bool operator!=(const ResourceName& lhs, const ResourceNameRef& rhs) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700376 return ResourceNameRef(lhs) != rhs;
Adam Lesinski74605cd2016-03-03 15:39:50 -0800377}
378
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700379inline bool operator==(const SourcedResourceName& lhs,
380 const SourcedResourceName& rhs) {
381 return lhs.name == rhs.name && lhs.line == rhs.line;
Adam Lesinski74605cd2016-03-03 15:39:50 -0800382}
383
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700384} // namespace aapt
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800385
Adam Lesinskibf0bd0f2016-06-01 15:31:50 -0700386namespace std {
387
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700388template <>
389struct hash<aapt::ResourceName> {
390 size_t operator()(const aapt::ResourceName& name) const {
391 android::hash_t h = 0;
Adam Lesinskic744ae82017-05-17 19:28:38 -0700392 h = android::JenkinsHashMix(h, static_cast<uint32_t>(hash<string>()(name.package)));
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700393 h = android::JenkinsHashMix(h, static_cast<uint32_t>(name.type));
Adam Lesinskic744ae82017-05-17 19:28:38 -0700394 h = android::JenkinsHashMix(h, static_cast<uint32_t>(hash<string>()(name.entry)));
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700395 return static_cast<size_t>(h);
396 }
Adam Lesinskibf0bd0f2016-06-01 15:31:50 -0700397};
398
Adam Lesinskic744ae82017-05-17 19:28:38 -0700399template <>
400struct hash<aapt::ResourceId> {
401 size_t operator()(const aapt::ResourceId& id) const {
402 return id.id;
403 }
404};
405
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700406} // namespace std
Adam Lesinskibf0bd0f2016-06-01 15:31:50 -0700407
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700408#endif // AAPT_RESOURCE_H