OpenASIP  2.0
BusFactory.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 BusFactory.cc
26  *
27  * Definition of BusFactory 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 "MachinePart.hh"
37 #include "Bus.hh"
38 #include "Segment.hh"
39 #include "BusFigure.hh"
40 #include "BusFactory.hh"
41 #include "EditPart.hh"
42 #include "SegmentFactory.hh"
43 #include "EditPolicyFactory.hh"
44 
45 using std::vector;
46 using namespace TTAMachine;
47 
48 /**
49  * The Constructor.
50  */
52  EditPartFactory(editPolicyFactory) {
53 
54  registerFactory(new SegmentFactory(editPolicyFactory));
55 }
56 
57 /**
58  * The Destructor.
59  */
61 }
62 
63 /**
64  * Returns an EditPart corresponding to a bus.
65  *
66  * @param component Bus of which to create the EditPart.
67  * @return NULL if the parameter is not an instance of the
68  * Bus class.
69  */
70 EditPart*
72 
73  EditPart* busEditPart = EditPartFactory::checkCache(component);
74 
75  if (busEditPart != NULL) {
76  return busEditPart;
77  }
78 
79  Bus* bus = dynamic_cast<Bus*>(component);
80 
81  if (bus != NULL) {
82 
83  busEditPart = new EditPart();
84  busEditPart->setModel(bus);
85 
86  BusFigure* fig = new BusFigure(bus->position());
87  busEditPart->setFigure(fig);
88 
89  for (int i = 0; i < bus->segmentCount(); i++) {
90  vector<Factory*>::const_iterator iter = factories_.begin();
91  while (iter != factories_.end()) {
92  EditPart* segEditPart =
93  (*iter)->createEditPart((MachinePart*)bus->segment(i));
94  if (segEditPart != NULL) {
95  busEditPart->addChild(segEditPart);
96  segEditPart->setSelectable(true);
97  segEditPart->setParent(busEditPart);
98  }
99  iter++;
100  }
101  }
102 
103  busEditPart->setSelectable(true);
104 
106  if (editPolicy != NULL) {
107  busEditPart->installEditPolicy(editPolicy);
108  }
109  EditPartFactory::writeToCache(busEditPart);
110  return busEditPart;
111 
112  } else {
113  return NULL;
114  }
115 }
BusFigure
Definition: BusFigure.hh:48
EditPolicyFactory
Definition: EditPolicyFactory.hh:46
EditPart::setSelectable
void setSelectable(bool selectable)
TTAMachine::Bus
Definition: Bus.hh:53
EditPartFactory::checkCache
EditPart * checkCache(const TTAMachine::MachinePart *component) const
Definition: EditPartFactory.cc:72
EditPolicyFactory::createBusEditPolicy
virtual EditPolicy * createBusEditPolicy()
EditPart::installEditPolicy
void installEditPolicy(EditPolicy *editpolicy)
Definition: EditPart.cc:247
TTAMachine::Bus::segment
virtual Segment * segment(int index) const
Definition: Bus.cc:329
MachinePart.hh
SegmentFactory.hh
EditPartFactory::registerFactory
void registerFactory(Factory *factory)
EditPart::setParent
void setParent(EditPart *parent)
EditPartFactory::writeToCache
void writeToCache(EditPart *editPart)
Definition: EditPartFactory.cc:89
Segment.hh
TTAMachine::Bus::position
virtual int position() const
Definition: Bus.cc:127
EditPolicyFactory.hh
EditPart.hh
BusFactory::createEditPart
virtual EditPart * createEditPart(TTAMachine::MachinePart *component)
Definition: BusFactory.cc:71
EditPartFactory
Definition: EditPartFactory.hh:48
EditPart::setModel
void setModel(TTAMachine::MachinePart *model)
TTAMachine::MachinePart
Definition: MachinePart.hh:57
EditPolicy
Definition: EditPolicy.hh:47
EditPart
Definition: EditPart.hh:60
BusFactory::~BusFactory
virtual ~BusFactory()
Definition: BusFactory.cc:60
Bus.hh
BusFactory::BusFactory
BusFactory(EditPolicyFactory &editPolicyFactory)
Definition: BusFactory.cc:51
EditPart::setFigure
void setFigure(Figure *figure)
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
BusFigure.hh
TTAMachine::Bus::segmentCount
virtual int segmentCount() const
Definition: Bus.cc:385
SegmentFactory
Definition: SegmentFactory.hh:45
BusFactory.hh
EditPartFactory::factories_
std::vector< Factory * > factories_
Registered factories.
Definition: EditPartFactory.hh:60