|
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 #include <degate.h> 00023 #include <GateLibrary.h> 00024 00025 using namespace degate; 00026 00027 GateLibrary::GateLibrary() { 00028 } 00029 00030 GateLibrary::~GateLibrary() { 00031 } 00032 00033 00034 void GateLibrary::remove_template(GateTemplate_shptr gate_template) { 00035 templates.erase(gate_template->get_object_id()); 00036 } 00037 00038 void GateLibrary::add_template(GateTemplate_shptr gate_template) { 00039 00040 if(gate_template == NULL) throw InvalidPointerException(); 00041 if(!gate_template->has_valid_object_id()) 00042 throw InvalidObjectIDException("Can't add a gate template to the gate library, " 00043 "if the template has no valid object ID."); 00044 else 00045 templates[gate_template->get_object_id()] = gate_template; 00046 } 00047 00048 bool GateLibrary::exists_template(object_id_t id) const { 00049 return templates.find(id) != templates.end(); 00050 } 00051 00052 00053 GateTemplate_shptr GateLibrary::get_template(object_id_t id) { 00054 00055 if(id == 0) 00056 throw InvalidObjectIDException("Error in get_template(): Can't lookup template with id == 0"); 00057 00058 template_iterator found = templates.find(id); 00059 if(found == templates.end()) { 00060 boost::format f("Error in get_template(): Can't lookup gate template with ID %1%"); 00061 f % id; 00062 throw CollectionLookupException(f.str()); 00063 } 00064 return found->second; 00065 } 00066 00067 00068 bool GateLibrary::is_name_in_use(std::string const & name) const { 00069 00070 for(const_template_iterator iter = begin(); iter != end(); ++iter) { 00071 if((*iter).second->has_name() && (*iter).second->get_name() == name) 00072 return true; 00073 } 00074 00075 return false; 00076 } 00077 00078 bool GateLibrary::exists_template_port(object_id_t port_id) { 00079 00080 for(template_iterator iter = begin(); iter != end(); ++iter) { 00081 00082 GateTemplate_shptr tmpl((*iter).second); 00083 00084 for(GateTemplate::port_iterator piter = tmpl->ports_begin(); 00085 piter != tmpl->ports_end(); 00086 piter++) { 00087 if((*piter)->get_object_id() == port_id) return true; 00088 } 00089 } 00090 00091 return false; 00092 } 00093 00094 00095 GateTemplatePort_shptr GateLibrary::get_template_port(object_id_t port_id) { 00096 00097 for(template_iterator iter = begin(); iter != end(); ++iter) { 00098 00099 GateTemplate_shptr tmpl((*iter).second); 00100 00101 for(GateTemplate::port_iterator piter = tmpl->ports_begin(); 00102 piter != tmpl->ports_end(); 00103 piter++) { 00104 if((*piter)->get_object_id() == port_id) return *piter; 00105 } 00106 } 00107 00108 std::ostringstream stm; 00109 stm << "There is no template port with ID. " << port_id << " in the gate library."; 00110 throw CollectionLookupException(stm.str()); 00111 } 00112 00113 GateLibrary::template_iterator GateLibrary::begin() { 00114 return templates.begin(); 00115 } 00116 00117 00118 GateLibrary::template_iterator GateLibrary::end() { 00119 return templates.end(); 00120 } 00121 00122 GateLibrary::const_template_iterator GateLibrary::begin() const { 00123 return templates.begin(); 00124 } 00125 00126 00127 GateLibrary::const_template_iterator GateLibrary::end() const { 00128 return templates.end(); 00129 } 00130 00131 00132 void GateLibrary::print(std::ostream & os) { 00133 for(template_iterator iter = begin(); iter != end(); ++iter) { 00134 GateTemplate_shptr tmpl = (*iter).second; 00135 00136 tmpl->print(os); 00137 os << std::endl; 00138 00139 } 00140 }
1.7.4