degate  0.1.2
RCVBlacklistImporter.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 <RCVBlacklistImporter.h>
00024 #include <ImageHelper.h>
00025 
00026 #include <sys/types.h>
00027 #include <sys/stat.h>
00028 #include <unistd.h>
00029 #include <errno.h>
00030 
00031 #include <string>
00032 #include <iostream>
00033 #include <fstream>
00034 #include <sstream>
00035 #include <stdexcept>
00036 #include <list>
00037 #include <memory>
00038 
00039 using namespace std;
00040 using namespace degate;
00041 
00042 void RCVBlacklistImporter::import_into(std::string const& filename,
00043                                   RCBase::container_type & blacklist) {
00044 
00045   if(RET_IS_NOT_OK(check_file(filename))) {
00046     debug(TM, "Problem: file %s not found.", filename.c_str());
00047     throw InvalidPathException("Can't load gate library from file.");
00048   }
00049   
00050   std::string directory = get_basedir(filename);
00051 
00052   try {
00053 
00054     xmlpp::DomParser parser;
00055     parser.set_substitute_entities(); // We just want the text to be resolved/unescaped automatically.
00056 
00057     parser.parse_file(filename);
00058     assert(parser == true);
00059 
00060     const xmlpp::Document * doc = parser.get_document();
00061     assert(doc != NULL);
00062 
00063     const xmlpp::Element * root_elem = doc->get_root_node(); // deleted by DomParser
00064     assert(root_elem != NULL);
00065 
00066     parse_list(root_elem, blacklist);
00067 
00068   }
00069   catch(const std::exception& ex) {
00070     std::cout << "Exception caught: " << ex.what() << std::endl;
00071     throw;
00072   }
00073 
00074 
00075 
00076 }
00077 
00078 
00079 void RCVBlacklistImporter::parse_list(const xmlpp::Element * const elem,
00080                                       RCBase::container_type & blacklist) {
00081 
00082   const xmlpp::Node::NodeList rcv_list = elem->get_children("rc-violation");
00083   for(xmlpp::Node::NodeList::const_iterator iter = rcv_list.begin();
00084       iter != rcv_list.end(); ++iter) {
00085 
00086     if(const xmlpp::Element* e = dynamic_cast<const xmlpp::Element*>(*iter)) {
00087 
00088       object_id_t object_id = parse_number<object_id_t>(e, "object-id");
00089 
00090       const Glib::ustring rcv_class(e->get_attribute_value("rc-violation-class"));
00091       const Glib::ustring description(e->get_attribute_value("description"));
00092       const Glib::ustring severity(e->get_attribute_value("severity"));
00093 
00094       RCViolation_shptr rcv(new RCViolation(_lmodel->get_object(object_id),
00095                                             description,
00096                                             rcv_class,
00097                                             RCViolation::get_severity_from_string(severity)));
00098       
00099       blacklist.push_back(rcv);
00100     }
00101   }
00102 }
00103