OpenASIP  2.0
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. More...
 
 ProDeSegmentEditPolicy (ProDeSegmentEditPolicy &old)
 Copying not allowed. More...
 

Additional Inherited Members

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

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 }

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 }

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 }

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:
Request::type
RequestType type() const
TTAMachine::Segment
Definition: Segment.hh:54
SetStatusTextCmd
Definition: SetStatusTextCmd.hh:43
Request::DELETE_REQUEST
@ DELETE_REQUEST
Delete request.
Definition: Request.hh:49
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
Request::CONNECT_REQUEST
@ CONNECT_REQUEST
Connect request.
Definition: Request.hh:50
SocketBusConnCmd
Definition: SocketBusConnCmd.hh:43
ProDeTextGenerator
Definition: ProDeTextGenerator.hh:49
assert
#define assert(condition)
Definition: Application.hh:86
DeleteSegmentCmd
Definition: DeleteSegmentCmd.hh:43
ConnectRequest
Definition: ConnectRequest.hh:43
EditPolicy::host_
EditPart * host_
Host EditPart of this EditPolicy.
Definition: EditPolicy.hh:74
ProDeTextGenerator::STATUS_SEGMENT
@ STATUS_SEGMENT
Status line template for segments.
Definition: ProDeTextGenerator.hh:290
EditPolicy::EditPolicy
EditPolicy()
Definition: EditPolicy.cc:41
TTAMachine::Socket
Definition: Socket.hh:53
Request::RequestType
RequestType
Data type for determining the type of a Request.
Definition: Request.hh:46
EditPart
Definition: EditPart.hh:60
TTAMachine::Socket::isConnectedTo
bool isConnectedTo(const Bus &bus) const
Definition: Socket.cc:331
EditPart::model
TTAMachine::MachinePart * model() const
ComponentCommand
Definition: ComponentCommand.hh:46
EditPart::parent
EditPart * parent() const
ProDeTextGenerator::instance
static ProDeTextGenerator * instance()
Definition: ProDeTextGenerator.cc:382
ModifyBusCmd
Definition: ModifyBusCmd.hh:43
ConnectRequest::part
EditPart * part()
Definition: ConnectRequest.cc:58
TTAMachine::Component::machine
virtual Machine * machine() const
ProDeSegmentEditPolicy::canHandle
virtual bool canHandle(Request *request) const
Definition: ProDeSegmentEditPolicy.cc:104
Request::MODIFY_REQUEST
@ MODIFY_REQUEST
Modfify request.
Definition: Request.hh:48
Request::STATUS_REQUEST
@ STATUS_REQUEST
Status request.
Definition: Request.hh:52
TTAMachine::Segment::name
std::string name() const
MachineTester
Definition: MachineTester.hh:46
ProDeSegmentEditPolicy::createConnectCmd
ComponentCommand * createConnectCmd(Request *request)
Definition: ProDeSegmentEditPolicy.cc:148