degate  0.1.2
Public Types | Public Member Functions | Private Attributes
degate::Gate Class Reference

The class Gate defines and implements a physically placed gate. More...

#include <Gate.h>

Inheritance diagram for degate::Gate:
Inheritance graph
[legend]

List of all members.

Public Types

enum  ORIENTATION {
  ORIENTATION_UNDEFINED = 0,
  ORIENTATION_NORMAL = 1,
  ORIENTATION_FLIPPED_UP_DOWN = 2,
  ORIENTATION_FLIPPED_LEFT_RIGHT = 3,
  ORIENTATION_FLIPPED_BOTH = 4
}
typedef std::set
< GatePort_shptr, LMOCompare >
::iterator 
port_iterator
typedef std::set
< GatePort_shptr, LMOCompare >
::const_iterator 
port_const_iterator

Public Member Functions

 Gate (int _min_x, int _max_x, int _min_y, int _max_y, ORIENTATION _orientation=ORIENTATION_UNDEFINED)
 Create a gate.
 Gate (BoundingBox const &bounding_box, ORIENTATION _orientation=ORIENTATION_UNDEFINED)
 Create a gate.
virtual ~Gate ()
 Destroy a gate.
virtual void add_port (GatePort_shptr gate_port)
 Add a gate port.
virtual void remove_port (GatePort_shptr gate_port)
 Remove a gate port.
virtual GatePort_shptr get_port_by_template_port (GateTemplatePort_shptr template_port)
 Get a gate port by a template port.
virtual void set_template_type_id (object_id_t template_type_id)
 Set the ID of the corresponding template.
virtual object_id_t get_template_type_id () const
 Get the ID of the corresponding template.
virtual void set_gate_template (std::shared_ptr< GateTemplate > gate_template)
 A gate usually has a gate template.
virtual std::shared_ptr
< GateTemplate
get_gate_template () const
 Get the gate template.
virtual bool has_template () const
 Check if the gate has a template type set.
virtual void remove_template ()
 Remove template from gate.
virtual bool has_template_port (GateTemplatePort_shptr template_port) const
 Check if a gate object has a port, that references a given template port.
virtual void set_orientation (ORIENTATION _orientation)
 If a physically placed gate has a template.
virtual ORIENTATION get_orientation () const
 Get the orientation relative to the master image.
bool has_orientation () const
 Check if the gate has a valid orientation.
virtual std::string get_orienation_type_as_string () const
 Get the orientation as a human readable string.
virtual port_iterator ports_begin ()
 Get an iterator to iterated over ports.
virtual port_const_iterator ports_begin () const
 Get an iterator to iterated over ports.
virtual port_iterator ports_end ()
 Get an end iterator.
virtual port_const_iterator ports_end () const
 Get an end iterator.
virtual unsigned int get_relative_x_position_within_gate (int rel_x) const
 Get the x-coordinate relative to min_x depending on the gate's orientation.
virtual unsigned int get_relative_y_position_within_gate (int rel_y) const
 Get the y-coordinate relative to min_y depending on the gate's orientation.
virtual const std::string get_descriptive_identifier () const
 Get a human readable string that describes the whole logic model object.
virtual const std::string get_object_type_name () const
 Get a human readable string that names the object type.
void print (std::ostream &os=std::cout, int n_tabs=0) const
 Print gate.
bool in_shape (int x, int y, int max_distance=0) const
 Check in the Point with coordinates x and y is within the area of the shape.
void shift_x (int delta_x)
 Shift the shape vertically.
void shift_y (int delta_y)
 Shift the shape horizontally.
virtual bool in_bounding_box (BoundingBox const &bbox) const
 Check, if this rectangle is in the bounding box.
virtual BoundingBox const & get_bounding_box () const
 Get the bounding box.
