OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | List of all members
ProDeSegmentEditPolicy Class Reference

#include <ProDeSegmentEditPolicy.hh>

Inheritance diagram for ProDeSegmentEditPolicy:
Inheritance graph
Collaboration diagram for ProDeSegmentEditPolicy:
Collaboration graph

Public Member Functions

 ProDeSegmentEditPolicy ()
 
virtual ~ProDeSegmentEditPolicy ()
 
virtual ComponentCommandgetCommand (Request *request)
 
virtual bool canHandle (Request *request) const
 
- Public Member Functions inherited from EditPolicy
 EditPolicy ()
 
virtual ~EditPolicy ()
 
EditParthost () const
 
void setHost (EditPart *host)
 

Private Member Functions

ComponentCommandcreateConnectCmd (Request *request)
 
ProDeSegmentEditPolicyoperator= (ProDeSegmentEditPolicy &old)
 Assignment not allowed.
 
 ProDeSegmentEditPolicy (ProDeSegmentEditPolicy &old)
 Copying not allowed.
 

Additional Inherited Members

- Protected Attributes inherited from EditPolicy
EditParthost_
 Host EditPart of this EditPolicy.
 

Detailed Description

Determines how a segment EditPart acts when a Request is performed on it.

Converts a given Request to a Command if the EditPolicy supports. the Request.

Definition at line 49 of file ProDeSegmentEditPolicy.hh.

Constructor & Destructor Documentation

◆ ProDeSegmentEditPolicy() [1/2]

ProDeSegmentEditPolicy::ProDeSegmentEditPolicy ( )

The Constructor.

Definition at line 56 of file ProDeSegmentEditPolicy.cc.

56 : EditPolicy() {
57}

◆ ~ProDeSegmentEditPolicy()

ProDeSegmentEditPolicy::~ProDeSegmentEditPolicy ( )
virtual

The Destructor.

Definition at line 62 of file ProDeSegmentEditPolicy.cc.

62 {
63}

◆ ProDeSegmentEditPolicy() [2/2]

ProDeSegmentEditPolicy::ProDeSegmentEditPolicy ( ProDeSegmentEditPolicy old)
private

Copying not allowed.

Member Function Documentation

◆ canHandle()

bool ProDeSegmentEditPolicy::canHandle ( Request request) const
virtual

Tells whether this EditPolicy is able to handle a certain type of Request.

Parameters
requestRequest to be asked if it can be handled.
Returns
True if the Request can be handled, false otherwise.

Implements EditPolicy.

Definition at line 104 of file ProDeSegmentEditPolicy.cc.

104 {
105 Request::RequestType type = request->type();
106 if (type == Request::CONNECT_REQUEST) {
107 ConnectRequest* cr = dynamic_cast<ConnectRequest*>(request);
108 assert(cr != NULL);
109 EditPart* part = cr->part();
110
111 if (part == NULL) {
112 // No selection.
113 // Segment can be selected for connecting, return true.
114 return true;
115 }
116 Socket* socket = dynamic_cast<Socket*>(part->model());
117 if (socket == NULL) {
118 // Segment can be connected only to sockets, return false.
119 return false;
120 }
121 MachineTester tester(*(socket->machine()));
122 Segment* segment = dynamic_cast<Segment*>(host_->model());
123 if (socket->isConnectedTo(*segment) ||
124 tester.canConnect(*socket, *segment)) {
125 return true;
126 }
127 return false;
128 } else if (type == Request::STATUS_REQUEST) {
129 return true;
130 } else if (type == Request::DELETE_REQUEST) {
131 return true;
132 } else if (type == Request::MODIFY_REQUEST) {
133 return true;
134 } else {
135 return false;
136 }
137}
#define assert(condition)
EditPart * part()
TTAMachine::MachinePart * model() const
EditPart * host_
Host EditPart of this EditPolicy.
Definition EditPolicy.hh:74
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
@ CONNECT_REQUEST
Connect request.
Definition Request.hh:50
RequestType type() const
virtual Machine * machine() const
bool isConnectedTo(const Bus &bus) const
Definition Socket.cc:331

