|
degate 0.1.1
|
00001 /* 00002 00003 This file is part of the IC reverse engineering tool degate. 00004 00005 Copyright 2008, 2009, 2010 by Martin Schobert 00006 00007 Degate is free software: you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation, either version 3 of the License, or 00010 any later version. 00011 00012 Degate is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with degate. If not, see <http://www.gnu.org/licenses/>. 00019 00020 */ 00021 00022 #include "DOTExporter.h" 00023 00024 #include <iostream> 00025 #include <fstream> 00026 00027 using namespace degate; 00028 00029 void DOTExporter::add_header_line(std::string header_line) { 00030 header_lines.push_back(std::string("# ") + header_line); 00031 } 00032 00033 void DOTExporter::add_graph_setting(std::string line) { 00034 graph_setting_lines.push_back(line); 00035 } 00036 00037 00038 void DOTExporter::add_node(std::string node_id, std::string node_params) { 00039 node_lines.push_back(node_id + node_params); 00040 } 00041 00042 00043 void DOTExporter::add_edge(std::string from_node_id, 00044 std::string to_node_id, 00045 std::string edge_params) { 00046 std::string txt(from_node_id); 00047 txt += std::string(" -- "); 00048 txt += to_node_id; 00049 txt += edge_params; 00050 edge_lines.push_back(txt); 00051 } 00052 00053 00054 void DOTExporter::dump_to_file(std::string const& filename) const { 00055 00056 std::ofstream dot_file; 00057 00058 dot_file.open(filename.c_str(), std::ios::trunc | std:: ios::out); 00059 00060 // write header 00061 00062 for(std::list<std::string>::const_iterator iter = header_lines.begin(); 00063 iter != header_lines.end(); ++iter) { 00064 dot_file << *iter << std::endl; 00065 } 00066 00067 dot_file << "graph LogicModel {" << std::endl; 00068 00069 for(std::list<std::string>::const_iterator iter = graph_setting_lines.begin(); 00070 iter != graph_setting_lines.end(); ++iter) { 00071 dot_file << "\t" << *iter << std::endl; 00072 } 00073 00074 00075 // nodes 00076 for(std::list<std::string>::const_iterator iter = node_lines.begin(); 00077 iter != node_lines.end(); ++iter) 00078 dot_file << "\t" << *iter << std::endl; 00079 00080 // edges 00081 for(std::list<std::string>::const_iterator iter = edge_lines.begin(); 00082 iter != edge_lines.end(); ++iter) 00083 dot_file << "\t" << *iter << std::endl; 00084 00085 00086 dot_file << "}" << std::endl; 00087 00088 dot_file.close(); 00089 } 00090 00091 void DOTExporter::clear() { 00092 header_lines.clear(); 00093 graph_setting_lines.clear(); 00094 node_lines.clear(); 00095 edge_lines.clear(); 00096 }
1.7.4