OpenASIP  2.0
UnitPortFactory.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file UnitPortFactory.cc
26  *
27  * Definition of UnitPortFactory class.
28  *
29  * @author Ari Metsähalme 2003 (ari.metsahalme-no.spam-tut.fi)
30  * @note rating: yellow
31  * @note reviewed Jul 14 2004 by jm, ll, jn, am
32  */
33 
34 #include <vector>
35 
36 #include "Application.hh"
37 #include "UnitPortFactory.hh"
38 #include "FUPort.hh"
39 #include "Port.hh"
40 #include "EditPart.hh"
41 #include "UnitPortFigure.hh"
42 #include "SocketFactory.hh"
43 #include "SocketPortConnFactory.hh"
44 #include "Socket.hh"
45 #include "EditPolicyFactory.hh"
46 #include "TriggeringPortFigure.hh"
47 
48 using std::vector;
49 using namespace TTAMachine;
50 
51 /**
52  * The Constructor.
53  */
55  EditPartFactory(editPolicyFactory) {
56 
57  registerFactory(new SocketFactory(editPolicyFactory));
58 }
59 
60 /**
61  * The Destructor.
62  */
64 }
65 
66 /**
67  * Returns an EditPart corresponding to a port.
68  *
69  * @param component Port of which to create the EditPart.
70  * @return NULL if the parameter is not an instance of the Port class.
71  */
72 EditPart*
74 
75  Port* port = dynamic_cast<Port*>(component);
76  EditPart* portEditPart = NULL;
77 
78  if (port != NULL) {
79 
80  portEditPart = new EditPart();
81  portEditPart->setModel(port);
82 
83  Figure* fig = NULL;
84 
85  FUPort* fuPort = dynamic_cast<FUPort*>(component);
86  if (fuPort != NULL && fuPort->isTriggering()) {
87  fig = new TriggeringPortFigure(port->name(), port->width());
88  } else {
89  fig = new UnitPortFigure(port->name(), port->width());
90  }
91 
92  portEditPart->setFigure(fig);
93 
94  if (port->inputSocket() != NULL) {
95  addSocket(portEditPart, port->inputSocket());
96  }
97 
98  if (port->outputSocket() != NULL) {
99  addSocket(portEditPart, port->outputSocket());
100  }
101 
102  // number of possible unconnected sockets
103  int unconnectedSockets = 2 - portEditPart->childCount();
104 
105  while (unconnectedSockets > 0) {
106  if (port->unconnectedSocket(unconnectedSockets - 1) != NULL) {
107  addSocket(
108  portEditPart,
109  port->unconnectedSocket(unconnectedSockets - 1));
110  }
111  unconnectedSockets--;
112  }
113  } else {
114  return NULL;
115  }
116 
117  portEditPart->setSelectable(true);
118 
119  // Install editpolicy common to all ports.
121  if (editPolicy != NULL) {
122  portEditPart->installEditPolicy(editPolicy);
123  }
124 
125  return portEditPart;
126 }
127 
128 /**
129  * Creates an EditPart of a socket and adds it as a child to the given
130  * EditPart.
131  *
132  * @param socket Socket of which to create the EditPart.
133  * @param portEditPart Port in which to add the socket as a child.
134  */
135 void
137  EditPart* portEditPart,
138  MachinePart* socket) const {
139 
140  EditPart* socketEditPart = NULL;
141  vector<Factory*>::const_iterator i = factories_.begin();
142 
143  while (socketEditPart == NULL && i != factories_.end()) {
144  socketEditPart = (*i)->createEditPart(socket);
145  i++;
146  }
147 
148  assert(socketEditPart != NULL);
149 
150  SocketPortConnFactory connFactory;
151 
152  socketEditPart->addChild(
153  connFactory.createConnection(
154  portEditPart, socketEditPart));
155  portEditPart->addChild(socketEditPart);
156 }
TTAMachine::Port::unconnectedSocket
virtual Socket * unconnectedSocket(int index) const
Definition: Port.cc:323
SocketPortConnFactory::createConnection
virtual EditPart * createConnection(EditPart *source, EditPart *target) const
Definition: SocketPortConnFactory.cc:66
TTAMachine::Port::inputSocket
virtual Socket * inputSocket() const
Definition: Port.cc:261
EditPolicyFactory
Definition: EditPolicyFactory.hh:46
EditPolicyFactory::createPortEditPolicy
virtual EditPolicy * createPortEditPolicy()
EditPart::setSelectable
void setSelectable(bool selectable)
UnitPortFactory.hh
EditPart::installEditPolicy
void installEditPolicy(EditPolicy *editpolicy)
Definition: EditPart.cc:247
TTAMachine::Port::width
virtual int width() const =0
UnitPortFigure
Definition: UnitPortFigure.hh:46
TTAMachine::FUPort::isTriggering
virtual bool isTriggering() const
Definition: FUPort.cc:182
Socket.hh
EditPartFactory::registerFactory
void registerFactory(Factory *factory)
assert
#define assert(condition)
Definition: Application.hh:86
Port.hh
UnitPortFactory::addSocket
void addSocket(EditPart *portEditPart, TTAMachine::MachinePart *socket) const
Definition: UnitPortFactory.cc:136
TTAMachine::FUPort
Definition: FUPort.hh:46
SocketFactory
Definition: SocketFactory.hh:47
EditPolicyFactory.hh
EditPart.hh
SocketPortConnFactory
Definition: SocketPortConnFactory.hh:44
TTAMachine::Port
Definition: Port.hh:54
Figure
Definition: Figure.hh:50
Application.hh
EditPartFactory
Definition: EditPartFactory.hh:48
UnitPortFactory::UnitPortFactory
UnitPortFactory(EditPolicyFactory &editPolicyFactory)
Definition: UnitPortFactory.cc:54
EditPart::setModel
void setModel(TTAMachine::MachinePart *model)
UnitPortFigure.hh
SocketFactory.hh
TTAMachine::MachinePart
Definition: MachinePart.hh:57
TriggeringPortFigure.hh
EditPolicy
Definition: EditPolicy.hh:47
EditPart
Definition: EditPart.hh:60
EditPart::childCount
int childCount() const
TTAMachine::Port::name
virtual std::string name() const
Definition: Port.cc:141
FUPort.hh
EditPart::setFigure
void setFigure(Figure *figure)
SocketPortConnFactory.hh
TTAMachine::Port::outputSocket
virtual Socket * outputSocket() const
Definition: Port.cc:281
TriggeringPortFigure
Definition: TriggeringPortFigure.hh:45
EditPart::addChild
void addChild(EditPart *child)
Definition: EditPart.cc:260
TTAMachine
Definition: Assembler.hh:48
EditPartFactory::editPolicyFactory_
EditPolicyFactory & editPolicyFactory_
Factory which creates edit policies for edit parts.
Definition: EditPartFactory.hh:64
UnitPortFactory::~UnitPortFactory
virtual ~UnitPortFactory()
Definition: UnitPortFactory.cc:63
UnitPortFactory::createEditPart
virtual EditPart * createEditPart(TTAMachine::MachinePart *component)
Definition: UnitPortFactory.cc:73
EditPartFactory::factories_
std::vector< Factory * > factories_
Registered factories.
Definition: EditPartFactory.hh:60