blob: c892b0900cbfe80ee64b0ded9762c0053402a5c2 [file] [log] [blame]
Adam Lesinski4d3a9872015-04-09 19:53:22 -07001/*
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
26namespace aapt {
27
28class BindingXmlPullParser : public XmlPullParser {
29public:
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;
45
46 const std::u16string& getElementNamespace() const override;
47 const std::u16string& getElementName() const override;
48
49 const_iterator beginAttributes() const override;
50 const_iterator endAttributes() const override;
51 size_t getAttributeCount() const override;
52
53 bool writeToFile(std::ostream& out) const;
54
55private:
56 struct VarDecl {
57 std::string name;
58 std::string type;
59 };
60
61 struct Import {
62 std::string name;
63 std::string type;
64 };
65
66 struct Target {
67 std::string className;
68 std::string id;
69 int32_t tagId;
70
71 std::vector<XmlPullParser::Attribute> expressions;
72 };
73
74 bool readVariableDeclaration();
75 bool readExpressions();
76
77 std::shared_ptr<XmlPullParser> mParser;
78 std::string mLastError;
79 bool mOverride;
80 std::vector<XmlPullParser::Attribute> mAttributes;
81 std::vector<VarDecl> mVarDecls;
82 std::vector<Target> mTargets;
83 int32_t mNextTagId;
84};
85
86} // namespace aapt
87
88#endif // AAPT_BINDING_XML_PULL_PARSER_H