|
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 __XMLIMPORTER_H__ 00023 #define __XMLIMPORTER_H__ 00024 00025 #include "globals.h" 00026 #include "Importer.h" 00027 00028 #include <libxml++/libxml++.h> 00029 00030 namespace degate { 00031 00032 class XMLImporter : public Importer { 00033 00034 protected: 00035 00036 using Importer::parse_number; 00037 00038 /** 00039 * Parse a string and convert it to a number (e.g. double, long, unsigned int, ...). 00040 * @exception InvalidPointerException is thrown, if you node is a NULL pointer. 00041 * @exception XMLAttributeMissingException The XML attribute is not present. 00042 * @return Returns the number in type T. 00043 */ 00044 template <typename T> 00045 T parse_number(const xmlpp::Element * const node, std::string const& attribute_str) const { 00046 00047 assert(node != NULL); 00048 if(node == NULL) throw InvalidPointerException("Parameter must be != NULL."); 00049 00050 if(node->get_attribute(attribute_str) == NULL) { 00051 throw XMLAttributeMissingException(std::string("attribute is not present: ") + attribute_str); 00052 } 00053 else return parse_number<T>(node->get_attribute_value(attribute_str)); 00054 } 00055 00056 /** 00057 * Parse a string and convert it to a number (e.g. double, long, unsigned int, ...). 00058 * @exception InvalidPointerException is thrown, if you node is a NULL pointer. 00059 * @return Returns the number in type T. If the XML attribute is not present, the default value is returned. 00060 */ 00061 00062 template <typename T> 00063 T parse_number(const xmlpp::Element * const node, std::string const& attribute_str, T default_value) { 00064 00065 assert(node != NULL); 00066 if(node == NULL) throw InvalidPointerException(); 00067 00068 if(node->get_attribute(attribute_str) == NULL) return default_value; 00069 else return parse_number<T>(node->get_attribute_value(attribute_str)); 00070 } 00071 00072 const xmlpp::Element * get_dom_twig(const xmlpp::Element * const start_node, std::string const & element_name) const; 00073 00074 /** 00075 * Parse a HTML RGBA color description, e.g. '#23FF42A0'. 00076 * @return Returns the internally used color code. If the string can't be parsed a value of 0 (black) is returned. 00077 */ 00078 color_t parse_color_string(std::string const& color_string) const; 00079 00080 00081 public: 00082 XMLImporter() {}; 00083 virtual ~XMLImporter() {}; 00084 00085 00086 }; 00087 00088 } 00089 00090 #endif
1.7.4