degate  0.1.2
XMLImporter.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 "XMLImporter.h"
00023 #include "Image.h"
00024 
00025 #include <sys/types.h>
00026 #include <sys/stat.h>
00027 #include <unistd.h>
00028 #include <errno.h>
00029 
00030 #include <string>
00031 #include <iostream>
00032 #include <sstream>
00033 #include <stdexcept>
00034 #include <list>
00035 
00036 using namespace degate;
00037 
00038 const xmlpp::Element * XMLImporter::get_dom_twig(const xmlpp::Element * const start_node, std::string const & element_name) const {
00039   xmlpp::Node::NodeList node_list = start_node->get_children(element_name);
00040   if(!node_list.empty()) {
00041     const xmlpp::Element * element = dynamic_cast<const xmlpp::Element*>(node_list.front());
00042     return element;
00043   }
00044   return NULL;
00045 }
00046 
00047 
00048 color_t XMLImporter::parse_color_string(std::string const& color_string) const {
00049   const unsigned int correct_length = 1 + 4 * 2;
00050   if(color_string.size() != correct_length) return 0;
00051 
00052   int r = 0;
00053   int g = 0;
00054   int b = 0;
00055   int a = 0;
00056 
00057   std::istringstream iss_r(color_string.substr(1, 2));
00058   std::istringstream iss_g(color_string.substr(3, 2));
00059   std::istringstream iss_b(color_string.substr(5, 2));
00060   std::istringstream iss_a(color_string.substr(7, 2));
00061 
00062   iss_r >> std::hex >> r;
00063   iss_g >> std::hex >> g;
00064   iss_b >> std::hex >> b;
00065   iss_a >> std::hex >> a;
00066 
00067   return MERGE_CHANNELS(r,g,b,a);
00068 }