|
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 __PORTCOLORMANAGER_H__ 00023 #define __PORTCOLORMANAGER_H__ 00024 00025 #include <map> 00026 #include <tr1/memory> 00027 00028 namespace degate { 00029 00030 /** 00031 * The PortColorManager manages color definitions based on common port names. 00032 * 00033 * In degate you can define colors, which are used for the rendering. To 00034 * make gate ports of the same type drawn in the same color, you can store a 00035 * color specification in the PortColorManager. 00036 00037 */ 00038 00039 class PortColorManager { 00040 00041 public: 00042 typedef std::map<std::string /* port name */, std::pair<color_t, color_t> > port_color_collection; 00043 00044 private: 00045 00046 port_color_collection port_color_map; 00047 00048 00049 public: 00050 00051 /** 00052 * Construct a new port color manager. 00053 */ 00054 PortColorManager() {} 00055 00056 /** 00057 * Destroy the port color mananger. 00058 */ 00059 ~PortColorManager() {}; 00060 00061 /** 00062 * Add a new color definition. 00063 */ 00064 void set_color(std::string port_name, color_t frame_color_def, color_t fill_color_def) { 00065 port_color_map[port_name] = std::pair<color_t, color_t>(frame_color_def, fill_color_def); 00066 } 00067 00068 /** 00069 * Remove a color definition. 00070 */ 00071 void remove_color(std::string port_name) { 00072 port_color_map.erase(port_name); 00073 } 00074 00075 /** 00076 * Get a fill color definition. 00077 * @exception CollectionLookupException 00078 */ 00079 color_t get_fill_color(std::string const & port_name) const { 00080 const port_color_collection::const_iterator iter = port_color_map.find(port_name); 00081 if(iter != port_color_map.end()) { 00082 return (*iter).second.second; 00083 } 00084 else throw CollectionLookupException("Can't lookup fill color."); 00085 } 00086 00087 /** 00088 * Get a frame color definition. 00089 * @exception CollectionLookupException 00090 */ 00091 color_t get_frame_color(std::string const & port_name) const { 00092 const port_color_collection::const_iterator iter = port_color_map.find(port_name); 00093 if(iter != port_color_map.end()) { 00094 return (*iter).second.first; 00095 } 00096 else throw CollectionLookupException("Can't lookup frame color."); 00097 } 00098 00099 /** 00100 * Check if there exists a frame and fill color definition for a port name. 00101 */ 00102 bool has_color_definition(std::string const & port_name) const { 00103 const port_color_collection::const_iterator iter = port_color_map.find(port_name); 00104 return (iter != port_color_map.end()); 00105 } 00106 00107 00108 /** 00109 * Get an iterator to iterate over port color definitions. 00110 * @see end() 00111 */ 00112 port_color_collection::iterator begin() { 00113 return port_color_map.begin(); 00114 } 00115 00116 /** 00117 * Get an end iterator. 00118 * @see begin() 00119 */ 00120 port_color_collection::iterator end() { 00121 return port_color_map.end(); 00122 } 00123 00124 }; 00125 00126 /** 00127 * Typedef for a shared pointer on PortColorManager objects. 00128 */ 00129 typedef std::tr1::shared_ptr<PortColorManager> PortColorManager_shptr; 00130 } 00131 00132 #endif
1.7.4