blob: 16fc8b7f700127dc8ae11fcd79d3b6abc016d0b0 [file] [log] [blame]
Adam Lesinski769de982015-04-10 19:43:55 -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_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
27namespace aapt {
28
29/**
30 * Wraps a ResTable into the canonical XmlPullParser interface.
31 */
32class BinaryXmlPullParser : public XmlPullParser {
33public:
34 BinaryXmlPullParser(const std::shared_ptr<android::ResXMLTree>& parser);
35 BinaryXmlPullParser(const BinaryXmlPullParser& rhs) = delete;
36
Adam Lesinski24aad162015-04-24 19:19:30 -070037 Event getEvent() const override;
38 const std::string& getLastError() const override;
39 Event next() override;
Adam Lesinski769de982015-04-10 19:43:55 -070040
Adam Lesinski24aad162015-04-24 19:19:30 -070041 const std::u16string& getComment() const override;
42 size_t getLineNumber() const override;
43 size_t getDepth() const override;
Adam Lesinski769de982015-04-10 19:43:55 -070044
Adam Lesinski24aad162015-04-24 19:19:30 -070045 const std::u16string& getText() const override;
Adam Lesinski769de982015-04-10 19:43:55 -070046
Adam Lesinski24aad162015-04-24 19:19:30 -070047 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 Lesinski769de982015-04-10 19:43:55 -070051
Adam Lesinski24aad162015-04-24 19:19:30 -070052 const std::u16string& getElementNamespace() const override;
53 const std::u16string& getElementName() const override;
Adam Lesinski769de982015-04-10 19:43:55 -070054
Adam Lesinski24aad162015-04-24 19:19:30 -070055 const_iterator beginAttributes() const override;
56 const_iterator endAttributes() const override;
57 size_t getAttributeCount() const override;
Adam Lesinski769de982015-04-10 19:43:55 -070058
59private:
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 Lesinski24aad162015-04-24 19:19:30 -070071 std::vector<std::pair<std::u16string, std::u16string>> mPackageAliases;
Adam Lesinski769de982015-04-10 19:43:55 -070072};
73
74} // namespace aapt
75
76#endif // AAPT_BINARY_XML_PULL_PARSER_H