OpenASIP  2.0
SocketFactory.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 SocketFactory.cc
26  *
27  * Definition of SocketFactory 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 "Machine.hh"
35 #include "SocketFactory.hh"
36 #include "Socket.hh"
37 #include "EditPart.hh"
38 #include "InputSocketFigure.hh"
39 #include "OutputSocketFigure.hh"
40 #include "UnknownSocketFigure.hh"
41 #include "EditPolicyFactory.hh"
42 
43 using std::vector;
44 using namespace TTAMachine;
45 
46 /**
47  * The Constructor.
48  */
50  EditPartFactory(editPolicyFactory) {
51 }
52 
53 /**
54  * The Destructor.
55  */
57 }
58 
59 /**
60  * Returns an EditPart corresponding to a socket.
61  *
62  * @param component Socket of which to create the EditPart.
63  * @return NULL if the parameter is not an instance of the Socket class.
64  */
65 EditPart*
67 
68  EditPart* socketEditPart = EditPartFactory::checkCache(component);
69 
70  if (socketEditPart != NULL) {
71  return socketEditPart;
72  }
73 
74  Socket* socket = dynamic_cast<Socket*>(component);
75 
76  if (socket != NULL) {
77 
78  socketEditPart = new EditPart();
79  socketEditPart->setModel(socket);
80 
81  Figure* fig = NULL;
82 
83  if (socket->direction() == Socket::INPUT) {
84  fig = new InputSocketFigure();
85  } else if (socket->direction() == Socket::OUTPUT) {
86  fig = new OutputSocketFigure();
87  } else {
88  fig = new UnknownSocketFigure();
89  }
90  socketEditPart->setFigure(fig);
91 
92  socketEditPart->setSelectable(true);
93 
95  if (editPolicy != NULL) {
96  socketEditPart->installEditPolicy(editPolicy);
97  }
98 
99  EditPartFactory::writeToCache(socketEditPart);
100  return socketEditPart;
101 
102  } else {
103  return NULL;
104  }
105 }
InputSocketFigure.hh
EditPolicyFactory
Definition: EditPolicyFactory.hh:46
SocketFactory::~SocketFactory
virtual ~SocketFactory()
Definition: SocketFactory.cc:56
EditPart::setSelectable
void setSelectable(bool selectable)
SocketFactory::SocketFactory
SocketFactory(EditPolicyFactory &editPolicyFactory)
Definition: SocketFactory.cc:49
EditPartFactory::checkCache
EditPart * checkCache(const TTAMachine::MachinePart *component) const
Definition: EditPartFactory.cc:72
EditPart::installEditPolicy
void installEditPolicy(EditPolicy *editpolicy)
Definition: EditPart.cc:247
TTAMachine::Socket::direction
Direction direction() const
EditPolicyFactory::createSocketEditPolicy
virtual EditPolicy * createSocketEditPolicy()
Socket.hh
OutputSocketFigure
Definition: OutputSocketFigure.hh:46
UnknownSocketFigure
Definition: UnknownSocketFigure.hh:46
EditPartFactory::writeToCache
void writeToCache(EditPart *editPart)
Definition: EditPartFactory.cc:89
EditPolicyFactory.hh
EditPart.hh
OutputSocketFigure.hh
Figure
Definition: Figure.hh:50
EditPartFactory
Definition: EditPartFactory.hh:48
EditPart::setModel
void setModel(TTAMachine::MachinePart *model)
TTAMachine::Socket
Definition: Socket.hh:53
SocketFactory.hh
TTAMachine::MachinePart
Definition: MachinePart.hh:57
SocketFactory::createEditPart
virtual EditPart * createEditPart(TTAMachine::MachinePart *component)
Definition: SocketFactory.cc:66
EditPolicy
Definition: EditPolicy.hh:47
EditPart
Definition: EditPart.hh:60
Machine.hh
InputSocketFigure
Definition: InputSocketFigure.hh:46
UnknownSocketFigure.hh
EditPart::setFigure
void setFigure(Figure *figure)
TTAMachine
Definition: Assembler.hh:48
EditPartFactory::editPolicyFactory_
EditPolicyFactory & editPolicyFactory_
Factory which creates edit policies for edit parts.
Definition: EditPartFactory.hh:64