OpenASIP 2.2
Loading...
Searching...
No Matches
ProDeBusEditPolicy.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 ProDeBusEditPolicy.cc
26 *
27 * Definition of ProDeBusEditPolicy class.
28 *
29 * @author Ari Metsähalme 2003 (ari.metsahalme-no.spam-tut.fi)
30 * @note rating: yellow
31 * @note reviewed Jul 20 2004 by vpj, jn, am
32 */
33
34#include <string>
35#include <boost/format.hpp>
36
37#include "ProDeBusEditPolicy.hh"
38#include "Request.hh"
39#include "ComponentCommand.hh"
40#include "SetStatusTextCmd.hh"
41#include "ModifyBusCmd.hh"
42#include "DeleteBusCmd.hh"
43#include "CopyComponent.hh"
44#include "EditPart.hh"
45#include "MachinePart.hh"
46#include "Bus.hh"
47#include "ProDeTextGenerator.hh"
48#include "Conversion.hh"
49
50using boost::format;
51using std::string;
52using namespace TTAMachine;
53
54/**
55 * The Constructor.
56 */
59
60/**
61 * The Destructor.
62 */
65
66/**
67 * Returns the Command corresponding to the type of the Request.
68 *
69 * @param request Request to be handled.
70 * @return NULL if the Request cannot be handled.
71 */
74
75 Request::RequestType type = request->type();
76
77 if (type == Request::MODIFY_REQUEST) {
78 ModifyBusCmd* modifyCmd = new ModifyBusCmd(host_);
79 return modifyCmd;
80
81 } else if (type == Request::DELETE_REQUEST) {
82 DeleteBusCmd* deleteCmd = new DeleteBusCmd(host_);
83 return deleteCmd;
84
85 } else if (type == Request::COPY_REQUEST) {
86 CopyComponent* copyCmd = new CopyComponent(host_);
87 return copyCmd;
88
89 } else if (type == Request::STATUS_REQUEST) {
90 Bus* bus = dynamic_cast<Bus*>(host_->model());
92 format fmt = generator->text(ProDeTextGenerator::STATUS_BUS);
93 string extension = "";
94 if (bus->signExtends()) {
95 extension = generator->text(
97 } else {
98 extension = generator->text(
100 }
101 fmt % bus->name() % Conversion::toString(bus->width()) %
103 extension;
104 SetStatusTextCmd* statusCmd = new SetStatusTextCmd(fmt.str());
105 return statusCmd;
106
107 } else {
108 return NULL;
109 }
110}
111
112/**
113 * Tells whether this EditPolicy is able to handle a certain type
114 * of Request.
115 *
116 * @param request Request to be asked if it can be handled.
117 * @return True if the Request can be handled, false otherwise.
118 */
119bool
121 Request::RequestType type = request->type();
122 if (type == Request::MODIFY_REQUEST ||
123 type == Request::DELETE_REQUEST ||
124 type == Request::COPY_REQUEST ||
125 type == Request::STATUS_REQUEST) {
126 return true;
127 } else {
128 return false;
129 }
130}
static std::string toString(const T &source)
TTAMachine::MachinePart * model() const
EditPart * host_
Host EditPart of this EditPolicy.
Definition EditPolicy.hh:74
virtual bool canHandle(Request *request) const
virtual ComponentCommand * getCommand(Request *request)
static ProDeTextGenerator * instance()
@ STATUS_BUS
Status line template for buses.
@ TXT_RADIO_EXTENSION_ZERO
Label for 'zero' radio button.
@ TXT_RADIO_EXTENSION_SIGN
Label for 'sign' radio button.
RequestType
Data type for determining the type of a Request.
Definition Request.hh:46
@ STATUS_REQUEST
Status request.
Definition Request.hh:52
@ MODIFY_REQUEST
Modfify request.
Definition Request.hh:48
@ DELETE_REQUEST
Delete request.
Definition Request.hh:49
@ COPY_REQUEST
Copy request.
Definition Request.hh:51
RequestType type() const
int width() const
Definition Bus.cc:149
int immediateWidth() const
Definition Bus.cc:160
bool signExtends() const
Definition Bus.cc:171
virtual TCEString name() const
virtual boost::format text(int textId)