blob: fe0883be50aa4ed30c816d0f9647cc6e3fba0404 [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_VALUES_H
18#define AAPT_RESOURCE_VALUES_H
19
Adam Lesinskice5e56e2016-10-21 17:56:45 -070020#include <array>
Adam Lesinskic744ae82017-05-17 19:28:38 -070021#include <limits>
Adam Lesinskice5e56e2016-10-21 17:56:45 -070022#include <ostream>
23#include <vector>
24
25#include "androidfw/ResourceTypes.h"
Adam Lesinskid5083f62017-01-16 15:07:21 -080026#include "androidfw/StringPiece.h"
Adam Lesinskice5e56e2016-10-21 17:56:45 -070027
Adam Lesinskia5870652015-11-20 15:32:30 -080028#include "Diagnostics.h"
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080029#include "Resource.h"
30#include "StringPool.h"
Adam Lesinski355f2852016-02-13 20:26:45 -080031#include "io/File.h"
Adam Lesinski93190b72017-11-03 15:20:17 -070032#include "text/Printer.h"
Adam Lesinskia5870652015-11-20 15:32:30 -080033#include "util/Maybe.h"
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080034
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080035namespace aapt {
36
Adam Lesinskid3ffa8442017-09-28 13:34:35 -070037class ValueVisitor;
38class ConstValueVisitor;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080039
Adam Lesinski75421622017-01-06 15:20:04 -080040// A resource value. This is an all-encompassing representation
41// of Item and Map and their subclasses. The way to do
42// type specific operations is to check the Value's type() and
43// cast it to the appropriate subclass. This isn't super clean,
44// but it is the simplest strategy.
Adam Lesinski5924d8c2017-05-30 15:15:58 -070045class Value {
46 public:
Adam Lesinskicacb28f2016-10-19 12:18:14 -070047 virtual ~Value() = default;
Adam Lesinski1ab598f2015-08-14 14:26:04 -070048
Adam Lesinski75421622017-01-06 15:20:04 -080049 // Whether this value is weak and can be overridden without warning or error. Default is false.
Adam Lesinskid3ffa8442017-09-28 13:34:35 -070050 bool IsWeak() const {
51 return weak_;
52 }
Adam Lesinski393b5f02015-12-17 13:03:11 -080053
Adam Lesinskid3ffa8442017-09-28 13:34:35 -070054 void SetWeak(bool val) {
55 weak_ = val;
56 }
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080057
Adam Lesinskid3ffa8442017-09-28 13:34:35 -070058 // Whether the value is marked as translatable. This does not persist when flattened to binary.
Adam Lesinskicacb28f2016-10-19 12:18:14 -070059 // It is only used during compilation phase.
Adam Lesinskid3ffa8442017-09-28 13:34:35 -070060 void SetTranslatable(bool val) {
61 translatable_ = val;
62 }
Adam Lesinski458b8772016-04-25 14:20:21 -070063
Adam Lesinskicacb28f2016-10-19 12:18:14 -070064 // Default true.
Adam Lesinskid3ffa8442017-09-28 13:34:35 -070065 bool IsTranslatable() const {
66 return translatable_;
67 }
Adam Lesinski458b8772016-04-25 14:20:21 -070068
Adam Lesinski75421622017-01-06 15:20:04 -080069 // Returns the source where this value was defined.
Adam Lesinskid3ffa8442017-09-28 13:34:35 -070070 const Source& GetSource() const {
71 return source_;
72 }
Adam Lesinskie78fd612015-10-22 12:48:43 -070073
Adam Lesinskid3ffa8442017-09-28 13:34:35 -070074 void SetSource(const Source& source) {
75 source_ = source;
76 }
Adam Lesinskie78fd612015-10-22 12:48:43 -070077
Adam Lesinskid3ffa8442017-09-28 13:34:35 -070078 void SetSource(Source&& source) {
79 source_ = std::move(source);
80 }
Adam Lesinskie78fd612015-10-22 12:48:43 -070081
Adam Lesinski75421622017-01-06 15:20:04 -080082 // Returns the comment that was associated with this resource.
Adam Lesinskid3ffa8442017-09-28 13:34:35 -070083 const std::string& GetComment() const {
84 return comment_;
85 }
Adam Lesinskie78fd612015-10-22 12:48:43 -070086
Adam Lesinskid3ffa8442017-09-28 13:34:35 -070087 void SetComment(const android::StringPiece& str) {
88 comment_ = str.to_string();
89 }
Adam Lesinskie78fd612015-10-22 12:48:43 -070090
Adam Lesinskid3ffa8442017-09-28 13:34:35 -070091 void SetComment(std::string&& str) {
92 comment_ = std::move(str);
93 }
Adam Lesinskie78fd612015-10-22 12:48:43 -070094
Adam Lesinskice5e56e2016-10-21 17:56:45 -070095 virtual bool Equals(const Value* value) const = 0;
Adam Lesinski458b8772016-04-25 14:20:21 -070096
Adam Lesinski75421622017-01-06 15:20:04 -080097 // Calls the appropriate overload of ValueVisitor.
Adam Lesinskid3ffa8442017-09-28 13:34:35 -070098 virtual void Accept(ValueVisitor* visitor) = 0;
99
100 // Calls the appropriate overload of ConstValueVisitor.
101 virtual void Accept(ConstValueVisitor* visitor) const = 0;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800102
Adam Lesinski75421622017-01-06 15:20:04 -0800103 // Clone the value. `new_pool` is the new StringPool that
104 // any resources with strings should use when copying their string.
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700105 virtual Value* Clone(StringPool* new_pool) const = 0;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800106
Adam Lesinski75421622017-01-06 15:20:04 -0800107 // Human readable printout of this value.
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700108 virtual void Print(std::ostream* out) const = 0;
Adam Lesinskie78fd612015-10-22 12:48:43 -0700109
Adam Lesinski93190b72017-11-03 15:20:17 -0700110 // Human readable printout of this value that may omit some information for the sake
111 // of brevity and readability. Default implementation just calls Print().
112 virtual void PrettyPrint(text::Printer* printer) const;
113
Adam Lesinski5924d8c2017-05-30 15:15:58 -0700114 friend std::ostream& operator<<(std::ostream& out, const Value& value);
115
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700116 protected:
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700117 Source source_;
118 std::string comment_;
119 bool weak_ = false;
Adam Lesinski75421622017-01-06 15:20:04 -0800120 bool translatable_ = true;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800121};
122
Adam Lesinski75421622017-01-06 15:20:04 -0800123// Inherit from this to get visitor accepting implementations for free.
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800124template <typename Derived>
125struct BaseValue : public Value {
Adam Lesinskid3ffa8442017-09-28 13:34:35 -0700126 void Accept(ValueVisitor* visitor) override;
127 void Accept(ConstValueVisitor* visitor) const override;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800128};
129
Adam Lesinski75421622017-01-06 15:20:04 -0800130// A resource item with a single value. This maps to android::ResTable_entry.
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800131struct Item : public Value {
Adam Lesinski75421622017-01-06 15:20:04 -0800132 // Clone the Item.
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700133 virtual Item* Clone(StringPool* new_pool) const override = 0;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800134
Adam Lesinski75421622017-01-06 15:20:04 -0800135 // Fills in an android::Res_value structure with this Item's binary representation.
136 // Returns false if an error occurred.
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700137 virtual bool Flatten(android::Res_value* out_value) const = 0;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800138};
139
Adam Lesinski75421622017-01-06 15:20:04 -0800140// Inherit from this to get visitor accepting implementations for free.
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800141template <typename Derived>
142struct BaseItem : public Item {
Adam Lesinskid3ffa8442017-09-28 13:34:35 -0700143 void Accept(ValueVisitor* visitor) override;
144 void Accept(ConstValueVisitor* visitor) const override;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800145};
146
Adam Lesinski75421622017-01-06 15:20:04 -0800147// A reference to another resource. This maps to android::Res_value::TYPE_REFERENCE.
148// A reference can be symbolic (with the name set to a valid resource name) or be
149// numeric (the id is set to a valid resource ID).
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800150struct Reference : public BaseItem<Reference> {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700151 enum class Type {
152 kResource,
153 kAttribute,
154 };
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800155
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700156 Maybe<ResourceName> name;
157 Maybe<ResourceId> id;
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700158 Reference::Type reference_type;
159 bool private_reference = false;
Todd Kennedy32512992018-04-25 16:45:59 -0700160 bool is_dynamic = false;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800161
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700162 Reference();
163 explicit Reference(const ResourceNameRef& n, Type type = Type::kResource);
164 explicit Reference(const ResourceId& i, Type type = Type::kResource);
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700165 Reference(const ResourceNameRef& n, const ResourceId& i);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800166
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700167 bool Equals(const Value* value) const override;
168 bool Flatten(android::Res_value* out_value) const override;
169 Reference* Clone(StringPool* new_pool) const override;
170 void Print(std::ostream* out) const override;
Adam Lesinski93190b72017-11-03 15:20:17 -0700171 void PrettyPrint(text::Printer* printer) const override;
172
173 // Prints the reference without a package name if the package name matches the one given.
174 void PrettyPrint(const android::StringPiece& package, text::Printer* printer) const;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800175};
176
Adam Lesinski8197cc462016-08-19 12:16:49 -0700177bool operator<(const Reference&, const Reference&);
178bool operator==(const Reference&, const Reference&);
179
Adam Lesinski75421622017-01-06 15:20:04 -0800180// An ID resource. Has no real value, just a place holder.
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800181struct Id : public BaseItem<Id> {
Adam Lesinskid3ffa8442017-09-28 13:34:35 -0700182 Id() {
183 weak_ = true;
184 }
185
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700186 bool Equals(const Value* value) const override;
187 bool Flatten(android::Res_value* out) const override;
188 Id* Clone(StringPool* new_pool) const override;
189 void Print(std::ostream* out) const override;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800190};
191
Adam Lesinski75421622017-01-06 15:20:04 -0800192// A raw, unprocessed string. This may contain quotations, escape sequences, and whitespace.
193// This shall *NOT* end up in the final resource table.
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800194struct RawString : public BaseItem<RawString> {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700195 StringPool::Ref value;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800196
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700197 explicit RawString(const StringPool::Ref& ref);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800198
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700199 bool Equals(const Value* value) const override;
200 bool Flatten(android::Res_value* out_value) const override;
201 RawString* Clone(StringPool* new_pool) const override;
202 void Print(std::ostream* out) const override;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800203};
204
Adam Lesinski75421622017-01-06 15:20:04 -0800205// Identifies a range of characters in a string that are untranslatable.
206// These should not be pseudolocalized. The start and end indices are measured in bytes.
207struct UntranslatableSection {
208 // Start offset inclusive.
209 size_t start;
210
211 // End offset exclusive.
212 size_t end;
213};
214
215inline bool operator==(const UntranslatableSection& a, const UntranslatableSection& b) {
216 return a.start == b.start && a.end == b.end;
217}
218
219inline bool operator!=(const UntranslatableSection& a, const UntranslatableSection& b) {
220 return a.start != b.start || a.end != b.end;
221}
222
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800223struct String : public BaseItem<String> {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700224 StringPool::Ref value;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800225
Adam Lesinski75421622017-01-06 15:20:04 -0800226 // Sections of the string to NOT translate. Mainly used
227 // for pseudolocalization. This data is NOT persisted
228 // in any format.
229 std::vector<UntranslatableSection> untranslatable_sections;
230
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700231 explicit String(const StringPool::Ref& ref);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800232
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700233 bool Equals(const Value* value) const override;
234 bool Flatten(android::Res_value* out_value) const override;
235 String* Clone(StringPool* new_pool) const override;
236 void Print(std::ostream* out) const override;
Adam Lesinski93190b72017-11-03 15:20:17 -0700237 void PrettyPrint(text::Printer* printer) const override;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800238};
239
240struct StyledString : public BaseItem<StyledString> {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700241 StringPool::StyleRef value;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800242
Adam Lesinski75421622017-01-06 15:20:04 -0800243 // Sections of the string to NOT translate. Mainly used
244 // for pseudolocalization. This data is NOT persisted
245 // in any format.
246 std::vector<UntranslatableSection> untranslatable_sections;
247
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700248 explicit StyledString(const StringPool::StyleRef& ref);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800249
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700250 bool Equals(const Value* value) const override;
251 bool Flatten(android::Res_value* out_value) const override;
252 StyledString* Clone(StringPool* new_pool) const override;
253 void Print(std::ostream* out) const override;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800254};
255
256struct FileReference : public BaseItem<FileReference> {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700257 StringPool::Ref path;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800258
Adam Lesinski75421622017-01-06 15:20:04 -0800259 // A handle to the file object from which this file can be read.
260 // This field is NOT persisted in any format. It is transient.
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700261 io::IFile* file = nullptr;
Adam Lesinski355f2852016-02-13 20:26:45 -0800262
Adam Lesinski00451162017-10-03 07:44:08 -0700263 // FileType of the file pointed to by `file`. This is used to know how to inflate the file,
264 // or if to inflate at all (just copy).
265 ResourceFile::Type type = ResourceFile::Type::kUnknown;
266
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700267 FileReference() = default;
268 explicit FileReference(const StringPool::Ref& path);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800269
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700270 bool Equals(const Value* value) const override;
271 bool Flatten(android::Res_value* out_value) const override;
272 FileReference* Clone(StringPool* new_pool) const override;
273 void Print(std::ostream* out) const override;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800274};
275
Adam Lesinski75421622017-01-06 15:20:04 -0800276// Represents any other android::Res_value.
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800277struct BinaryPrimitive : public BaseItem<BinaryPrimitive> {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700278 android::Res_value value;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800279
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700280 BinaryPrimitive() = default;
281 explicit BinaryPrimitive(const android::Res_value& val);
282 BinaryPrimitive(uint8_t dataType, uint32_t data);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800283
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700284 bool Equals(const Value* value) const override;
285 bool Flatten(android::Res_value* out_value) const override;
286 BinaryPrimitive* Clone(StringPool* new_pool) const override;
287 void Print(std::ostream* out) const override;
Adam Lesinski93190b72017-11-03 15:20:17 -0700288 void PrettyPrint(text::Printer* printer) const override;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800289};
290
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800291struct Attribute : public BaseValue<Attribute> {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700292 struct Symbol {
293 Reference symbol;
294 uint32_t value;
Ryan Mitchellc1676802019-05-20 16:47:08 -0700295 uint8_t type;
Adam Lesinski5924d8c2017-05-30 15:15:58 -0700296
297 friend std::ostream& operator<<(std::ostream& out, const Symbol& symbol);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700298 };
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800299
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700300 uint32_t type_mask;
301 int32_t min_int;
302 int32_t max_int;
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700303 std::vector<Symbol> symbols;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800304
Adam Lesinski73bff1e2017-12-08 16:06:10 -0800305 explicit Attribute(uint32_t t = 0u);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800306
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700307 bool Equals(const Value* value) const override;
Adam Lesinski73bff1e2017-12-08 16:06:10 -0800308
309 // Returns true if this Attribute's format is compatible with the given Attribute. The basic
310 // rule is that TYPE_REFERENCE can be ignored for both of the Attributes, and TYPE_FLAGS and
311 // TYPE_ENUMS are never compatible.
312 bool IsCompatibleWith(const Attribute& attr) const;
313
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700314 Attribute* Clone(StringPool* new_pool) const override;
Adam Lesinski93190b72017-11-03 15:20:17 -0700315 std::string MaskString() const;
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700316 void Print(std::ostream* out) const override;
Adam Lesinski3124e7c2017-06-13 16:03:55 -0700317 bool Matches(const Item& item, DiagMessage* out_msg = nullptr) const;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800318};
319
320struct Style : public BaseValue<Style> {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700321 struct Entry {
322 Reference key;
323 std::unique_ptr<Item> value;
Adam Lesinski5924d8c2017-05-30 15:15:58 -0700324
325 friend std::ostream& operator<<(std::ostream& out, const Entry& entry);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700326 };
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800327
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700328 Maybe<Reference> parent;
Adam Lesinskibdaa0922015-05-08 20:16:23 -0700329
Adam Lesinski75421622017-01-06 15:20:04 -0800330 // If set to true, the parent was auto inferred from the style's name.
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700331 bool parent_inferred = false;
Adam Lesinskibdaa0922015-05-08 20:16:23 -0700332
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700333 std::vector<Entry> entries;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800334
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700335 bool Equals(const Value* value) const override;
336 Style* Clone(StringPool* new_pool) const override;
337 void Print(std::ostream* out) const override;
Adam Lesinski5924d8c2017-05-30 15:15:58 -0700338
339 // Merges `style` into this Style. All identical attributes of `style` take precedence, including
340 // the parent, if there is one.
341 void MergeWith(Style* style, StringPool* pool);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800342};
343
344struct Array : public BaseValue<Array> {
Adam Lesinski4ffea042017-08-10 15:37:28 -0700345 std::vector<std::unique_ptr<Item>> elements;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800346
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700347 bool Equals(const Value* value) const override;
348 Array* Clone(StringPool* new_pool) const override;
349 void Print(std::ostream* out) const override;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800350};
351
352struct Plural : public BaseValue<Plural> {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700353 enum { Zero = 0, One, Two, Few, Many, Other, Count };
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800354
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700355 std::array<std::unique_ptr<Item>, Count> values;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800356
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700357 bool Equals(const Value* value) const override;
358 Plural* Clone(StringPool* new_pool) const override;
359 void Print(std::ostream* out) const override;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800360};
361
362struct Styleable : public BaseValue<Styleable> {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700363 std::vector<Reference> entries;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800364
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700365 bool Equals(const Value* value) const override;
366 Styleable* Clone(StringPool* newPool) const override;
367 void Print(std::ostream* out) const override;
368 void MergeWith(Styleable* styleable);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800369};
370
Adam Lesinski5924d8c2017-05-30 15:15:58 -0700371template <typename T>
372typename std::enable_if<std::is_base_of<Value, T>::value, std::ostream&>::type operator<<(
373 std::ostream& out, const std::unique_ptr<T>& value) {
374 if (value == nullptr) {
375 out << "NULL";
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700376 } else {
Adam Lesinski5924d8c2017-05-30 15:15:58 -0700377 value->Print(&out);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700378 }
Adam Lesinski5924d8c2017-05-30 15:15:58 -0700379 return out;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800380}
381
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700382} // namespace aapt
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800383
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700384#endif // AAPT_RESOURCE_VALUES_H