PandA-2024.02
xml_element.hpp
Go to the documentation of this file.
1 /*
2  *
3  * _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
4  * _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
5  * _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
6  * _/ _/ _/ _/ _/ _/ _/ _/ _/
7  * _/ _/ _/ _/ _/ _/_/_/ _/ _/
8  *
9  * ***********************************************
10  * PandA Project
11  * URL: http://panda.dei.polimi.it
12  * Politecnico di Milano - DEIB
13  * System Architectures Group
14  * ***********************************************
15  * Copyright (C) 2004-2024 Politecnico di Milano
16  *
17  * This file is part of the PandA framework.
18  *
19  * The PandA framework is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
43 #ifndef XML_ELEMENT_HPP
44 #define XML_ELEMENT_HPP
45 
46 #include "refcount.hpp"
47 
48 #include "exceptions.hpp"
49 #include "xml_attribute.hpp"
50 #include "xml_node.hpp"
51 #include <string>
52 
59 
61 {
62  public:
66  explicit xml_element(const std::string& _name) : xml_child(_name)
67  {
68  }
69 
73  void print(std::ostream& os, bool formatted, simple_indent* pp) const override
74  {
75  THROW_ASSERT(pp, "Null indenter object: unexpected condition");
76  if(formatted)
77  {
78  (*pp)(os, "\n");
79  }
80  (*pp)(os, "<" + get_name());
81  if(has_attributes())
82  {
83  print_attributes(os);
84  }
85  if(has_child())
86  {
87  const char soc[2] = {STD_OPENING_CHAR, '\0'};
88  const char scc[2] = {STD_CLOSING_CHAR, '\0'};
89  (*pp)(os, ">");
90  if(formatted)
91  {
92  (*pp)(os, soc);
93  }
94  xml_child::print(os, formatted, pp);
95  if(formatted)
96  {
97  (*pp)(os, scc);
98  if(get_children().size() > 1 || !get_child_text())
99  {
100  (*pp)(os, "\n");
101  }
102  }
103  (*pp)(os, "</" + get_name() + ">");
104  }
105  else
106  {
107  (*pp)(os, "/>");
108  }
109  }
110 };
111 
112 #endif
bool has_attributes() const
xml_element(const std::string &_name)
constructor
Definition: xml_element.hpp:66
REF_FORWARD_DECL(xml_element)
exceptions managed by PandA
std::string get_name() const
Get the name of this node.
Definition: xml_node.hpp:132
bool has_child() const
Definition: xml_node.hpp:326
void print_attributes(std::ostream &os) const
Print the class.
void print(std::ostream &os, bool formatted, simple_indent *pp) const override
Print the class.
Definition: xml_element.hpp:73
#define STD_OPENING_CHAR
STD include.
Template definition of refcount.
Very simple pretty printer functor.
#define STD_CLOSING_CHAR
Special closing character used to close the current nested level.
xml_text_node * get_child_text()
Get the first child text content node.
Definition: xml_node.hpp:272
void print(std::ostream &os, bool formatted, simple_indent *pp) const override
Print the class.
Definition: xml_node.hpp:240
node_list const & get_children()
Obtain the list of child nodes.
Definition: xml_node.hpp:310
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...
Definition: exceptions.hpp:289

Generated on Mon Feb 12 2024 13:02:55 for PandA-2024.02 by doxygen 1.8.13