|
degate 0.1.1
|
The class Gate defines and implements a physically placed gate. More...
#include <Gate.h>

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 >::iterator | port_iterator |
| typedef std::set < GatePort_shptr > ::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::tr1::shared_ptr< GateTemplate > gate_template) |
| A gate usually has a gate template. | |
| virtual std::tr1::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. | |
Private Attributes | |
| GateTemplate_shptr | gate_template |
| std::set< GatePort_shptr > | gate_ports |
| ORIENTATION | orientation |
| object_id_t | template_type_id |
The class Gate defines and implements a physically placed gate.
| typedef std::set< GatePort_shptr >::const_iterator degate::Gate::port_const_iterator |
| typedef std::set< GatePort_shptr >::iterator degate::Gate::port_iterator |
| ORIENTATION_UNDEFINED | |
| ORIENTATION_NORMAL | |
| ORIENTATION_FLIPPED_UP_DOWN | |
| ORIENTATION_FLIPPED_LEFT_RIGHT | |
| ORIENTATION_FLIPPED_BOTH |
Definition at line 50 of file Gate.h.
{
ORIENTATION_UNDEFINED = 0,
ORIENTATION_NORMAL = 1,
ORIENTATION_FLIPPED_UP_DOWN = 2,
ORIENTATION_FLIPPED_LEFT_RIGHT = 3,
ORIENTATION_FLIPPED_BOTH = 4
};
| Gate::Gate | ( | int | _min_x, |
| int | _max_x, | ||
| int | _min_y, | ||
| int | _max_y, | ||
| ORIENTATION | _orientation = ORIENTATION_UNDEFINED |
||
| ) |
Create a gate.
Definition at line 29 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 36 of file Gate.cc.
: Rectangle(bounding_box.get_min_x(), bounding_box.get_max_x(), bounding_box.get_min_y(), bounding_box.get_max_y()), orientation(_orientation), template_type_id(0) { }
| Gate::~Gate | ( | ) | [virtual] |
Destroy a gate.
Definition at line 44 of file Gate.cc.
References debug(), gate_template, remove_template(), and TM.
{
debug(TM, "destroy gate");
if(gate_template != NULL) remove_template();
}

| 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()
| InvalidObjectIDException | This exception is thrown, if the port has no valid object ID. |
| DegateLogicException | Is thrown if gate_port has no valid GateTemplatePort or if the gate has no valid orientation. |
Definition at line 49 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);
}

| virtual BoundingBox const& degate::Gate::get_bounding_box | ( | ) | const [inline, virtual] |
Get the bounding box.
Reimplemented from degate::Rectangle.
Definition at line 315 of file Gate.h.
Referenced by print().
{
return Rectangle::get_bounding_box();
}

| 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 243 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();
}
}
}

| std::tr1::shared_ptr< GateTemplate > Gate::get_gate_template | ( | ) | const [virtual] |
Get the gate template.
Definition at line 125 of file Gate.cc.
References gate_template.
Referenced by get_descriptive_identifier().
{
return gate_template;
}

| 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 273 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 182 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");
}
}
| Gate::ORIENTATION Gate::get_orientation | ( | ) | const [virtual] |
Get the orientation relative to the master image.
Definition at line 174 of file Gate.cc.
References orientation.
{
return orientation;
}
| GatePort_shptr Gate::get_port_by_template_port | ( | GateTemplatePort_shptr | template_port | ) | [virtual] |
Get a gate port by a template port.
Definition at line 82 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();
}

| 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.
| rel_x | The x-coordinate realtive to min_x. |
| DegateRuntimeException | This exception is thrown if the object has an undefined gate orientation. |
Definition at line 211 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");
}
}


| 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.
| rel_y | The y-coordinate realtive to min_y. |
| DegateRuntimeException | This exception is thrown if the object has an undefined gate orientation. |
Definition at line 227 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");
}
}


| object_id_t Gate::get_template_type_id | ( | ) | const [virtual] |
Get the ID of the corresponding template.
Definition at line 98 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 178 of file Gate.cc.
References orientation, and ORIENTATION_UNDEFINED.
Referenced by add_port().
{
return orientation != ORIENTATION_UNDEFINED;
}

| bool Gate::has_template | ( | ) | const [virtual] |
Check if the gate has a template type set.
Definition at line 129 of file Gate.cc.
References gate_template.
Referenced by get_descriptive_identifier(), remove_template(), and set_gate_template().
{
return gate_template != NULL;
}

| 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 145 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;
}

| 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 311 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 298 of file Gate.h.
{
return Rectangle::in_shape(x, y, max_distance);
}
| Gate::port_const_iterator Gate::ports_begin | ( | ) | const [virtual] |
Get an iterator to iterated over ports.
Definition at line 198 of file Gate.cc.
References gate_ports.
{
return gate_ports.begin();
}
| Gate::port_iterator Gate::ports_begin | ( | ) | [virtual] |
Get an iterator to iterated over ports.
Definition at line 194 of file Gate.cc.
References gate_ports.
Referenced by get_port_by_template_port(), has_template_port(), and print().
{
return gate_ports.begin();
}

| Gate::port_iterator Gate::ports_end | ( | ) | [virtual] |
Get an end iterator.
Definition at line 202 of file Gate.cc.
References gate_ports.
Referenced by get_port_by_template_port(), has_template_port(), and print().
{
return gate_ports.end();
}

| Gate::port_const_iterator Gate::ports_end | ( | ) | const [virtual] |
Get an end iterator.
Definition at line 206 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 277 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;
}

| void Gate::remove_port | ( | GatePort_shptr | gate_port | ) | [virtual] |
Remove a gate port.
Definition at line 73 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 133 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();
}
}


| void Gate::set_gate_template | ( | std::tr1::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.
Definition at line 104 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());
}
}
}

| 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 170 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.
| template_type_id | The ID of the template (cell type). A value of zero indicates, that there is no template for this gate. |
Definition at line 93 of file Gate.cc.
References template_type_id.
Referenced by set_gate_template().
{
this->template_type_id = template_type_id;
}

| 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 302 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 306 of file Gate.h.
{
Rectangle::shift_y(delta_y);
}
std::set<GatePort_shptr> degate::Gate::gate_ports [private] |
Definition at line 65 of file Gate.h.
Referenced by add_port(), ports_begin(), ports_end(), remove_port(), and remove_template().
Definition at line 63 of file Gate.h.
Referenced by get_gate_template(), has_template(), remove_template(), set_gate_template(), and ~Gate().
ORIENTATION degate::Gate::orientation [private] |
Definition at line 67 of file Gate.h.
Referenced by get_orienation_type_as_string(), get_orientation(), get_relative_x_position_within_gate(), get_relative_y_position_within_gate(), has_orientation(), remove_template(), and set_orientation().
object_id_t degate::Gate::template_type_id [private] |
Definition at line 69 of file Gate.h.
Referenced by get_template_type_id(), remove_template(), and set_template_type_id().
1.7.4