blob: 9f1ff84080176369e1f8a5fe803f4a078d46eb02 [file] [log] [blame]
Adedeji Adebisi684ec912021-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;
Patrick Williamsf5c0b9d2023-03-14 09:31:01 -050028 XMLNode(const std::string& t) : tag(t) {}
Adedeji Adebisi684ec912021-07-22 18:07:52 +000029
30 void AddChild(XMLNode* x)
31 {
32 children.push_back(x);
33 }
34
35 void do_Print(int indent)
36 {
37 for (int i = 0; i < indent; i++)
38 printf(" ");
39 printf("%s", tag.c_str());
40 if (fields["name"] != "")
41 {
42 printf(" name=[%s]", fields["name"].c_str());
43 }
44 printf("\n");
45 for (XMLNode* ch : children)
46 {
47 ch->do_Print(indent + 1);
48 }
49 }
50
51 void Print()
52 {
53 do_Print(0);
54 }
55
56 void SetName(const std::string& n)
57 {
58 fields["name"] = n;
59 }
kuiyingdfb0cd92023-03-14 11:43:23 +080060
Adedeji Adebisi684ec912021-07-22 18:07:52 +000061 std::vector<std::string> GetChildNodeNames();
62 std::vector<std::string> GetInterfaceNames();
63};
64
65XMLNode* ParseXML(const std::string& sv);
66void DeleteTree(XMLNode* x);