blob: 3a76e9ae3e22a8d5a6ad70f1c4a7ebd48d55fd66 [file] [log] [blame]
Adedeji Adebisi12c5f112021-07-22 18:07:52 +00001// Copyright 2021 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <map>
18#include <string>
19#include <vector>
20
21class XMLNode
22{
23 public:
24 std::string tag;
25 std::map<std::string, std::string> fields;
26 std::vector<XMLNode*> children;
27 std::vector<XMLNode*> interfaces;
28 XMLNode(const std::string& t) : tag(t)
29 {}
30
31 void AddChild(XMLNode* x)
32 {
33 children.push_back(x);
34 }
35
36 void do_Print(int indent)
37 {
38 for (int i = 0; i < indent; i++)
39 printf(" ");
40 printf("%s", tag.c_str());
41 if (fields["name"] != "")
42 {
43 printf(" name=[%s]", fields["name"].c_str());
44 }
45 printf("\n");
46 for (XMLNode* ch : children)
47 {
48 ch->do_Print(indent + 1);
49 }
50 }
51
52 void Print()
53 {
54 do_Print(0);
55 }
56
57 void SetName(const std::string& n)
58 {
59 fields["name"] = n;
60 }
61
62 std::vector<std::string> GetChildNodeNames();
63 std::vector<std::string> GetInterfaceNames();
64};
65
66XMLNode* ParseXML(const std::string& sv);
67void DeleteTree(XMLNode* x);