blob: 8f714a2c5a3f9925249f4392f61bea12c992edcd [file] [log] [blame]
Eric Holk3cbf1762018-12-13 16:04:56 -08001/*
2 * Copyright (C) 2018 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#ifndef TINYXML_LAYOUT_PARSER_H_
17#define TINYXML_LAYOUT_PARSER_H_
18
19#include "tinyxml2.h"
20
21#include <codecvt>
22#include <locale>
23#include <string>
24
25namespace startop {
26
27template <typename Visitor>
28class TinyXmlVisitorAdapter : public tinyxml2::XMLVisitor {
29 public:
30 explicit TinyXmlVisitorAdapter(Visitor* visitor) : visitor_{visitor} {}
31
32 bool VisitEnter(const tinyxml2::XMLDocument& /*doc*/) override {
33 visitor_->VisitStartDocument();
34 return true;
35 }
36
37 bool VisitExit(const tinyxml2::XMLDocument& /*doc*/) override {
38 visitor_->VisitEndDocument();
39 return true;
40 }
41
42 bool VisitEnter(const tinyxml2::XMLElement& element,
43 const tinyxml2::XMLAttribute* /*firstAttribute*/) override {
44 visitor_->VisitStartTag(
45 std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}.from_bytes(
46 element.Name()));
47 return true;
48 }
49
50 bool VisitExit(const tinyxml2::XMLElement& /*element*/) override {
51 visitor_->VisitEndTag();
52 return true;
53 }
54
55 private:
56 Visitor* visitor_;
57};
58
59// Returns whether a layout resource represented by a TinyXML document is supported by the layout
60// compiler.
61bool CanCompileLayout(const tinyxml2::XMLDocument& xml, std::string* message = nullptr);
62
63} // namespace startop
64
65#endif // TINYXML_LAYOUT_PARSER_H_