degate 0.1.1
GateTemplatePort.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 __GATETEMPLATEPORT_H__
00023 #define __GATETEMPLATEPORT_H__
00024 
00025 #include "LogicModelObjectBase.h"
00026 #include "Circle.h"
00027 #include "Point.h"
00028 
00029 namespace degate {
00030 
00031   /**
00032    * This class represents a port of a gate template.
00033    */
00034   class GateTemplatePort : public LogicModelObjectBase, public ColoredObject {
00035 
00036   public:
00037 
00038     /**
00039      * Enum to define type of ports.
00040      */
00041     enum PORT_TYPE {
00042       PORT_TYPE_UNDEFINED = 0,
00043       PORT_TYPE_IN = 1,
00044       PORT_TYPE_OUT = 2,
00045       PORT_TYPE_INOUT = 3
00046     };
00047 
00048   private:
00049 
00050     Point point;
00051     PORT_TYPE port_type;
00052 
00053     bool position_defined;
00054 
00055 
00056   public:
00057 
00058     /**
00059      * Create a template port.
00060      */
00061 
00062     GateTemplatePort(int _x, int _y, PORT_TYPE _port_type = PORT_TYPE_UNDEFINED) :
00063       point(_x, _y), port_type(_port_type), position_defined( true) {
00064     }
00065 
00066     /**
00067      * Create a template port.
00068      */
00069 
00070     GateTemplatePort(PORT_TYPE _port_type = PORT_TYPE_UNDEFINED) :
00071       point(0, 0), port_type(_port_type), position_defined(false) {
00072     }
00073 
00074 
00075     virtual ~GateTemplatePort() {}
00076 
00077     /**
00078      * Check if a position is defined for the port.
00079      */
00080 
00081     virtual bool is_position_defined() const { return position_defined; }
00082 
00083 
00084     /**
00085      * Set the port position within the gate template.
00086      * The position is in relative coordinates
00087      *   related to the left upper corner of the gate template.
00088      */
00089 
00090     virtual void set_point(Point p) {
00091       position_defined = true;
00092       point = p;
00093     }
00094 
00095     /**
00096      * Check if a port is of type input port or an in-out-port.
00097      */
00098 
00099     virtual bool is_inport() const { return port_type == PORT_TYPE_IN || is_inoutport(); }
00100 
00101     /**
00102      * Check if a port is of type output port or an in-out-port.
00103      */
00104 
00105     virtual bool is_outport() const { return port_type == PORT_TYPE_OUT || is_inoutport(); }
00106 
00107     /**
00108      * Check if a port is of type tristate.
00109      */
00110 
00111     virtual bool is_inoutport() const { return port_type == PORT_TYPE_INOUT; }
00112 
00113     /**
00114      * Check if a port is of type is undefined.
00115      */
00116 
00117     virtual bool has_undefined_port_type() const { return port_type == PORT_TYPE_UNDEFINED; }
00118 
00119     /**
00120      * Set the port type.
00121      */
00122 
00123     virtual void set_port_type(PORT_TYPE _port_type) { port_type = _port_type; }
00124 
00125     /**
00126      * Get the port type.
00127      */
00128 
00129     virtual PORT_TYPE get_port_type() const { return port_type; }
00130 
00131     /**
00132      * Get a human readable string, that describes the port type.
00133      * That is "in", "out" or "tristate".
00134      */
00135 
00136     virtual const std::string get_port_type_as_string() const {
00137       switch(port_type) {
00138       case PORT_TYPE_IN: return std::string("in");
00139       case PORT_TYPE_OUT: return std::string("out");
00140       case PORT_TYPE_INOUT: return std::string("inout");
00141 
00142       case PORT_TYPE_UNDEFINED:
00143       default: return std::string("undefined");
00144       }
00145     }
00146 
00147     /**
00148      * Get the port position within the gate template.
00149      * @return Returns the position in relative coordinates
00150      *   related to the left upper corner of the gate template.
00151      */
00152 
00153     virtual Point const& get_point() const { return point; }
00154 
00155     /**
00156      * Get the x position for a port.
00157      * @return Returns the postion relative to the left upper corner of
00158      *   the gate template.
00159      */
00160 
00161     virtual int get_x() const { return point.get_x(); }
00162 
00163     /**
00164      * Get the y position for a port.
00165      * @return Returns the postion relative to the left upper corner of
00166      *   the gate template.
00167      */
00168 
00169     virtual int get_y() const { return point.get_y(); }
00170 
00171 
00172     /**
00173      * Parse a port type type indicating string.
00174      * @exception DegateRuntimeException This exception is thrown if the string
00175      *   cannot be parsed.
00176      */
00177 
00178     static PORT_TYPE get_port_type_from_string(std::string const& port_type_str) {
00179 
00180       if(port_type_str == "undefined") return GateTemplatePort::PORT_TYPE_UNDEFINED;
00181       else if(port_type_str == "in") return  GateTemplatePort::PORT_TYPE_IN;
00182       else if(port_type_str == "out") return GateTemplatePort::PORT_TYPE_OUT;
00183       else if(port_type_str == "inout") return GateTemplatePort::PORT_TYPE_INOUT;
00184       else throw DegateRuntimeException("Can't parse port type.");
00185     }
00186 
00187   };
00188 
00189   typedef std::tr1::shared_ptr<GateTemplatePort> GateTemplatePort_shptr;
00190 
00191 }
00192 
00193 #endif