|
degate 0.1.1
|
00001 /* -*-c++-*- 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 #ifndef __DOTATTRIBUTES_H__ 00023 #define __DOTATTRIBUTES_H__ 00024 00025 #include "globals.h" 00026 00027 #include <string> 00028 #include <list> 00029 #include <map> 00030 #include <iostream> 00031 #include <fstream> 00032 #include <sstream> 00033 00034 namespace degate { 00035 00036 /** 00037 * Helper class to handle attributes for the dot language. 00038 * 00039 */ 00040 class DOTAttributes { 00041 private: 00042 00043 std::map<std::string, std::string> attributes; 00044 00045 public: 00046 00047 /** 00048 * The constructor. 00049 */ 00050 DOTAttributes() {}; 00051 00052 /** 00053 * The destructor, that destroys a DOTAttributes object. 00054 */ 00055 ~DOTAttributes() {}; 00056 00057 /** 00058 * Add a key/value attribute. 00059 * 00060 * If this method is called multiple times with the same 00061 * attribute name, the last value is accepted. 00062 * 00063 * The value string should not contain quotation marks. If it 00064 * has one, you should handle the escaping by yourself. 00065 * 00066 * @param attribute_name The attribute name as a string. 00067 * @param value The string value. You don't have to add opening and closing quotation marks. 00068 */ 00069 00070 void add(std::string const& attribute_name, std::string const& value); 00071 00072 00073 /** 00074 * Add a key/value attribute. 00075 * 00076 * If this method is called multiple times with the same 00077 * attribute name, the last value is accepted. 00078 * 00079 * @param attribute_name The attribute name as a string. 00080 * @param value The parameter value. 00081 */ 00082 template<typename T> 00083 void add_number(std::string const& attribute_name, T value) { 00084 std::ostringstream stm; 00085 stm << attribute_name << "=\"" << value << "\""; 00086 attributes[attribute_name] = stm.str(); 00087 } 00088 00089 00090 /** 00091 * Add a position attertribute. 00092 * 00093 * If this method is called multiple times with the same 00094 * attribute name, the last value is accepted. 00095 * 00096 * @param center_x The x-coordinate for the center. Value and unit 00097 * are the one from the dot coordinate system. 00098 * @param center_y The y-coordinate for the center. Value and unit 00099 * are the one from the dot coordinate system. 00100 * @param preserve_position A boolean value that indicates if positions 00101 * should be preserved. In the dot language this is expressed 00102 * with a '!' flag. 00103 * @see http://www.graphviz.org/doc/info/attrs.html#d:pos 00104 */ 00105 00106 void add_position(long center_x, long center_y, 00107 bool preserve_position = true); 00108 00109 00110 /** 00111 * Get the attributes as a string. 00112 * 00113 * @return Returns the dot attributes as a string, you can directly write into the dot file. 00114 * The string is of format [color="red",label="N3018",shape="box"], including the 00115 * squared brackets. 00116 */ 00117 00118 std::string get_string() const; 00119 00120 }; 00121 00122 } 00123 00124 #endif
1.7.4