DeepCopyable_shptr cloneShallow () const
 Return a copy of this object, but with all references to other DeepCopyables cleared (e.g.
void cloneDeepInto (DeepCopyable_shptr destination, oldnew_t *oldnew) const
 Deep-copy all members to destination.

Private Attributes

GateTemplate_shptr gate_template
std::set< GatePort_shptr,
LMOCompare
gate_ports
ORIENTATION orientation
object_id_t template_type_id

Detailed Description

The class Gate defines and implements a physically placed gate.

Todo:
The template type id makes only sense, if ports have the same thing with template ports. Maybe removing this is an option, because there are easier ways to reload the gate library.

Definition at line 47 of file Gate.h.


Member Typedef Documentation

typedef std::set< GatePort_shptr, LMOCompare >::const_iterator degate::Gate::port_const_iterator

Definition at line 60 of file Gate.h.

typedef std::set< GatePort_shptr, LMOCompare >::iterator degate::Gate::port_iterator

Definition at line 59 of file Gate.h.


Member Enumeration Documentation

Enumerator:
ORIENTATION_UNDEFINED 
ORIENTATION_NORMAL 
ORIENTATION_FLIPPED_UP_DOWN 
ORIENTATION_FLIPPED_LEFT_RIGHT 
ORIENTATION_FLIPPED_BOTH 

Definition at line 51 of file Gate.h.


Constructor & Destructor Documentation

Gate::Gate ( int  _min_x,
int  _max_x,
int  _min_y,
int  _max_y,
ORIENTATION  _orientation = ORIENTATION_UNDEFINED 
)

Create a gate.

Definition at line 30 of file Gate.cc.

                                     :
  Rectangle(_min_x, _max_x, _min_y, _max_y),
  orientation(_orientation),
  template_type_id(0) {
}
Gate::Gate ( BoundingBox const &  bounding_box,
ORIENTATION  _orientation = ORIENTATION_UNDEFINED 
)

Create a gate.

Definition at line 37 of file Gate.cc.

Gate::~Gate ( ) [virtual]

Destroy a gate.

Definition at line 45 of file Gate.cc.

References debug(), gate_template, remove_template(), and TM.

            {
  debug(TM, "destroy gate");
  if(gate_template != NULL) remove_template();
}

Here is the call graph for this function:


Member Function Documentation

void Gate::add_port ( GatePort_shptr  gate_port) [virtual]

Add a gate port.

If you add a gate port to a gate you have to make some changes to the logic model. Please call method LogicModel::update_ports()

Exceptions:
InvalidObjectIDExceptionThis exception is thrown, if the port has no valid object ID.
DegateLogicExceptionIs thrown if gate_port has no valid GateTemplatePort or if the gate has no valid orientation.
See also:
LogicModel::update_ports()

Definition at line 70 of file Gate.cc.

References gate_ports, degate::Rectangle::get_min_x(), degate::Rectangle::get_min_y(), get_relative_x_position_within_gate(), get_relative_y_position_within_gate(), and has_orientation().

                                            {
  if(!gate_port->has_valid_object_id())
    throw InvalidObjectIDException("Error in Gate::add_port(). "
                                   "The port has no valid object ID.");

  if(!gate_port->has_template_port())
    throw DegateLogicException("Error in Gate::add_port(). "
                               "The gate port has no template port");

  if(!has_orientation())
    throw DegateLogicException("Error in Gate::add_port(). "
                               "The gate has no defined orientation");

  gate_port->set_x(get_min_x() +
                   get_relative_x_position_within_gate
                     (gate_port->get_template_port()->get_x()));
  gate_port->set_y(get_min_y() +
                   get_relative_y_position_within_gate
                     (gate_port->get_template_port()->get_y()));

  gate_ports.insert(gate_port);
}

Here is the call graph for this function:

void Gate::cloneDeepInto ( DeepCopyable_shptr  destination,
oldnew_t oldnew 
) const [virtual]

Deep-copy all members to destination.

Todo:
Find out whether the default assignment operator can be used to simplify implementations of this method.

Reimplemented from degate::PlacedLogicModelObject.

Definition at line 56 of file Gate.cc.

References gate_ports, and gate_template.

                                                                        {
  auto clone = std::dynamic_pointer_cast<Gate>(dest);
  
  PlacedLogicModelObject::cloneDeepInto(clone, oldnew);
  Rectangle::cloneDeepInto(clone, oldnew);
  
  if (gate_template.get() != 0) {
    clone->gate_template = std::dynamic_pointer_cast<GateTemplate>(gate_template->cloneDeep(oldnew));
  }
  std::for_each(gate_ports.begin(), gate_ports.end(), [&](const GatePort_shptr &d) {
    clone->gate_ports.insert(std::dynamic_pointer_cast<GatePort>(d->cloneDeep(oldnew)));
  });
}

Return a copy of this object, but with all references to other DeepCopyables cleared (e.g.

set to 0-pointer).

Implements degate::DeepCopyable.

Definition at line 50 of file Gate.cc.

References get_bounding_box(), orientation, and template_type_id.

                                            {
  auto clone = std::make_shared<Gate>(get_bounding_box(), orientation);
  clone->template_type_id = template_type_id;
  return clone;
}

Here is the call graph for this function:

virtual BoundingBox const& degate::Gate::get_bounding_box ( ) const [inline, virtual]

Get the bounding box.

Reimplemented from degate::Rectangle.

Definition at line 321 of file Gate.h.

Referenced by cloneShallow(), and print().

Here is the caller graph for this function:

const std::string Gate::get_descriptive_identifier ( ) const [virtual]

Get a human readable string that describes the whole logic model object.

The string should be unique in order to let the user identify the concrete object. But that is not a must.

Reimplemented from degate::LogicModelObjectBase.

Definition at line 264 of file Gate.cc.

References get_gate_template(), degate::LogicModelObjectBase::get_name(), degate::LogicModelObjectBase::get_object_id(), degate::LogicModelObjectBase::has_name(), and has_template().

                                                       {

  if(has_template()) {
    if(has_name()) {
      boost::format fmter("%1% : %2%");
      fmter % get_name() % get_gate_template()->get_name();
      return fmter.str();
    }
    else {
      boost::format fmter("%1% (%2%)");
      fmter % get_gate_template()->get_name() % get_object_id();
      return fmter.str();
    }
  }
  else {
    if(!has_name()) {
      boost::format fmter("gate (%1%)");
      fmter % get_object_id();
      return fmter.str();
    }
    else {
      boost::format fmter("gate %1% (%2%)");
      fmter % get_name() % get_object_id();
      return fmter.str();
    }
  }

}

Here is the call graph for this function:

std::shared_ptr< GateTemplate > Gate::get_gate_template ( ) const [virtual]

Get the gate template.

See also:
set_gate_template()

Definition at line 146 of file Gate.cc.

References gate_template.

Referenced by get_descriptive_identifier().

                                                          {
  return gate_template;
}

Here is the caller graph for this function:

const std::string Gate::get_object_type_name ( ) const [virtual]

Get a human readable string that names the object type.

Here it is "Gate".

Reimplemented from degate::LogicModelObjectBase.

Definition at line 294 of file Gate.cc.

                                                 {
  return std::string("Gate");
}
std::string Gate::get_orienation_type_as_string ( ) const [virtual]

Get the orientation as a human readable string.

Definition at line 203 of file Gate.cc.

References orientation, ORIENTATION_FLIPPED_BOTH, ORIENTATION_FLIPPED_LEFT_RIGHT, ORIENTATION_FLIPPED_UP_DOWN, ORIENTATION_NORMAL, and ORIENTATION_UNDEFINED.

                                                    {
  switch(orientation) {
  case ORIENTATION_NORMAL: return std::string("normal");
  case ORIENTATION_FLIPPED_UP_DOWN: return std::string("flipped-up-down");
  case ORIENTATION_FLIPPED_LEFT_RIGHT: return std::string("flipped-left-right");
  case ORIENTATION_FLIPPED_BOTH: return std::string("flipped-both");
  case ORIENTATION_UNDEFINED:
  default: return std::string("undefined");
  }
}

Get the orientation relative to the master image.

Definition at line 195 of file Gate.cc.

References orientation.

                                            {
  return orientation;
}

Get a gate port by a template port.

Definition at line 103 of file Gate.cc.

References ports_begin(), and ports_end().

                                                                                   {
  for(port_iterator piter = ports_begin(); piter != ports_end(); ++piter) {
    GatePort_shptr gate_port = *piter;
    GateTemplatePort_shptr tmpl_port = gate_port->get_template_port();
    if(tmpl_port == template_port)
      return gate_port;
  }
  throw CollectionLookupException();
}

Here is the call graph for this function:

unsigned int Gate::get_relative_x_position_within_gate ( int  rel_x) const [virtual]

Get the x-coordinate relative to min_x depending on the gate's orientation.

Parameters:
rel_xThe x-coordinate realtive to min_x.
Exceptions:
DegateRuntimeExceptionThis exception is thrown if the object has an undefined gate orientation.
See also:
has_orientation()

Definition at line 232 of file Gate.cc.

References degate::Rectangle::get_width(), orientation, ORIENTATION_FLIPPED_BOTH, ORIENTATION_FLIPPED_LEFT_RIGHT, ORIENTATION_FLIPPED_UP_DOWN, ORIENTATION_NORMAL, and ORIENTATION_UNDEFINED.

Referenced by add_port().

                                                                      {
  switch(orientation) {
  case ORIENTATION_NORMAL:
  case ORIENTATION_FLIPPED_UP_DOWN:
    return rel_x;
  case ORIENTATION_FLIPPED_LEFT_RIGHT:
  case ORIENTATION_FLIPPED_BOTH:
    return get_width() - rel_x;
  case ORIENTATION_UNDEFINED:
  default:
    assert(orientation != ORIENTATION_UNDEFINED);
    throw DegateRuntimeException("Can't calculate a position for an undefined orientation");
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int Gate::get_relative_y_position_within_gate ( int  rel_y) const [virtual]

Get the y-coordinate relative to min_y depending on the gate's orientation.

Parameters:
rel_yThe y-coordinate realtive to min_y.
Exceptions:
DegateRuntimeExceptionThis exception is thrown if the object has an undefined gate orientation.
See also:
has_orientation()

Definition at line 248 of file Gate.cc.

References degate::Rectangle::get_height(), orientation, ORIENTATION_FLIPPED_BOTH, ORIENTATION_FLIPPED_LEFT_RIGHT, ORIENTATION_FLIPPED_UP_DOWN, ORIENTATION_NORMAL, and ORIENTATION_UNDEFINED.

Referenced by add_port().

                                                                      {
  switch(orientation) {
  case ORIENTATION_NORMAL:
  case ORIENTATION_FLIPPED_LEFT_RIGHT:
    return rel_y;
  case ORIENTATION_FLIPPED_UP_DOWN:
  case ORIENTATION_FLIPPED_BOTH:
    return get_height() - rel_y;
  case ORIENTATION_UNDEFINED:
  default:
    assert(orientation != ORIENTATION_UNDEFINED);
    throw DegateRuntimeException("Can't calculate a position for an undefined orientation");
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Get the ID of the corresponding template.

See also:
set_template_type_id()

Definition at line 119 of file Gate.cc.

References template_type_id.

                                             {
  return template_type_id;
}
bool Gate::has_orientation ( ) const

Check if the gate has a valid orientation.

Definition at line 199 of file Gate.cc.

References orientation, and ORIENTATION_UNDEFINED.

Referenced by add_port().

Here is the caller graph for this function:

bool Gate::has_template ( ) const [virtual]

Check if the gate has a template type set.

Returns:
Returns true, if there is a template for this gate. A template is present, if the gate has a shared pointer to the template. That is that there is a object you can work with. Just having a template ID is not sufficient. If there is no shared pointer to the template, false is returned.

Definition at line 150 of file Gate.cc.

References gate_template.

Referenced by get_descriptive_identifier(), remove_template(), and set_gate_template().

                              {
  return gate_template != NULL;
}

Here is the caller graph for this function:

bool Gate::has_template_port ( GateTemplatePort_shptr  template_port) const [virtual]

Check if a gate object has a port, that references a given template port.

This method bases on shared pointers not on simple port IDs.

Definition at line 166 of file Gate.cc.

References ports_begin(), and ports_end().

                                                                       {
  for(port_iterator piter = ports_begin(); piter != ports_end(); ++piter) {
    GatePort_shptr gate_port = *piter;

    assert(gate_port->get_template_port()->has_valid_object_id());
    assert(template_port->has_valid_object_id());

    if(gate_port->get_template_port()->get_object_id() == template_port->get_object_id()) {

      // debugging
      if(gate_port->get_template_port() != template_port) {
        std::cout << "ERROR\n";
        gate_port->print();
      }
      // debugging
      //assert(gate_port->get_template_port() == template_port);

      return true;
    }

  }
  return false;
}

Here is the call graph for this function:

virtual bool degate::Gate::in_bounding_box ( BoundingBox const &  bbox) const [inline, virtual]

Check, if this rectangle is in the bounding box.

Reimplemented from degate::Rectangle.

Definition at line 317 of file Gate.h.

                                                                {
      return Rectangle::in_bounding_box(bbox);
    }
bool degate::Gate::in_shape ( int  x,
int  y,
int  max_distance = 0 
) const [inline, virtual]

Check in the Point with coordinates x and y is within the area of the shape.

Reimplemented from degate::Rectangle.

Definition at line 304 of file Gate.h.

                                                            {
      return Rectangle::in_shape(x, y, max_distance);
    }

Get an iterator to iterated over ports.

Definition at line 215 of file Gate.cc.

References gate_ports.

Referenced by get_port_by_template_port(), has_template_port(), and print().

                                    {
  return gate_ports.begin();
}

Here is the caller graph for this function:

Get an iterator to iterated over ports.

Definition at line 219 of file Gate.cc.

References gate_ports.

                                                {
  return gate_ports.begin();
}

Get an end iterator.

See also:
ports_begin()

Definition at line 223 of file Gate.cc.

References gate_ports.

Referenced by get_port_by_template_port(), has_template_port(), and print().

                                  {
  return gate_ports.end();
}

Here is the caller graph for this function:

Get an end iterator.

See also:
ports_begin()

Definition at line 227 of file Gate.cc.

References gate_ports.

                                              {
  return gate_ports.end();
}
void Gate::print ( std::ostream &  os = std::cout,
int  n_tabs = 0 
) const [virtual]

Print gate.

Implements degate::PlacedLogicModelObject.

Definition at line 298 of file Gate.cc.

References degate::gen_tabs(), get_bounding_box(), degate::LogicModelObjectBase::get_description(), degate::LogicModelObjectBase::get_name(), degate::LogicModelObjectBase::get_object_id(), ports_begin(), ports_end(), and degate::BoundingBox::to_string().

                                                  {

  os
    << gen_tabs(n_tabs) << "Gate name        : " << get_name() << std::endl
    << gen_tabs(n_tabs) << "Gate description : " << get_description() << std::endl
    << gen_tabs(n_tabs) << "Object ID        : " << get_object_id() << std::endl
    << gen_tabs(n_tabs) << "Bounding box     : " << Rectangle::get_bounding_box().to_string() << std::endl
    << std::endl;

  for(port_const_iterator pi = ports_begin(); pi != ports_end(); ++pi) {
    const GatePort_shptr gate_port = *pi;
    gate_port->print(os, n_tabs + 1);
    os << std::endl;
  }

  os << std::endl;
}

Here is the call graph for this function:

void Gate::remove_port ( GatePort_shptr  gate_port) [virtual]

Remove a gate port.

add_port()

See also:
LogicModel::update_ports()

Definition at line 94 of file Gate.cc.

References gate_ports.

                                               {
  port_iterator found = gate_ports.find(gate_port);
  if(found != gate_ports.end()) {
    gate_ports.erase(found);
  }
  else throw CollectionLookupException();
}
void Gate::remove_template ( ) [virtual]

Remove template from gate.

This will destroy all gate ports, too.

Definition at line 154 of file Gate.cc.

References gate_ports, gate_template, has_template(), orientation, ORIENTATION_UNDEFINED, degate::ColoredObject::set_fill_color(), degate::ColoredObject::set_frame_color(), and template_type_id.

Referenced by ~Gate().

                           {
  gate_ports.clear();
  orientation = ORIENTATION_UNDEFINED;
  template_type_id = 0;
  set_fill_color(0);
  set_frame_color(0);
  if(has_template()) {
    gate_template->decrement_reference_counter();
    gate_template.reset();
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Gate::set_gate_template ( std::shared_ptr< GateTemplate gate_template) [virtual]

A gate usually has a gate template.

The gate template specifies common properties. Use that function to set the gate template. If the template has other dimensions than the gate, the gate shape is adjusted, so that the gate's dimension complies with the template's one. The attributes min_x and min_y are preserved in that case.

This method updates the template type ID as well.

See also:
set_template_type_id()

Definition at line 125 of file Gate.cc.

References gate_template, degate::Rectangle::get_height(), degate::Rectangle::get_min_x(), degate::Rectangle::get_min_y(), degate::Rectangle::get_width(), has_template(), degate::ColoredObject::set_fill_color(), degate::ColoredObject::set_frame_color(), degate::Rectangle::set_max_x(), degate::Rectangle::set_max_y(), and set_template_type_id().

                                                                      {
  if(has_template()) {
    this->gate_template->decrement_reference_counter();
  }

  if(this->gate_template != gate_template) {
    this->gate_template = gate_template;
    set_template_type_id(gate_template->get_object_id());
    set_fill_color(gate_template->get_fill_color());
    set_frame_color(gate_template->get_frame_color());
    this->gate_template->increment_reference_counter();

    if((unsigned int)get_width() != gate_template->get_width() ||
       (unsigned int)get_height() != gate_template->get_height()) {
      set_max_x(get_min_x() + gate_template->get_width());
      set_max_y(get_min_y() + gate_template->get_height());
    }
  }
}

Here is the call graph for this function:

void Gate::set_orientation ( ORIENTATION  _orientation) [virtual]

If a physically placed gate has a template.

This template defines the appearance of the gate in terms of an image. Because the physically placed gate can have another orientation than the template image, you need to set the image orientation in relation to the master image.

Definition at line 191 of file Gate.cc.

References orientation.

                                                   {
  orientation = _orientation;
}
void Gate::set_template_type_id ( object_id_t  template_type_id) [virtual]

Set the ID of the corresponding template.

This is useful, if there is a cell type defined for this gate, but the cell library is not available, e.g. if the gate library is unloaded in order to load another version of the gate library. In this case we can't work with (shared) pointers and need way to remember the cell type.

If you use method set_gate_template() you don't need to call this method.

Parameters:
template_type_idThe ID of the template (cell type). A value of zero indicates, that there is no template for this gate.
See also:
set_gate_template()

Definition at line 114 of file Gate.cc.

References template_type_id.

Referenced by set_gate_template().

Here is the caller graph for this function:

void degate::Gate::shift_x ( int  delta_x) [inline, virtual]

Shift the shape vertically.

Note: If you store this shape in a QuadTree, you have to manage the changes in your QuadTree by yourself.

Reimplemented from degate::Rectangle.

Definition at line 308 of file Gate.h.

                              {
      Rectangle::shift_x(delta_x);
    }
void degate::Gate::shift_y ( int  delta_y) [inline, virtual]

Shift the shape horizontally.

Note: If you store this shape in a QuadTree, you have to manage the changes in your QuadTree by yourself.

Reimplemented from degate::Rectangle.

Definition at line 312 of file Gate.h.

                              {
      Rectangle::shift_y(delta_y);
    }

Member Data Documentation

Definition at line 66 of file Gate.h.

Referenced by add_port(), cloneDeepInto(), ports_begin(), ports_end(), remove_port(), and remove_template().

Definition at line 70 of file Gate.h.

Referenced by cloneShallow(), get_template_type_id(), remove_template(), and set_template_type_id().


The documentation for this class was generated from the following files: