Adam Lesinski | 4d3a987 | 2015-04-09 19:53:22 -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_BINDING_XML_PULL_PARSER_H |
| 18 | #define AAPT_BINDING_XML_PULL_PARSER_H |
| 19 | |
| 20 | #include "XmlPullParser.h" |
| 21 | |
| 22 | #include <iostream> |
| 23 | #include <memory> |
| 24 | #include <string> |
| 25 | |
| 26 | namespace aapt { |
| 27 | |
| 28 | class BindingXmlPullParser : public XmlPullParser { |
| 29 | public: |
| 30 | BindingXmlPullParser(const std::shared_ptr<XmlPullParser>& parser); |
| 31 | BindingXmlPullParser(const BindingXmlPullParser& rhs) = delete; |
| 32 | |
| 33 | Event getEvent() const override; |
| 34 | const std::string& getLastError() const override; |
| 35 | Event next() override; |
| 36 | |
| 37 | const std::u16string& getComment() const override; |
| 38 | size_t getLineNumber() const override; |
| 39 | size_t getDepth() const override; |
| 40 | |
| 41 | const std::u16string& getText() const override; |
| 42 | |
| 43 | const std::u16string& getNamespacePrefix() const override; |
| 44 | const std::u16string& getNamespaceUri() const override; |
Adam Lesinski | 24aad16 | 2015-04-24 19:19:30 -0700 | [diff] [blame] | 45 | bool applyPackageAlias(std::u16string* package, const std::u16string& defaultPackage) |
| 46 | const override; |
Adam Lesinski | 4d3a987 | 2015-04-09 19:53:22 -0700 | [diff] [blame] | 47 | |
| 48 | const std::u16string& getElementNamespace() const override; |
| 49 | const std::u16string& getElementName() const override; |
| 50 | |
| 51 | const_iterator beginAttributes() const override; |
| 52 | const_iterator endAttributes() const override; |
| 53 | size_t getAttributeCount() const override; |
| 54 | |
| 55 | bool writeToFile(std::ostream& out) const; |
| 56 | |
| 57 | private: |
| 58 | struct VarDecl { |
| 59 | std::string name; |
| 60 | std::string type; |
| 61 | }; |
| 62 | |
| 63 | struct Import { |
| 64 | std::string name; |
| 65 | std::string type; |
| 66 | }; |
| 67 | |
| 68 | struct Target { |
| 69 | std::string className; |
| 70 | std::string id; |
| 71 | int32_t tagId; |
| 72 | |
| 73 | std::vector<XmlPullParser::Attribute> expressions; |
| 74 | }; |
| 75 | |
| 76 | bool readVariableDeclaration(); |
| 77 | bool readExpressions(); |
| 78 | |
| 79 | std::shared_ptr<XmlPullParser> mParser; |
| 80 | std::string mLastError; |
| 81 | bool mOverride; |
| 82 | std::vector<XmlPullParser::Attribute> mAttributes; |
| 83 | std::vector<VarDecl> mVarDecls; |
| 84 | std::vector<Target> mTargets; |
| 85 | int32_t mNextTagId; |
| 86 | }; |
| 87 | |
| 88 | } // namespace aapt |
| 89 | |
| 90 | #endif // AAPT_BINDING_XML_PULL_PARSER_H |