References assert, MachineTester::canConnect(), Request::CONNECT_REQUEST, Request::DELETE_REQUEST, EditPolicy::host_, TTAMachine::Socket::isConnectedTo(), TTAMachine::Component::machine(), EditPart::model(), Request::MODIFY_REQUEST, ConnectRequest::part(), Request::STATUS_REQUEST, and Request::type().

Referenced by createConnectCmd().

Here is the call graph for this function:

◆ createConnectCmd()

ComponentCommand * ProDeSegmentEditPolicy::createConnectCmd ( Request request)
private

Creates a command which connects the selected component to the requested component.

Parameters
requestConnectionRequest with the target component for the connection.
Returns
Command for connecting the selected and requested components.

Definition at line 148 of file ProDeSegmentEditPolicy.cc.

148 {
149
150 ConnectRequest* cr = dynamic_cast<ConnectRequest*>(request);
151 assert(cr != NULL);
152 EditPart* part = cr->part();
153
154 if (canHandle(request)) {
155 Segment* segment = dynamic_cast<Segment*>(host_->model());
156 Socket* socket = dynamic_cast<Socket*>(part->model());
157 if (socket == NULL) {
158 return NULL;
159 }
160 ComponentCommand* cmd = NULL;
161 cmd = new SocketBusConnCmd(socket, segment);
162 return cmd;
163 } else {
164 return NULL;
165 }
166}
virtual bool canHandle(Request *request) const

References assert, canHandle(), EditPolicy::host_, EditPart::model(), and ConnectRequest::part().

Referenced by getCommand().

Here is the call graph for this function:

◆ getCommand()

ComponentCommand * ProDeSegmentEditPolicy::getCommand ( Request request)
virtual

Returns the Command corresponding to the type of the Request.

Parameters
requestRequest to be handled.
Returns
NULL if the Request cannot be handled.
Note
ConnectCommand is not yet implemented, thus returns always NULL.

Implements EditPolicy.

Definition at line 73 of file ProDeSegmentEditPolicy.cc.

73 {
74
75
76 Request::RequestType type = request->type();
77 if (type == Request::CONNECT_REQUEST) {
78 return createConnectCmd(request);
79 } else if (type == Request::MODIFY_REQUEST) {
80 return new ModifyBusCmd(host_->parent());
81 } else if (type == Request::DELETE_REQUEST) {
82 return new DeleteSegmentCmd(host_);
83 } else if (type == Request::STATUS_REQUEST) {
84 // Editing segments is unsupported feature => return empty command
85 return NULL;
86 Segment* segment = dynamic_cast<Segment*>(host_->model());
88 format fmt = generator->text(ProDeTextGenerator::STATUS_SEGMENT);
89 fmt % segment->name();
90 SetStatusTextCmd* statusCmd = new SetStatusTextCmd(fmt.str());
91 return statusCmd;
92 }
93 return NULL;
94}
EditPart * parent() const
ComponentCommand * createConnectCmd(Request *request)
static ProDeTextGenerator * instance()
@ STATUS_SEGMENT
Status line template for segments.
std::string name() const
virtual boost::format text(int textId)

References Request::CONNECT_REQUEST, createConnectCmd(), Request::DELETE_REQUEST, EditPolicy::host_, ProDeTextGenerator::instance(), EditPart::model(), Request::MODIFY_REQUEST, TTAMachine::Segment::name(), EditPart::parent(), Request::STATUS_REQUEST, ProDeTextGenerator::STATUS_SEGMENT, Texts::TextGenerator::text(), and Request::type().

Here is the call graph for this function:

◆ operator=()

ProDeSegmentEditPolicy & ProDeSegmentEditPolicy::operator= ( ProDeSegmentEditPolicy old)
private

Assignment not allowed.


The documentation for this class was generated from the following files: