# cGate Class Reference
[Simulation core classes]

`#include <cgate.h>`

Inheritance diagram for cGate:

List of all members.

## Detailed Description

Represents a module gate.

cGate object are created and managed by modules; the user typically does not want to directly create or destroy cGate objects. However, they are important if a simple module algorithm needs to know about its surroundings.

## Public Member Functions

virtual bool | deliver (cMessage *msg, simtime_t at)
Constructors, destructor, assignment.
| cGate (const cGate &gate)
| cGate (const char *name, char tp)
virtual | ~cGate ()
cGate & | operator= (const cGate &gate)
Redefined cObject member functions
virtual cPolymorphic * | dup () const
virtual void | forEachChild (cVisitor *v)
virtual std::string | info () const
virtual const char * | fullName () const
virtual void | setName (const char *s)
virtual std::string | fullPath () const
virtual const char * | fullPath (char *buffer, int bufsize) const
virtual void | writeContents (std::ostream &os)
Setting up the gate.
void | setOwnerModule (cModule *m, int gid)
void | setIndex (int sn, int vs)
Connecting the gate.
void | connectTo (cGate *g, cChannel *chan=NULL)
void | disconnect ()
void | setFrom (cGate *g)
void | setTo (cGate *g)
Accessing the channel object.
void | setChannel (cChannel *ch)
cChannel * | channel () const
Information about the gate.
char | type () const
cModule * | ownerModule () const
int | id () const
bool | isVector () const
int | index () const
int | size () const
Setting and getting link attributes. DEPRECATED methods.
void | setLink (cChannelType *l)
void | setDelay (cPar *p)
void | setError (cPar *p)
void | setDataRate (cPar *p)
cPar * | delay () const
cPar * | error () const
cPar * | datarate () const
Transmission state.
bool | isBusy () const
simtime_t | transmissionFinishes () const
Gate connectivity.
cGate * | fromGate () const
cGate * | toGate () const
cGate * | sourceGate () const
cGate * | destinationGate () const
int | routeContains (cModule *m, int g=-1)
bool | isConnectedOutside () const
bool | isConnectedInside () const
bool | isConnected () const
bool | isRouteOK () const
Display string.
cDisplayString & | displayString ()
void | setDisplayString (const char *dispstr, bool immediate=true)

## Friends

class | cModule

## Constructor & Destructor Documentation

cGate::cGate | ( | const cGate & | gate | ) |

| Copy constructor.

cGate::cGate | ( | const char * | name,
|  | char | tp
| ) | `[explicit]`

| Constructor.

virtual cGate::~cGate | ( |  | ) | `[virtual]`

| Destructor.

## Member Function Documentation

cChannel* cGate::channel | ( |  | ) | const`[inline]`

| Returns the channel object attached to this gate, or NULL if there's no channel.

void cGate::connectTo | ( | cGate * | g,
|  | cChannel * | chan = `NULL`
| ) |

Connects the gate to another gate, optionally using the given channel object.

This method can be used to manually create connections for dynamically created modules. If no channel object is specified (or NULL pointer is passed), the existing channel object (assigned via setChannel()) is preserved.

If the gate is already connected, an error will occur. The g argument cannot be NULL, that is, you cannot use this function to disconnect a gate. Use disconnect() instead.

cPar* cGate::datarate | ( |  | ) | const

| DEPRECATED! Use channel() and cBasicChannel::datarate() instead. If the gate has a channel, calls datarate() on it. The channel must be of class cBasicChannel or one subclassed from it. If the gate has no channel, the method returns NULL.

cPar* cGate::delay | ( |  | ) | const

| DEPRECATED! Use channel() and cBasicChannel::delay() instead. If the gate has a channel, calls delay() on it. The channel must be of class cBasicChannel or one subclassed from it. If the gate has no channel, the method returns NULL.

virtual bool cGate::deliver | ( | cMessage * | msg,
|  | simtime_t | at
| ) | `[virtual]`

