degate  0.1.2
Exporter.h
Go to the documentation of this file.
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 __EXPORTER_H__
00023 #define __EXPORTER_H__
00024 
00025 #include "globals.h"
00026 #include "Image.h"
00027 
00028 #include <stdexcept>
00029 #include <sstream>
00030 
00031 namespace degate {
00032 
00033   /**
00034    * This is the  base class for exporter classes.
00035    */
00036   class Exporter {
00037 
00038   protected:
00039 
00040     /**
00041      * Convert a number type to a human readable string.
00042      */
00043     template<typename T> std::string number_to_string(T num) {
00044       std::ostringstream stm;
00045       stm << num;
00046       return stm.str();
00047     }
00048 
00049     /**
00050      * Convert a RGBA color value into the common format of "#%2x%2x%2x%2x".
00051      */
00052     std::string to_color_string(color_t col) const {
00053       char buf[100];
00054       snprintf(buf, sizeof(buf), "#%02X%02X%02X%02X",
00055                MASK_R(col),
00056                MASK_G(col),
00057                MASK_B(col),
00058                MASK_A(col));
00059       return std::string(buf);
00060     }
00061 
00062   public:
00063 
00064     /**
00065      * The ctor for an exporter object.
00066      */
00067     Exporter() {};
00068 
00069     /**
00070      * The dtor for an exporter object.
00071      */
00072     virtual ~Exporter() {};
00073   };
00074 
00075 }
00076 
00077 #endif