PandA-2024.02
data_xml_parser.cpp
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  */
42 #include "data_xml_parser.hpp"
44 
46 #include "Parameter.hpp"
47 
50 #include "latex_table_xml.hpp"
51 
53 #include "exceptions.hpp"
54 #include "fileIO.hpp"
55 #include "string_manipulation.hpp" // for GET_CLASS
56 
58 #include "data_xml.hpp"
59 #include "polixml.hpp"
60 #include "xml_dom_parser.hpp"
61 #include "xml_helper.hpp"
62 
64  : debug_level(Param->get_class_debug_level(GET_CLASS(*this)))
65 {
66 }
67 
69 
72 {
73  try
74  {
75  for(const auto& file_name : file_names)
76  {
77  XMLDomParser parser(GetPath(file_name));
78  parser.Exec();
79  if(parser)
80  {
81  // Walk the tree:
82  const xml_element* root = parser.get_document()->get_root_node();
84  {
85  std::string benchmark_name;
86  if(!CE_XVM(benchmark_name, root))
87  {
88  THROW_ERROR("Name of benchmark not found in file " + file_name);
89  }
90  benchmark_name = root->get_attribute(STR_XML_data_xml_benchmark_name)->get_value();
91 
92  // Recurse through child nodes:
93  const auto& list = root->get_children();
94  xml_node::node_list::const_iterator child, child_end = list.end();
95  for(child = list.begin(); child != child_end; ++child)
96  {
97  const auto* child_element = GetPointer<const xml_element>(*child);
98  if(!child_element)
99  {
100  continue;
101  }
102  const std::string child_name = child_element->get_name();
103  const std::string value = child_element->get_attribute(STR_XML_data_xml_value)->get_value();
104  output[benchmark_name][child_name] = value;
105  }
106  }
107  }
108  }
109  }
110  catch(const char* msg)
111  {
112  THROW_ERROR("Error during parsing of data xml file: " + std::string(msg));
113  }
114  catch(const std::string& msg)
115  {
116  THROW_ERROR("Error during parsing of data xml file: " + msg);
117  }
118  catch(const std::exception& ex)
119  {
120  THROW_ERROR("Error during parsing of data xml file: " + std::string(ex.what()));
121  }
122  catch(...)
123  {
124  THROW_ERROR("Error during parsing of data xml file");
125  }
126 }
std::string get_value() const
Get the value of this attribute.
xml nodes used in file specifying latex table format
xml nodes for generic data xml files
#define GET_CLASS(obj)
Macro returning the actual type of an object.
CustomOrderedMap< T, U > CustomMap
Definition: custom_map.hpp:167
exceptions managed by PandA
#define CE_XVM(variable, node)
Check existence XML Value Macro. Check if an XML attribute is present in the XML tree.
Definition: xml_helper.hpp:88
void Parse(const CustomSet< std::string > &file_names, std::map< std::string, CustomMap< std::string, std::string >> &output) const
Parse xml file.
~DataXmlParser()
Destructor.
volatile int output[DIM_Y][DIM_X]
Definition: los.h:1
Auxiliary methods for manipulating string.
#define STR_XML_data_xml_benchmark_name
The benchmark name attribute.
Definition: data_xml.hpp:46
#define STR_XML_experimental_setup_root
The root node.
unsigned map[NUM_VERTICES]
Definition: bfs.c:12
std::string get_name() const
Get the name of this node.
Definition: xml_node.hpp:132
string benchmark_name
Definition: test_panda.py:828
XML DOM parser.
XML DOM parser.
utility function used to read files.
xml_attribute * get_attribute(const std::string &name) const
Obtain the attribute with this name.
void Exec()
Parse an XML document from a file.
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
Definition: exceptions.hpp:263
#define STR_XML_latex_table_root
The root node.
std::string GetPath(std::filesystem::path path)
Definition: fileIO.hpp:140
xml nodes used in file specifying experimental setup
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
xml_documentRef get_document()
Obtain the parsed document.
DataXmlParser(const ParameterConstRef &parameters)
Constructor.
this class is used to manage the command-line or XML options.
#define STR_XML_data_xml_value
The attribute containing the value of a node.
Definition: data_xml.hpp:49
Some macro used to interface with the XML library.
node_list const & get_children()
Obtain the list of child nodes.
Definition: xml_node.hpp:310
Parse xml file containing generic data.

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