| This function is called internally by the send() functions and channel classes' deliver() to deliver the message to its destination. A false return value means that the message object should be deleted by the caller. (This is used e.g. with parallel simulation, for messages leaving the partition.)

cGate* cGate::destinationGate | ( |  | ) | const

| Return the ultimate destination of the series of connections (the route) that contains this gate.

void cGate::disconnect | ( |  | ) |

| Disconnects the gate. It also destroys the associated channel object if one has been set (see setChannel()). disconnect() must be invoked on the source gate ("from" side) of the connection. The method has no effect if the gate is not connected.

cDisplayString& cGate::displayString | ( |  | ) |

| Returns the display string for the gate, which in practice affects the apprearance of the connection for which this gate is the source.

virtual cPolymorphic* cGate::dup | ( |  | ) | const`[inline, virtual]`

| Creates and returns an exact copy of this object. See cObject for more details. Reimplemented from cObject.

cPar* cGate::error | ( |  | ) | const

| DEPRECATED! Use channel() and cBasicChannel::error() instead. If the gate has a channel, calls error() on it. The channel must be of class cBasicChannel or one subclassed from it. If the gate has no channel, the method returns NULL.

virtual void cGate::forEachChild | ( | cVisitor * | v | ) | `[virtual]`

| Calls v->visit(this) for each contained object. See cObject for more details. Reimplemented from cObject.

cGate* cGate::fromGate | ( |  | ) | const`[inline]`

| Returns the previous gate in the series of connections (the route) that contains this gate, or a NULL pointer if this gate is the first one in the route. (E.g. for a simple module output gate, this function will return NULL.)

virtual const char* cGate::fullName | ( |  | ) | const`[virtual]`

| Returns the full name of the gate, which is name() plus the index in square brackets (e.g. "out[4]"). Redefined to add the index. Reimplemented from cObject.

virtual const char* cGate::fullPath | ( | char * | buffer,
|  | int | bufsize
| ) | const`[virtual]`

| The original fullPath() method is redefined to hide the internal array (a cArray) used to store the gate objects. Reimplemented from cObject.

virtual std::string cGate::fullPath | ( |  | ) | const`[virtual]`

| Redefined. (Reason: a C++ rule that overloaded virtual methods must be redefined together.) Reimplemented from cObject.

int cGate::id | ( |  | ) | const`[inline]`

| Returns gate ID, the position of the gate in the array of all gates of the module.

int cGate::index | ( |  | ) | const`[inline]`

| If the gate is part of a gate vector, returns the gate's index in the vector. Otherwise, it returns 0.

virtual std::string cGate::info | ( |  | ) | const`[virtual]`

| Produces a one-line description of object contents into the buffer passed as argument. See cObject for more details. Reimplemented from cPolymorphic.

bool cGate::isBusy | ( |  | ) | const

| If the gate has a channel subclassed from cBasicChannel, the methods calls isBusy() on it and returns the result. Otherwise, it returns false.

bool cGate::isConnected | ( |  | ) | const

| Returns true if the gate fully connected. For a compound module gate this means both isConnectedInside() and isConnectedOutside() are true; for a simple module, only isConnectedOutside() is checked.

bool cGate::isConnectedInside | ( |  | ) | const

| Returns true if the gate (of a compound module) is connected inside (i.e. to one of its submodules). This means that for an input gate, toGate() must be non-NULL; for an output gate, fromGate() must be non-NULL.

bool cGate::isConnectedOutside | ( |  | ) | const

| Returns true if the gate is connected outside (i.e. to one of its sibling modules or to the parent module). This means that for an input gate, fromGate() must be non-NULL; for an output gate, toGate() must be non-NULL.

bool cGate::isRouteOK | ( |  | ) | const

| Returns true if the route that this gate is in is complete, that is, if it starts and arrives at a simple module.

bool cGate::isVector | ( |  | ) | const`[inline]`

| Returns true if the gate is part of a gate vector.

cGate& cGate::operator= | ( | const cGate & | gate | ) |

| Assignment operator. The name member doesn't get copied; see cObject's operator=() for more details.

cModule* cGate::ownerModule | ( |  | ) | const`[inline]`

| Returns a pointer to the owner module of the gate.

int cGate::routeContains | ( | cModule * | m,
|  | int | g = `-1`
| ) |

| Determines if a given module is in the route containing this gate.

void cGate::setChannel | ( | cChannel * | ch | ) |

| Assigns a channel object to this gate. The channel object stores connection attributes such as delay, bit error rate or data rate. See also connectTo().

void cGate::setDataRate | ( | cPar * | p | ) |

| DEPRECATED! Use cBasicChannel and setChannel() instead. Creates a channel (of class cBasicChannel) if the gate does not have one, and calls setDataRate() on it. If the gate already has a channel, it must be of class cBasicChannel or one subclassed from it.

void cGate::setDelay | ( | cPar * | p | ) |

| DEPRECATED! Use cBasicChannel and setChannel() instead. Creates a channel (of class cBasicChannel) if the gate does not have one, and calls setDelay() on it. If the gate already has a channel, it must be of class cBasicChannel or one subclassed from it.

void cGate::setDisplayString | ( | const char * | dispstr,
|  | bool | immediate = `true`
| ) |

| DEPRECATED. Use displayString() and cDisplayString methods instead.

void cGate::setError | ( | cPar * | p | ) |

| DEPRECATED! Use cBasicChannel and setChannel() instead. Creates a channel (of class cBasicChannel) if the gate does not have one, and calls setError() on it. If the gate already has a channel, it must be of class cBasicChannel or one subclassed from it.

void cGate::setFrom | ( | cGate * | g | ) |

| DEPRECATED - use connectTo() instead! Redirect gates. This method is mostly used internally during network setup to create the connections.

void cGate::setIndex | ( | int | sn,
|  | int | vs
| ) |

| Specifies that the gate is at index sn in a gate array of size vs. This function should not be directly called by the user.

void cGate::setLink | ( | cChannelType * | l | ) |

| DEPRECATED! Use cChannel/cBasicChannel and setChannel() instead. Sets the parameters of the link to those specified by the link type.

virtual void cGate::setName | ( | const char * | s | ) | `[virtual]`

| Sets object's name. Redefined to update the stored fullName string. Reimplemented from cObject.

void cGate::setOwnerModule | ( | cModule * | m,
|  | int | gid
| ) |

| Specifies that the gate is owned by module m, and it is at index g in the gate vector. This function should not be directly called by the user.

void cGate::setTo | ( | cGate * | g | ) |

| DEPRECATED - use connectTo() instead! Redirect gates. This method is mostly used internally during network setup to create the connections.

int cGate::size | ( |  | ) | const`[inline]`

| If the gate is part of a gate vector, returns the size of the vector. For non-vector gates it returns 1. Zero-size vectors are represented by a single gate whose size() returns 0. The gate vector size can also be obtained by calling the cModule::gateSize().

cGate* cGate::sourceGate | ( |  | ) | const

| Return the ultimate source of the series of connections (the route) that contains this gate.

cGate* cGate::toGate | ( |  | ) | const`[inline]`

| Returns the next gate in the series of connections (the route) that contains this gate, or a NULL pointer if this gate is the last one in the route. (E.g. for a simple module input gate, this function will return NULL.)

simtime_t cGate::transmissionFinishes | ( |  | ) | const

| If the gate has a channel subclassed from cBasicChannel, the methods calls transmissionFinishes() on it and returns the result. Otherwise, it returns 0.0.

char cGate::type | ( |  | ) | const`[inline]`

| Returns the gate's type: 'I' for input and 'O' for output.

virtual void cGate::writeContents | ( | std::ostream & | os | ) | `[virtual]`

| Writes textual information about this object to the stream. See cObject for more details. Reimplemented from cObject.

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

- cgate.h