OpenASIP  2.0
BridgeFactory.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 BridgeFactory.cc
26  *
27  * Definition of BridgeFactory 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 "Bridge.hh"
38 #include "BridgeFigure.hh"
39 #include "BridgeFactory.hh"
40 #include "ConnectionEditPart.hh"
41 #include "BusFactory.hh"
42 #include "EditPolicyFactory.hh"
43 
44 using std::vector;
45 using namespace TTAMachine;
46 
47 /**
48  * The Constructor.
49  */
51  EditPartFactory(editPolicyFactory) {
52 
53  registerFactory(new BusFactory(editPolicyFactory));
54 }
55 
56 /**
57  * The Destructor.
58  */
60 }
61 
62 /**
63  * Returns an EditPart corresponding to a bridge.
64  *
65  * @param component Bridge of which to create the EditPart.
66  * @return NULL if the parameter is not an instance of the
67  * Bridge class.
68  */
69 EditPart*
71 
72  Bridge* bridge = dynamic_cast<Bridge*>(component);
73 
74  if (bridge != NULL) {
75 
76  ConnectionEditPart* bridgeEditPart = new ConnectionEditPart();
77 
78  bridgeEditPart->setModel(bridge);
79  BridgeFigure* fig = new BridgeFigure();
80  bridgeEditPart->setFigure(fig);
81 
82  vector<Factory*>::const_iterator iter;
83 
84  for (iter = factories_.begin(); iter != factories_.end(); iter++) {
85 
86  EditPart* busEditPart = (*iter)->createEditPart(
87  (MachinePart*)bridge->sourceBus());
88 
89  if (busEditPart != NULL) {
90  bridgeEditPart->setSource(busEditPart);
91  bridgeEditPart->setTarget(
92  (*iter)->createEditPart(
93  (MachinePart*)bridge->destinationBus()));
94  break;
95  }
96  }
97 
98  assert(bridgeEditPart->target() != NULL &&
99  bridgeEditPart->source() != NULL);
100 
101  bridgeEditPart->setSelectable(true);
102 
104  if (editPolicy != NULL) {
105  bridgeEditPart->installEditPolicy(editPolicy);
106  }
107 
108  return bridgeEditPart;
109 
110  } else {
111  return NULL;
112  }
113 }
ConnectionEditPart::setSource
void setSource(EditPart *source)
Definition: ConnectionEditPart.cc:56
EditPolicyFactory
Definition: EditPolicyFactory.hh:46
TTAMachine::Bridge::sourceBus
Bus * sourceBus() const
BridgeFactory::~BridgeFactory
virtual ~BridgeFactory()
Definition: BridgeFactory.cc:59
TTAMachine::Bridge::destinationBus
Bus * destinationBus() const
TTAMachine::Bridge
Definition: Bridge.hh:51
EditPart::setSelectable
void setSelectable(bool selectable)
EditPart::installEditPolicy
void installEditPolicy(EditPolicy *editpolicy)
Definition: EditPart.cc:247
ConnectionEditPart::target
EditPart * target() const
EditPolicyFactory::createBridgeEditPolicy
virtual EditPolicy * createBridgeEditPolicy()
ConnectionEditPart::source
EditPart * source() const
EditPartFactory::registerFactory
void registerFactory(Factory *factory)
assert
#define assert(condition)
Definition: Application.hh:86
EditPolicyFactory.hh
ConnectionEditPart.hh
BridgeFactory.hh
Application.hh
EditPartFactory
Definition: EditPartFactory.hh:48
BridgeFigure
Definition: BridgeFigure.hh:46
EditPart::setModel
void setModel(TTAMachine::MachinePart *model)
TTAMachine::MachinePart
Definition: MachinePart.hh:57
EditPolicy
Definition: EditPolicy.hh:47
EditPart
Definition: EditPart.hh:60
BridgeFigure.hh
BusFactory
Definition: BusFactory.hh:45
EditPart::setFigure
void setFigure(Figure *figure)
ConnectionEditPart
Definition: ConnectionEditPart.hh:42
ConnectionEditPart::setTarget
void setTarget(EditPart *target)
Definition: ConnectionEditPart.cc:71
BridgeFactory::BridgeFactory
BridgeFactory(EditPolicyFactory &editPolicyFactory)
Definition: BridgeFactory.cc:50
TTAMachine
Definition: Assembler.hh:48
EditPartFactory::editPolicyFactory_
EditPolicyFactory & editPolicyFactory_
Factory which creates edit policies for edit parts.
Definition: EditPartFactory.hh:64
BridgeFactory::createEditPart
virtual EditPart * createEditPart(TTAMachine::MachinePart *component)
Definition: BridgeFactory.cc:70
Bridge.hh
BusFactory.hh
EditPartFactory::factories_
std::vector< Factory * > factories_
Registered factories.
Definition: EditPartFactory.hh:60