OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
TTAMachine::Segment Class Reference

#include <Segment.hh>

Inheritance diagram for TTAMachine::Segment:
Inheritance graph
Collaboration diagram for TTAMachine::Segment:
Collaboration graph

Public Member Functions

 Segment (const std::string &name, Bus &parent)
 
 Segment (const ObjectState *state, Bus &parent)
 
 ~Segment ()
 
void setName (const std::string &name)
 
std::string name () const
 
void attachSocket (Socket &socket)
 
void detachSocket (Socket &socket)
 
void detachAllSockets ()
 
bool isConnectedTo (const Socket &socket) const
 
const Connectionconnection (const Socket &socket) const
 
Socketconnection (int index) const
 
int connectionCount () const
 
BusparentBus () const
 
void moveBefore (Segment &segment)
 
void moveAfter (Segment &segment)
 
bool hasSourceSegment () const
 
bool hasDestinationSegment () const
 
SegmentsourceSegment () const
 
SegmentdestinationSegment () const
 
virtual ObjectStatesaveState () const
 
virtual void loadState (const ObjectState *state)
 
- Public Member Functions inherited from Serializable
virtual ~Serializable ()
 

Static Public Attributes

static const std::string OSNAME_SEGMENT = "segment"
 ObjectState name for Segment.
 
static const std::string OSKEY_NAME = "name"
 ObjectState attribute key for segment name.
 
static const std::string OSKEY_DESTINATION = "destination"
 ObjectState attribute key for destination segment name.
 

Private Types

typedef std::vector< const Connection * > ConnectionTable
 Vector of Connection pointers.
 

Private Member Functions

void loadStateWithoutReferences (const ObjectState *state)
 
void removeConnection (const Connection *connection)
 

Private Attributes

std::string name_
 Name of the segment.
 
Busparent_
 The parent bus.
 
SegmentsourceSegment_
 Source segment.
 
SegmentdestinationSegment_
 Destination segment.
 
ConnectionTable connections_
 Contains all the connections to sockets.
 

Additional Inherited Members

- Protected Member Functions inherited from TTAMachine::SubComponent
 SubComponent ()
 
virtual ~SubComponent ()
 
- Protected Member Functions inherited from TTAMachine::MachinePart
 MachinePart ()
 
virtual ~MachinePart ()
 

Detailed Description

Represents a segment of a bus.

Definition at line 54 of file Segment.hh.

Member Typedef Documentation

◆ ConnectionTable

typedef std::vector<const Connection*> TTAMachine::Segment::ConnectionTable
private

Vector of Connection pointers.

Definition at line 95 of file Segment.hh.

Constructor & Destructor Documentation

◆ Segment() [1/2]

TTAMachine::Segment::Segment ( const std::string &  name,
Bus parent 
)

Constructor.

The segment is appended at the end of the segment chain of its parent bus.

Parameters
nameName of the segment.
parentThe bus this segment belongs to (parent bus).
Exceptions
ComponentAlreadyExistsIf a segment with the same name already exists in the same segment chain.
InvalidNameIf the given name is not a valid component name.

Definition at line 70 of file Segment.cc.

71 : name_(name),
72 parent_(NULL),
73 sourceSegment_(NULL),
76 const string procName = "Segment::Segment";
77 throw InvalidName(__FILE__, __LINE__, procName);
78 }
79
80 parent.addSegment(*this);
81 parent_ = &parent;
82
83 for (int i = 0; i < parent.segmentCount(); i++) {
84 Segment* segment = parent.segment(i);
85 if (segment->destinationSegment_ == NULL && segment != this) {
86 segment->destinationSegment_ = this;
87 sourceSegment_ = segment;
88 break;
89 }
90 }
91}
static bool isValidComponentName(const std::string &name)
Segment(const std::string &name, Bus &parent)
Definition Segment.cc:70
Segment * sourceSegment_
Source segment.
Definition Segment.hh:105
std::string name_
Name of the segment.
Definition Segment.hh:101
Bus * parent_
The parent bus.
Definition Segment.hh:103
std::string name() const
Segment * destinationSegment_
Destination segment.
Definition Segment.hh:107

References TTAMachine::Bus::addSegment(), destinationSegment_, MachineTester::isValidComponentName(), name(), parent_, TTAMachine::Bus::segment(), TTAMachine::Bus::segmentCount(), and sourceSegment_.

Here is the call graph for this function:

◆ Segment() [2/2]

TTAMachine::Segment::Segment ( const ObjectState state,
Bus parent 
)

Constructor.

Creates a skeleton segment with name only. This method should be called by Bus::loadStateWithoutReferences only. Do not use this constructor.

Parameters
stateThe ObjectState instance from which the name is loaded.
parentThe bus this segment belongs to (parent bus).
Exceptions
ComponentAlreadyExistsIf a segment with the same name already exists in the given parent bus.
ObjectStateLoadingExceptionIf an error occurs while loading the state.

Definition at line 106 of file Segment.cc.

107 : name_(""),
108 parent_(NULL),
109 sourceSegment_(NULL),
110 destinationSegment_(NULL) {
112 parent.addSegment(*this);
113 parent_ = &parent;
114}
void loadStateWithoutReferences(const ObjectState *state)
Definition Segment.cc:469

References TTAMachine::Bus::addSegment(), loadStateWithoutReferences(), and parent_.

Here is the call graph for this function:

◆ ~Segment()

TTAMachine::Segment::~Segment ( )

Destructor.

Detaches all the sockets before destruction.

Definition at line 121 of file Segment.cc.

121 {
122
123 Bus* parentBus = parent_;
124 parent_ = NULL;
125 parentBus->removeSegment(*this);
126
128
129 if (sourceSegment_ != NULL) {
131 }
132 if (destinationSegment_ != NULL) {
134 }
135}
virtual void removeSegment(Segment &segment)
Definition Bus.cc:757
void detachAllSockets()
Definition Segment.cc:229
Bus * parentBus() const

References destinationSegment_, detachAllSockets(), parent_, parentBus(), TTAMachine::Bus::removeSegment(), and sourceSegment_.

Here is the call graph for this function:

Member Function Documentation

◆ attachSocket()

void TTAMachine::Segment::attachSocket ( Socket socket)

Connects a socket to the segment.

Parameters
socketSocket to be connected.
Exceptions
IllegalRegistrationIf socket and segment do not belong to the same machine.
IllegalConnectivityIf the connection would violate a connectivity constraint.

Definition at line 180 of file Segment.cc.

180 {
181 parentBus()->ensureRegistration(socket);
182
183 if (socket.isConnectedTo(*this)) {
184 if (!isConnectedTo(socket)) {
185 const Connection* conn = &(socket.connection(*this));
186 connections_.push_back(conn);
187 } else {
189 assert(!tester.canConnect(socket, *this));
190 MachineTestReporter reporter;
191 string errorMsg =
192 reporter.socketSegmentConnectionError(socket, *this, tester);
193 string procName = "Segment::attachSocket";
195 __FILE__, __LINE__, procName, errorMsg);
196 }
197 } else {
198 socket.attachBus(*this);
199 }
200}
#define assert(condition)
static std::string socketSegmentConnectionError(const TTAMachine::Socket &socket, const TTAMachine::Segment &segment, const MachineTester &tester)
virtual bool canConnect(const TTAMachine::Socket &socket, const TTAMachine::Segment &segment)
virtual Machine * machine() const
virtual void ensureRegistration(const Component &component) const
MachineTester & machineTester() const
Definition Machine.cc:671
ConnectionTable connections_
Contains all the connections to sockets.
Definition Segment.hh:109
bool isConnectedTo(const Socket &socket) const
Definition Segment.cc:274

References assert, TTAMachine::Socket::attachBus(), MachineTester::canConnect(), TTAMachine::Socket::connection(), connections_, TTAMachine::Component::ensureRegistration(), TTAMachine::Socket::isConnectedTo(), isConnectedTo(), TTAMachine::Component::machine(), TTAMachine::Machine::machineTester(), parentBus(), and MachineTestReporter::socketSegmentConnectionError().

Referenced by TTAMachine::Socket::attachBus(), BlocksConnectIC::explore(), and VLIWConnectIC::explore().

Here is the call graph for this function:

◆ connection() [1/2]

const Connection & TTAMachine::Segment::connection ( const Socket socket) const

Returns the Connection object which joins this segment and the given socket.

The connection must exist before calling this method. This method is not intended for clients. Do not use this method.

Parameters
socketSocket which is attached to this segment.
Returns
Connection object which joins the socket and the segment.

Definition at line 250 of file Segment.cc.

250 {
251
252 ConnectionTable::const_iterator iter = connections_.begin();
253 while (iter != connections_.end()) {
254 if ((*iter)->socket() == &socket) {
255 return **iter;
256 } else {
257 iter++;
258 }
259 }
260 assert(false);
261
262 // this return statement is only to avoid warning in Solaris environment
263 return **iter;
264}

References assert, and connections_.

Referenced by BEMValidator::checkDestinationField(), BEMValidator::checkSourceField(), SegmentFactory::createEditPart(), detachSocket(), CostEstimator::Estimator::findAllICPaths(), DefaultICGenerator::inputSockets(), BEMValidator::needsSourceField(), DefaultICGenerator::outputSockets(), removeConnection(), BusBroker::setupResourceLinks(), BEMGenerator::socket(), BEMGenerator::socketCount(), ConnectionSweeper::sweepBypasses(), and ConnectionSweeper::sweepRFs().

◆ connection() [2/2]

Socket * TTAMachine::Segment::connection ( int  index) const

Returns the connected socket by the given index.

The index must be greater or equal to 0 and less than the number of socket connections.

Parameters
indexIndex.
Returns
The connected socket by the given index.
Exceptions
OutOfRangeIf the given index is out of range.

Definition at line 300 of file Segment.cc.

300 {
301 if (index < 0 || index >= connectionCount()) {
302 string procName = "Segment::connection";
303 throw OutOfRange(__FILE__, __LINE__, procName);
304 }
305 return connections_[index]->socket();
306}
int connectionCount() const

References connectionCount(), and connections_.

Here is the call graph for this function:

◆ connectionCount()

int TTAMachine::Segment::connectionCount ( ) const

◆ destinationSegment()

Segment * TTAMachine::Segment::destinationSegment ( ) const

◆ detachAllSockets()

void TTAMachine::Segment::detachAllSockets ( )

Detaches all the sockets attached to the segment.

Definition at line 229 of file Segment.cc.

229 {
230 ConnectionTable::iterator iter = connections_.begin();
231 while (iter != connections_.end()) {
232 Socket* socket = (*iter)->socket();
233 detachSocket(*socket); // removes the socket from connections_
234 iter = connections_.begin();
235 }
236}
void detachSocket(Socket &socket)
Definition Segment.cc:210

References connections_, and detachSocket().

Referenced by loadState(), and ~Segment().

Here is the call graph for this function:

◆ detachSocket()

void TTAMachine::Segment::detachSocket ( Socket socket)

Detaches socket from the segment.

Parameters
socketSocket which is detached.
Exceptions
InstanceNotFoundIf the segment is not attached to the given socket.

Definition at line 210 of file Segment.cc.

210 {
211 if (!isConnectedTo(socket)) {
212 string procName = "Segment::detachSocket";
213 throw InstanceNotFound(__FILE__, __LINE__, procName);
214 }
215
216 const Connection& conn = connection(socket);
217 removeConnection(&conn);
218
219 if (socket.isConnectedTo(*this)) {
220 socket.detachBus(*this);
221 delete &conn;
222 }
223}
const Connection & connection(const Socket &socket) const
Definition Segment.cc:250
void removeConnection(const Connection *connection)
Definition Segment.cc:410

References connection(), TTAMachine::Socket::detachBus(), TTAMachine::Socket::isConnectedTo(), isConnectedTo(), and removeConnection().

Referenced by detachAllSockets(), TTAMachine::Socket::detachBus(), and ConnectionSweeper::removeConnection().

Here is the call graph for this function:

◆ hasDestinationSegment()

bool TTAMachine::Segment::hasDestinationSegment ( ) const

Returns true if the segment has a destination segment, otherwise false.

Returns
True if the segment has a destination segment, otherwise false.

Definition at line 399 of file Segment.cc.

399 {
400 return (destinationSegment_ != NULL);
401}

References destinationSegment_.

Referenced by BusDialog::onSegmentDown().

◆ hasSourceSegment()

bool TTAMachine::Segment::hasSourceSegment ( ) const

Returns true if the segment has a source segment, otherwise false.

Returns
True if the segment has a source segment, otherwise false.

Definition at line 388 of file Segment.cc.

388 {
389 return (sourceSegment_ != NULL);
390}

References sourceSegment_.

Referenced by BusDialog::onSegmentUp(), and TTAMachine::Bus::segment().

◆ isConnectedTo()

bool TTAMachine::Segment::isConnectedTo ( const Socket socket) const

Checks whether the segment is connected to the given socket.

Parameters
socketSocket.
Returns
True if connected, otherwise false.

Definition at line 274 of file Segment.cc.

274 {
275
276 ConnectionTable::const_iterator iter = connections_.begin();
277 while (iter != connections_.end()) {
278 if ((*iter)->socket() == &socket) {
279 return true;
280 } else {
281 iter++;
282 }
283 }
284
285 return false;
286}

References connections_.

Referenced by TTAMachine::Socket::attachBus(), attachSocket(), TTAMachine::Socket::detachBus(), detachSocket(), BlocksConnectIC::explore(), and TTAMachine::Connection::~Connection().

◆ loadState()

void TTAMachine::Segment::loadState ( const ObjectState state)
virtual

Loads the state of the segment from the given ObjectState instance.

Loads only name of the segment. Does not load connections to sockets. The destination of the segment and the order the segments in the chain is set later, in Bus::loadState.

Parameters
stateThe ObjectState instance.
Exceptions
ObjectStateLoadingExceptionIf the parent bus has a segment with the same name that is assigned to this segment or if the ObjectState tree is invalid.

Implements Serializable.

Definition at line 448 of file Segment.cc.

448 {
449 string procName = "Segment::loadState";
450 MOMTextGenerator textGenerator;
451
452 if (state->name() != OSNAME_SEGMENT) {
453 throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
454 }
455
458}
std::string name() const
static const std::string OSNAME_SEGMENT
ObjectState name for Segment.
Definition Segment.hh:87

References detachAllSockets(), loadStateWithoutReferences(), ObjectState::name(), and OSNAME_SEGMENT.

Referenced by TTAMachine::Bus::loadState().

Here is the call graph for this function:

◆ loadStateWithoutReferences()

void TTAMachine::Segment::loadStateWithoutReferences ( const ObjectState state)
private

Loads the state of the object from the given ObjectState instance without references to other machine parts.

Parameters
stateThe ObjectState instance.
Exceptions
ObjectStateLoadingExceptionIf the given ObjectState instance is invalid.

Definition at line 469 of file Segment.cc.

469 {
470 const string procName = "Segment::loadStateWithoutReferences";
471
472 if (state->name() != OSNAME_SEGMENT) {
473 throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
474 }
475
476 try {
477 string name = state->stringAttribute(OSKEY_NAME);
479 throw InvalidName(__FILE__, __LINE__, procName);
480 }
481 if (parent_ != NULL && parent_->hasSegment(name) &&
482 this->name() != name) {
483 throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
484 }
485 name_ = name;
486 } catch (const Exception& exception) {
488 __FILE__, __LINE__, procName, exception.errorMessage());
489 }
490}
std::string errorMessage() const
Definition Exception.cc:123
std::string stringAttribute(const std::string &name) const
virtual bool hasSegment(const std::string &name) const
Definition Bus.cc:284
static const std::string OSKEY_NAME
ObjectState attribute key for segment name.
Definition Segment.hh:89

References Exception::errorMessage(), TTAMachine::Bus::hasSegment(), MachineTester::isValidComponentName(), name(), ObjectState::name(), name_, OSKEY_NAME, OSNAME_SEGMENT, parent_, and ObjectState::stringAttribute().

Referenced by loadState(), and Segment().

Here is the call graph for this function:

◆ moveAfter()

void TTAMachine::Segment::moveAfter ( Segment segment)

Moves the segment behind the given segment in the segment chain.

The successor of this segment will become the successor of the current predecessor of this segment. The current successor of the given segment will become the successor the this segment.

Parameters
segmentThe segment behind of which the segment is moved.
Exceptions
IllegalRegistrationIf the given segment is in different bus than this segment.

Definition at line 357 of file Segment.cc.

357 {
358 if (parentBus() != segment.parentBus()) {
359 string procName = "Segment::moveAfter";
360 throw IllegalRegistration(__FILE__, __LINE__, procName);
361 }
362
363 // detach from chain
364 if (destinationSegment_ != NULL) {
366 }
367 if (sourceSegment_ != NULL) {
369 }
370
371 // attach to new position
372 if (segment.destinationSegment_ != NULL) {
373 segment.destinationSegment_->sourceSegment_ = this;
374 }
375
376 sourceSegment_ = &segment;
378
379 segment.destinationSegment_ = this;
380}

References destinationSegment_, parentBus(), and sourceSegment_.

Referenced by BusDialog::onSegmentDown().

Here is the call graph for this function:

◆ moveBefore()

void TTAMachine::Segment::moveBefore ( Segment segment)

Moves the segment to the front of the given segment in the segment chain.

The successor of this segment will become the successor of the current predecessor of this segment. The current predecessor of the given segment will become the predecessor of this segment.

Parameters
segmentThe segment in front of which the segment is moved.
Exceptions
IllegalRegistrationIf the given segment is in different bus than this segment.

Definition at line 320 of file Segment.cc.

320 {
321 if (parentBus() != segment.parentBus()) {
322 string procName = "Segment::moveBefore";
323 throw IllegalRegistration(__FILE__, __LINE__, procName);
324 }
325
326 // detach from chain
327 if (destinationSegment_ != NULL) {
329 }
330 if (sourceSegment_ != NULL) {
332 }
333
334 // attach to new position
335 if (segment.sourceSegment_ != NULL) {
336 segment.sourceSegment_->destinationSegment_ = this;
337 }
338
340 destinationSegment_ = &segment;
341
342 segment.sourceSegment_ = this;
343}

References destinationSegment_, parentBus(), and sourceSegment_.

Referenced by TTAMachine::Bus::adjustSegmentChain(), and BusDialog::onSegmentUp().

Here is the call graph for this function:

◆ name()

std::string TTAMachine::Segment::name ( ) const

◆ parentBus()

Bus * TTAMachine::Segment::parentBus ( ) const

◆ removeConnection()

void TTAMachine::Segment::removeConnection ( const Connection connection)
private

Removes connection from the connection table.

Parameters
connectionConnection to be removed.

Definition at line 410 of file Segment.cc.

410 {
412}
static bool removeValueIfExists(ContainerType &aContainer, const ElementType &aKey)

References connection(), connections_, and ContainerTools::removeValueIfExists().

Referenced by detachSocket().

Here is the call graph for this function:

◆ saveState()

ObjectState * TTAMachine::Segment::saveState ( ) const
virtual

Saves the contents of the segment to an ObjectState object.

Returns
The created ObjectState object.

Implements Serializable.

Definition at line 421 of file Segment.cc.

421 {
422
423 ObjectState* segmentState = new ObjectState(OSNAME_SEGMENT);
424 segmentState->setAttribute(OSKEY_NAME, name());
425 if (destinationSegment_ != NULL) {
426 segmentState->setAttribute(
428 }
429
430 return segmentState;
431}
void setAttribute(const std::string &name, const std::string &value)
static const std::string OSKEY_DESTINATION
ObjectState attribute key for destination segment name.
Definition Segment.hh:91

References destinationSegment_, name(), OSKEY_DESTINATION, OSKEY_NAME, OSNAME_SEGMENT, and ObjectState::setAttribute().

Referenced by TTAMachine::Bus::saveState().

Here is the call graph for this function:

◆ setName()

void TTAMachine::Segment::setName ( const std::string &  name)

Sets the name of the segment.

Parameters
nameName of the segment.
Exceptions
ComponentAlreadyExistsIf a segment with the given name already exists in the segment chain of the parent bus.
InvalidNameIf the given name is not a valid component name.

Definition at line 148 of file Segment.cc.

148 {
149 if (name == this->name()) {
150 return;
151 }
152
153 const string procName = "Segment::setName";
154
156 throw InvalidName(__FILE__, __LINE__, procName);
157 }
158
159 Bus* parent = parentBus();
160 for (int i = 0; i < parent->segmentCount(); i++) {
161 Segment* segment = parent->segment(i);
162 if (segment->name() == name) {
163 throw ComponentAlreadyExists(__FILE__, __LINE__, procName);
164 }
165 }
166
167 name_ = name;
168}

References MachineTester::isValidComponentName(), name(), name_, parentBus(), TTAMachine::Bus::segment(), and TTAMachine::Bus::segmentCount().

Here is the call graph for this function:

◆ sourceSegment()

Segment * TTAMachine::Segment::sourceSegment ( ) const

Referenced by BusDialog::onSegmentUp().

Member Data Documentation

◆ connections_

ConnectionTable TTAMachine::Segment::connections_
private

Contains all the connections to sockets.

Definition at line 109 of file Segment.hh.

Referenced by attachSocket(), connection(), connection(), detachAllSockets(), isConnectedTo(), and removeConnection().

◆ destinationSegment_

Segment* TTAMachine::Segment::destinationSegment_
private

Destination segment.

Definition at line 107 of file Segment.hh.

Referenced by hasDestinationSegment(), moveAfter(), moveBefore(), saveState(), Segment(), and ~Segment().

◆ name_

std::string TTAMachine::Segment::name_
private

Name of the segment.

Definition at line 101 of file Segment.hh.

Referenced by loadStateWithoutReferences(), and setName().

◆ OSKEY_DESTINATION

const string TTAMachine::Segment::OSKEY_DESTINATION = "destination"
static

ObjectState attribute key for destination segment name.

Definition at line 91 of file Segment.hh.

Referenced by TTAMachine::Bus::adjustSegmentChain(), ADFSerializer::busToMachine(), ADFSerializer::busToMDF(), and saveState().

◆ OSKEY_NAME

const string TTAMachine::Segment::OSKEY_NAME = "name"
static

◆ OSNAME_SEGMENT

const string TTAMachine::Segment::OSNAME_SEGMENT = "segment"
static

◆ parent_

Bus* TTAMachine::Segment::parent_
private

The parent bus.

Definition at line 103 of file Segment.hh.

Referenced by loadStateWithoutReferences(), Segment(), Segment(), and ~Segment().

◆ sourceSegment_

Segment* TTAMachine::Segment::sourceSegment_
private

Source segment.

Definition at line 105 of file Segment.hh.

Referenced by hasSourceSegment(), moveAfter(), moveBefore(), Segment(), and ~Segment().


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