degate  0.1.2
RCVBlacklistExporter.cc
Go to the documentation of this file.
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 <degate.h>
00023 #include <RCVBlacklistExporter.h>
00024 #include <FileSystem.h>
00025 #include <ImageHelper.h>
00026 
00027 #include <sys/types.h>
00028 #include <sys/stat.h>
00029 #include <unistd.h>
00030 #include <errno.h>
00031 
00032 #include <string>
00033 #include <iostream>
00034 #include <sstream>
00035 #include <fstream>
00036 #include <stdexcept>
00037 #include <list>
00038 #include <memory>
00039 
00040 
00041 using namespace std;
00042 using namespace degate;
00043 
00044 void RCVBlacklistExporter::export_data(std::string const& filename,
00045                                        RCBase::container_type const& violations) {
00046 
00047   std::string directory = get_basedir(filename);
00048 
00049   try {
00050 
00051     xmlpp::Document doc;
00052 
00053     xmlpp::Element * root_elem = doc.create_root_node("rc-blacklist");
00054     assert(root_elem != NULL);
00055 
00056     BOOST_FOREACH(RCViolation_shptr rcv, violations) {
00057       add_rcv(root_elem, rcv);
00058     }
00059 
00060     doc.write_to_file_formatted(filename, "ISO-8859-1");
00061 
00062   }
00063   catch(const std::exception& ex) {
00064     std::cout << "Exception caught: " << ex.what() << std::endl;
00065     throw;
00066   }
00067 
00068 }
00069 
00070 void RCVBlacklistExporter::add_rcv(xmlpp::Element* root_elem,
00071                                     RCViolation_shptr rcv) {
00072 
00073   xmlpp::Element* rcv_elem = root_elem->add_child("rc-violation");
00074   if(rcv_elem == NULL) throw(std::runtime_error("Failed to create node."));
00075   
00076   
00077   PlacedLogicModelObject_shptr o = rcv->get_object();    
00078   object_id_t new_oid = oid_rewriter->get_new_object_id(o->get_object_id());
00079   
00080   rcv_elem->set_attribute("object-id", number_to_string<object_id_t>(new_oid));
00081   rcv_elem->set_attribute("rc-violation-class", rcv->get_rc_violation_class());
00082   rcv_elem->set_attribute("severity", rcv->get_severity_as_string());
00083   rcv_elem->set_attribute("description", rcv->get_problem_description());
00084 
00085 }
00086