Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [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_BINARY_XML_PULL_PARSER_H |
| 18 | #define AAPT_BINARY_XML_PULL_PARSER_H |
| 19 | |
| 20 | #include "XmlPullParser.h" |
| 21 | |
| 22 | #include <androidfw/ResourceTypes.h> |
| 23 | #include <memory> |
| 24 | #include <string> |
| 25 | #include <vector> |
| 26 | |
| 27 | namespace aapt { |
| 28 | |
| 29 | /** |
| 30 | * Wraps a ResTable into the canonical XmlPullParser interface. |
| 31 | */ |
| 32 | class BinaryXmlPullParser : public XmlPullParser { |
| 33 | public: |
| 34 | BinaryXmlPullParser(const std::shared_ptr<android::ResXMLTree>& parser); |
| 35 | BinaryXmlPullParser(const BinaryXmlPullParser& rhs) = delete; |
| 36 | |
Adam Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 37 | Event getEvent() const override; |
| 38 | const std::string& getLastError() const override; |
| 39 | Event next() override; |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 40 | |
Adam Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 41 | const std::u16string& getComment() const override; |
| 42 | size_t getLineNumber() const override; |
| 43 | size_t getDepth() const override; |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 44 | |
Adam Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 45 | const std::u16string& getText() const override; |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 46 | |
Adam Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 47 | const std::u16string& getNamespacePrefix() const override; |
| 48 | const std::u16string& getNamespaceUri() const override; |
| 49 | bool applyPackageAlias(std::u16string* package, const std::u16string& defaultpackage) |
| 50 | const override; |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 51 | |
Adam Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 52 | const std::u16string& getElementNamespace() const override; |
| 53 | const std::u16string& getElementName() const override; |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 54 | |
Adam Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 55 | const_iterator beginAttributes() const override; |
| 56 | const_iterator endAttributes() const override; |
| 57 | size_t getAttributeCount() const override; |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 58 | |
| 59 | private: |
| 60 | void copyAttributes(); |
| 61 | |
| 62 | std::shared_ptr<android::ResXMLTree> mParser; |
| 63 | std::u16string mStr1; |
| 64 | std::u16string mStr2; |
| 65 | std::vector<Attribute> mAttributes; |
| 66 | Event mEvent; |
| 67 | bool mHasComment; |
| 68 | const std::u16string sEmpty; |
| 69 | const std::string sEmpty8; |
| 70 | size_t mDepth; |
Adam Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 71 | std::vector<std::pair<std::u16string, std::u16string>> mPackageAliases; |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | } // namespace aapt |
| 75 | |
| 76 | #endif // AAPT_BINARY_XML_PULL_PARSER_H |