Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 1 | /* |
| 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 Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 20 | #include "Diagnostics.h" |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 21 | #include "Resource.h" |
| 22 | #include "StringPool.h" |
Adam Lesinski | 355f285 | 2016-02-13 20:26:45 -0800 | [diff] [blame] | 23 | #include "io/File.h" |
Adam Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 24 | #include "util/Maybe.h" |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 25 | |
| 26 | #include <array> |
| 27 | #include <androidfw/ResourceTypes.h> |
| 28 | #include <ostream> |
| 29 | #include <vector> |
| 30 | |
| 31 | namespace aapt { |
| 32 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 33 | struct RawValueVisitor; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * A resource value. This is an all-encompassing representation |
| 37 | * of Item and Map and their subclasses. The way to do |
| 38 | * type specific operations is to check the Value's type() and |
| 39 | * cast it to the appropriate subclass. This isn't super clean, |
| 40 | * but it is the simplest strategy. |
| 41 | */ |
| 42 | struct Value { |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 43 | virtual ~Value() = default; |
| 44 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 45 | /** |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 46 | * Whether this value is weak and can be overridden without |
Adam Lesinski | 393b5f0 | 2015-12-17 13:03:11 -0800 | [diff] [blame] | 47 | * warning or error. Default is false. |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 48 | */ |
Adam Lesinski | 393b5f0 | 2015-12-17 13:03:11 -0800 | [diff] [blame] | 49 | bool isWeak() const { |
| 50 | return mWeak; |
| 51 | } |
| 52 | |
| 53 | void setWeak(bool val) { |
| 54 | mWeak = val; |
| 55 | } |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 56 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 57 | // Whether the value is marked as translateable. |
| 58 | // This does not persist when flattened. |
| 59 | // It is only used during compilation phase. |
| 60 | void setTranslateable(bool val) { |
| 61 | mTranslateable = val; |
| 62 | } |
| 63 | |
| 64 | // Default true. |
| 65 | bool isTranslateable() const { |
| 66 | return mTranslateable; |
| 67 | } |
| 68 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 69 | /** |
Adam Lesinski | e78fd61 | 2015-10-22 12:48:43 -0700 | [diff] [blame] | 70 | * Returns the source where this value was defined. |
| 71 | */ |
| 72 | const Source& getSource() const { |
| 73 | return mSource; |
| 74 | } |
| 75 | |
| 76 | void setSource(const Source& source) { |
| 77 | mSource = source; |
| 78 | } |
| 79 | |
| 80 | void setSource(Source&& source) { |
| 81 | mSource = std::move(source); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Returns the comment that was associated with this resource. |
| 86 | */ |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 87 | const std::string& getComment() const { |
Adam Lesinski | e78fd61 | 2015-10-22 12:48:43 -0700 | [diff] [blame] | 88 | return mComment; |
| 89 | } |
| 90 | |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 91 | void setComment(const StringPiece& str) { |
Adam Lesinski | e78fd61 | 2015-10-22 12:48:43 -0700 | [diff] [blame] | 92 | mComment = str.toString(); |
| 93 | } |
| 94 | |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 95 | void setComment(std::string&& str) { |
Adam Lesinski | e78fd61 | 2015-10-22 12:48:43 -0700 | [diff] [blame] | 96 | mComment = std::move(str); |
| 97 | } |
| 98 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 99 | virtual bool equals(const Value* value) const = 0; |
| 100 | |
Adam Lesinski | e78fd61 | 2015-10-22 12:48:43 -0700 | [diff] [blame] | 101 | /** |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 102 | * Calls the appropriate overload of ValueVisitor. |
| 103 | */ |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 104 | virtual void accept(RawValueVisitor* visitor) = 0; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 105 | |
| 106 | /** |
| 107 | * Clone the value. |
| 108 | */ |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 109 | virtual Value* clone(StringPool* newPool) const = 0; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 110 | |
| 111 | /** |
| 112 | * Human readable printout of this value. |
| 113 | */ |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 114 | virtual void print(std::ostream* out) const = 0; |
Adam Lesinski | e78fd61 | 2015-10-22 12:48:43 -0700 | [diff] [blame] | 115 | |
Adam Lesinski | b274e35 | 2015-11-06 15:14:35 -0800 | [diff] [blame] | 116 | protected: |
Adam Lesinski | e78fd61 | 2015-10-22 12:48:43 -0700 | [diff] [blame] | 117 | Source mSource; |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame] | 118 | std::string mComment; |
Adam Lesinski | 393b5f0 | 2015-12-17 13:03:11 -0800 | [diff] [blame] | 119 | bool mWeak = false; |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 120 | bool mTranslateable = true; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | /** |
| 124 | * Inherit from this to get visitor accepting implementations for free. |
| 125 | */ |
| 126 | template <typename Derived> |
| 127 | struct BaseValue : public Value { |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 128 | void accept(RawValueVisitor* visitor) override; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | /** |
| 132 | * A resource item with a single value. This maps to android::ResTable_entry. |
| 133 | */ |
| 134 | struct Item : public Value { |
| 135 | /** |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 136 | * Clone the Item. |
| 137 | */ |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 138 | virtual Item* clone(StringPool* newPool) const override = 0; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 139 | |
| 140 | /** |
| 141 | * Fills in an android::Res_value structure with this Item's binary representation. |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 142 | * Returns false if an error occurred. |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 143 | */ |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 144 | virtual bool flatten(android::Res_value* outValue) const = 0; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | /** |
| 148 | * Inherit from this to get visitor accepting implementations for free. |
| 149 | */ |
| 150 | template <typename Derived> |
| 151 | struct BaseItem : public Item { |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 152 | void accept(RawValueVisitor* visitor) override; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 153 | }; |
| 154 | |
| 155 | /** |
| 156 | * A reference to another resource. This maps to android::Res_value::TYPE_REFERENCE. |
| 157 | * |
| 158 | * A reference can be symbolic (with the name set to a valid resource name) or be |
| 159 | * numeric (the id is set to a valid resource ID). |
| 160 | */ |
| 161 | struct Reference : public BaseItem<Reference> { |
| 162 | enum class Type { |
| 163 | kResource, |
| 164 | kAttribute, |
| 165 | }; |
| 166 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 167 | Maybe<ResourceName> name; |
| 168 | Maybe<ResourceId> id; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 169 | Reference::Type referenceType; |
| 170 | bool privateReference = false; |
| 171 | |
| 172 | Reference(); |
Adam Lesinski | 59e04c6 | 2016-02-04 15:59:23 -0800 | [diff] [blame] | 173 | explicit Reference(const ResourceNameRef& n, Type type = Type::kResource); |
| 174 | explicit Reference(const ResourceId& i, Type type = Type::kResource); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 175 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 176 | bool equals(const Value* value) const override; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 177 | bool flatten(android::Res_value* outValue) const override; |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 178 | Reference* clone(StringPool* newPool) const override; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 179 | void print(std::ostream* out) const override; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 180 | }; |
| 181 | |
| 182 | /** |
| 183 | * An ID resource. Has no real value, just a place holder. |
| 184 | */ |
| 185 | struct Id : public BaseItem<Id> { |
Adam Lesinski | 393b5f0 | 2015-12-17 13:03:11 -0800 | [diff] [blame] | 186 | Id() { mWeak = true; } |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 187 | bool equals(const Value* value) const override; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 188 | bool flatten(android::Res_value* out) const override; |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 189 | Id* clone(StringPool* newPool) const override; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 190 | void print(std::ostream* out) const override; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 191 | }; |
| 192 | |
| 193 | /** |
| 194 | * A raw, unprocessed string. This may contain quotations, |
| 195 | * escape sequences, and whitespace. This shall *NOT* |
| 196 | * end up in the final resource table. |
| 197 | */ |
| 198 | struct RawString : public BaseItem<RawString> { |
| 199 | StringPool::Ref value; |
| 200 | |
Chih-Hung Hsieh | 9b8528f | 2016-08-10 14:15:30 -0700 | [diff] [blame^] | 201 | explicit RawString(const StringPool::Ref& ref); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 202 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 203 | bool equals(const Value* value) const override; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 204 | bool flatten(android::Res_value* outValue) const override; |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 205 | RawString* clone(StringPool* newPool) const override; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 206 | void print(std::ostream* out) const override; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 207 | }; |
| 208 | |
| 209 | struct String : public BaseItem<String> { |
| 210 | StringPool::Ref value; |
| 211 | |
Chih-Hung Hsieh | 9b8528f | 2016-08-10 14:15:30 -0700 | [diff] [blame^] | 212 | explicit String(const StringPool::Ref& ref); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 213 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 214 | bool equals(const Value* value) const override; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 215 | bool flatten(android::Res_value* outValue) const override; |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 216 | String* clone(StringPool* newPool) const override; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 217 | void print(std::ostream* out) const override; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 218 | }; |
| 219 | |
| 220 | struct StyledString : public BaseItem<StyledString> { |
| 221 | StringPool::StyleRef value; |
| 222 | |
Chih-Hung Hsieh | 9b8528f | 2016-08-10 14:15:30 -0700 | [diff] [blame^] | 223 | explicit StyledString(const StringPool::StyleRef& ref); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 224 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 225 | bool equals(const Value* value) const override; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 226 | bool flatten(android::Res_value* outValue) const override; |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 227 | StyledString* clone(StringPool* newPool) const override; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 228 | void print(std::ostream* out) const override; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 229 | }; |
| 230 | |
| 231 | struct FileReference : public BaseItem<FileReference> { |
| 232 | StringPool::Ref path; |
| 233 | |
Adam Lesinski | 355f285 | 2016-02-13 20:26:45 -0800 | [diff] [blame] | 234 | /** |
| 235 | * A handle to the file object from which this file can be read. |
| 236 | */ |
| 237 | io::IFile* file = nullptr; |
| 238 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 239 | FileReference() = default; |
Chih-Hung Hsieh | 9b8528f | 2016-08-10 14:15:30 -0700 | [diff] [blame^] | 240 | explicit FileReference(const StringPool::Ref& path); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 241 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 242 | bool equals(const Value* value) const override; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 243 | bool flatten(android::Res_value* outValue) const override; |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 244 | FileReference* clone(StringPool* newPool) const override; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 245 | void print(std::ostream* out) const override; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 246 | }; |
| 247 | |
| 248 | /** |
| 249 | * Represents any other android::Res_value. |
| 250 | */ |
| 251 | struct BinaryPrimitive : public BaseItem<BinaryPrimitive> { |
| 252 | android::Res_value value; |
| 253 | |
| 254 | BinaryPrimitive() = default; |
Chih-Hung Hsieh | 9b8528f | 2016-08-10 14:15:30 -0700 | [diff] [blame^] | 255 | explicit BinaryPrimitive(const android::Res_value& val); |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 256 | BinaryPrimitive(uint8_t dataType, uint32_t data); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 257 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 258 | bool equals(const Value* value) const override; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 259 | bool flatten(android::Res_value* outValue) const override; |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 260 | BinaryPrimitive* clone(StringPool* newPool) const override; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 261 | void print(std::ostream* out) const override; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 262 | }; |
| 263 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 264 | struct Attribute : public BaseValue<Attribute> { |
| 265 | struct Symbol { |
| 266 | Reference symbol; |
| 267 | uint32_t value; |
| 268 | }; |
| 269 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 270 | uint32_t typeMask; |
Adam Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 271 | int32_t minInt; |
| 272 | int32_t maxInt; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 273 | std::vector<Symbol> symbols; |
| 274 | |
Chih-Hung Hsieh | 9b8528f | 2016-08-10 14:15:30 -0700 | [diff] [blame^] | 275 | explicit Attribute(bool w, uint32_t t = 0u); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 276 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 277 | bool equals(const Value* value) const override; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 278 | Attribute* clone(StringPool* newPool) const override; |
| 279 | void printMask(std::ostream* out) const; |
| 280 | void print(std::ostream* out) const override; |
Adam Lesinski | a587065 | 2015-11-20 15:32:30 -0800 | [diff] [blame] | 281 | bool matches(const Item* item, DiagMessage* outMsg) const; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 282 | }; |
| 283 | |
| 284 | struct Style : public BaseValue<Style> { |
| 285 | struct Entry { |
| 286 | Reference key; |
| 287 | std::unique_ptr<Item> value; |
| 288 | }; |
| 289 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 290 | Maybe<Reference> parent; |
Adam Lesinski | bdaa092 | 2015-05-08 20:16:23 -0700 | [diff] [blame] | 291 | |
| 292 | /** |
| 293 | * If set to true, the parent was auto inferred from the |
| 294 | * style's name. |
| 295 | */ |
| 296 | bool parentInferred = false; |
| 297 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 298 | std::vector<Entry> entries; |
| 299 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 300 | bool equals(const Value* value) const override; |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 301 | Style* clone(StringPool* newPool) const override; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 302 | void print(std::ostream* out) const override; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 303 | }; |
| 304 | |
| 305 | struct Array : public BaseValue<Array> { |
| 306 | std::vector<std::unique_ptr<Item>> items; |
| 307 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 308 | bool equals(const Value* value) const override; |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 309 | Array* clone(StringPool* newPool) const override; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 310 | void print(std::ostream* out) const override; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 311 | }; |
| 312 | |
| 313 | struct Plural : public BaseValue<Plural> { |
| 314 | enum { |
| 315 | Zero = 0, |
| 316 | One, |
| 317 | Two, |
| 318 | Few, |
| 319 | Many, |
| 320 | Other, |
| 321 | Count |
| 322 | }; |
| 323 | |
| 324 | std::array<std::unique_ptr<Item>, Count> values; |
| 325 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 326 | bool equals(const Value* value) const override; |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 327 | Plural* clone(StringPool* newPool) const override; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 328 | void print(std::ostream* out) const override; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 329 | }; |
| 330 | |
| 331 | struct Styleable : public BaseValue<Styleable> { |
| 332 | std::vector<Reference> entries; |
| 333 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 334 | bool equals(const Value* value) const override; |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 335 | Styleable* clone(StringPool* newPool) const override; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 336 | void print(std::ostream* out) const override; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 337 | }; |
| 338 | |
| 339 | /** |
| 340 | * Stream operator for printing Value objects. |
| 341 | */ |
| 342 | inline ::std::ostream& operator<<(::std::ostream& out, const Value& value) { |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 343 | value.print(&out); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 344 | return out; |
| 345 | } |
| 346 | |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 347 | inline ::std::ostream& operator<<(::std::ostream& out, const Attribute::Symbol& s) { |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 348 | if (s.symbol.name) { |
| 349 | out << s.symbol.name.value().entry; |
| 350 | } else { |
| 351 | out << "???"; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 352 | } |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 353 | return out << "=" << s.value; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | } // namespace aapt |
| 357 | |
| 358 | #endif // AAPT_RESOURCE_VALUES_H |