PandA-2024.02
structuralIO.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  */
44 #include "structuralIO.hpp"
45 
46 #include "Parameter.hpp" // for ParameterRef
47 #include "structural_manager.hpp" // for structural_managerRef, str...
48 #include "structural_objects.hpp" // for structural_type_descriptorRef
49 #include "xml_document.hpp" // for xml_document
50 #include "xml_dom_parser.hpp" // for XMLDomParser
51 #include <iostream> // for operator<<, endl, basic_os...
52 #include <string> // for operator<<, string, char_t...
53 
54 structural_managerRef read_structural_File(const std::string& fn, const ParameterRef& Param)
55 {
56  try
57  {
59  XMLDomParser parser(fn);
60  parser.Exec();
61  if(parser)
62  {
63  // Walk the tree:
67  CM->set_top_info("BUILD", build_type);
68  const xml_element* node = parser.get_document()->get_root_node(); // deleted by DomParser.
69  structural_manager::xload(node, CM);
70  }
71  return CM;
72  }
73  catch(const char* msg)
74  {
75  std::cerr << msg << std::endl;
76  }
77  catch(const std::string& msg)
78  {
79  std::cerr << msg << std::endl;
80  }
81  catch(const std::exception& ex)
82  {
83  std::cout << "Exception caught: " << ex.what() << std::endl;
84  }
85  catch(...)
86  {
87  std::cerr << "unknown exception" << std::endl;
88  }
89  return structural_managerRef();
90 }
91 
92 void write_structural_File(const std::string& f, structural_managerRef const& CM)
93 {
94  try
95  {
96  xml_document document;
97  xml_element* nodeRoot = document.create_root_node("circuit");
98  CM->xwrite(nodeRoot);
99  document.write_to_file_formatted(f);
100  }
101  catch(const char* msg)
102  {
103  std::cerr << msg << std::endl;
104  }
105  catch(const std::string& msg)
106  {
107  std::cerr << msg << std::endl;
108  }
109  catch(const std::exception& ex)
110  {
111  std::cout << "Exception caught: " << ex.what() << std::endl;
112  }
113  catch(...)
114  {
115  std::cerr << "unknown exception" << std::endl;
116  }
117 }
static void xload(const xml_element *node, structural_managerRef const &CM)
Load a structural manager from an xml file.
refcount< structural_type_descriptor > structural_type_descriptorRef
RefCount type definition of the structural_type_descriptor class structure.
Structure representing the most relevant information about the type of a structural object...
structural_managerRef read_structural_File(const std::string &fn, const ParameterRef &Param)
Read an xml file describing the structural data structures.
This class manages the circuit structures.
void set_top_info(const std::string &id, const technology_managerRef &LM, const std::string &Library="")
void write_to_file_formatted(const std::filesystem::path &filename)
Write the document to a file.
xml_element * create_root_node(const std::string &_name)
Creates the root node.
XML DOM parser.
XML DOM parser.
void Exec()
Parse an XML document from a file.
refcount< structural_manager > structural_managerRef
RefCount type definition of the structural_manager class structure.
void write_structural_File(const std::string &f, structural_managerRef const &CM)
Write an xml file describing the structural data structures.
This class describes all classes used to represent a structural object.
xml_documentRef get_document()
Obtain the parsed document.
this class is used to manage the command-line or XML options.
Class implementation of the structural_manager.
Input and output functions used to read and write the structural data structures. ...
void xwrite(xml_element *rootnode, const technology_nodeRef &tn=technology_nodeRef()) const
Add a component to an xml tree.

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