Adedeji Adebisi | 684ec91 | 2021-07-22 18:07:52 +0000 | [diff] [blame] | 1 | // 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 | |
| 21 | class 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 Williams | f5c0b9d | 2023-03-14 09:31:01 -0500 | [diff] [blame] | 28 | XMLNode(const std::string& t) : tag(t) {} |
Adedeji Adebisi | 684ec91 | 2021-07-22 18:07:52 +0000 | [diff] [blame] | 29 | |
| 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 | } |
kuiying | dfb0cd9 | 2023-03-14 11:43:23 +0800 | [diff] [blame] | 60 | |
Adedeji Adebisi | 684ec91 | 2021-07-22 18:07:52 +0000 | [diff] [blame] | 61 | std::vector<std::string> GetChildNodeNames(); |
| 62 | std::vector<std::string> GetInterfaceNames(); |
| 63 | }; |
| 64 | |
| 65 | XMLNode* ParseXML(const std::string& sv); |
| 66 | void DeleteTree(XMLNode* x); |