Top Up Prev Next Bottom Contents Index Search

6.1 Class GenericPort

The class GenericPort is a base class that provides common elements between class PortHole and class MultiPortHole. Any GenericPort object can be assumed to be either one or the other; we recommend avoiding deriving any new objects directly from GenericPort. GenericPort is derived from class NamedObj . GenericPort provides several basic facilities: aliases, which specify that another GenericPort should be used in place of this port, types, which specify the type of data to be moved by the port, and typePort, which specifies that this port has the same type as another port. When a GenericPort is destroyed, any alias or typePort pointers are automatically cleaned up, so that other GenericPorts are never left with dangling pointers.

The type() and typePort() functions belong to GenericPort, not PortHole, because multiportholes have a declared type and can be type-equivalenced to other portholes. However, type resolution is strictly a PortHole notion. Multiportholes need no resolved type because they do not themselves transport particles, and indeed the concept would be ambiguous since the member ports of a multiporthole might have different resolved types. The declared type of a multiporthole is automatically assigned to its children, and its children are automatically brought into any type equivalence set the multiporthole is made part of. Thereafter, type resolution considers only the member portholes and not the multiporthole itself.

6.1.1 GenericPort query functions

virtual int isItInput () const; 
virtual int isItOutput () const;
virtual int isItMulti () const;
Each of the above functions returns TRUE (1) or FALSE (0).

StringList print (int verbose = 0) const; 
Print human-readable information on the GenericPort.

DataType type () const; 
Return my DataType. This may be one of the DataType values associated with Particle classes, or the special type `ANYTYPE', which indicates that the type must be resolved during setup. Note that type() returns the port's declared type, as supplied to setPort(). This is not necessarily the datatype that will be chosen to pass through the port at runtime. That type is available from the PortHole::resolvedType() function.

GenericPort* alias() const; 
Return my alias, or a null pointer if I have no alias. Generally, Galaxy portholes have aliases and Star portholes do not, but this is not a strict requirement.

GenericPort* aliasFrom() const; 
Return the porthole that I am the alias for (a null pointer if none). It is guaranteed that if gp is a pointer to GenericPort and if gp->alias() is non-null, then the boolean expression
gp->alias()->aliasFrom() == gp
is always true.

bitWord attributes() const; 
Return my attributes. Attributes are a series of bits.

GenericPort& realPort(); 
const GenericPort& realPort() const;
Return the real port after resolving any aliases. If I have no alias, then a reference to myself is returned.

GenericPort* typePort() const; 
Return another generic port that is constrained to have the same type as me (0 if none). If a non-null value is called, successive calls will form a circular linked list that always returns to its starting point; that is, the loop

void printLoop(GenericPort& g) { 
if (g->typePort()) {
GenericPort* gp = g;
while (gp->typePort() != g) {
cout << gp->fullName() << "\back n";
gp = gp->typePort();
is guaranteed to terminate and not to dereference a null pointer.

inline int hidden(const GenericPort& p) 
IMPORTANT: hidden is not a member function of GenericPort, but is a "plain function". It returns TRUE if the port in question has the HIDDEN attribute.

6.1.2 Other GenericPort public members

virtual PortHole& newConnection(); 
Return a reference to a porthole to be used for new connections. Class PortHole uses this one unchanged; MultiPortHole has to create a new member PortHole.

GenericPort& setPort(const char* portName, Block* blk, DataType typ=FLOAT); 
Set the basic PortHole parameters: the name, parent, and data type.

void inheritTypeFrom(GenericPort& p); 
Link to another port for determining the type of `ANYTYPE' connections. The "inheritance" relationship is actually a completely symmetric constraint, and so this function would have been better named sameTypeAs(). Any number of portholes can be tied together by inheritTypeFrom() calls. Internally this is represented by chaining all the members of such a type equivalence set into a circular loop, which can be walked via typePort() calls. If a multiporthole is made part of a type equivalence set, all its current and future children become part of the set automatically.

virtual void connect(GenericPort& destination,int numberDelays,
const char* initDelayValues = 0);
Connect me with the indicated peer.

bitWord setAttributes(const Attribute& attr); 
Set my attributes (some bits are turned on and others are turned off).

void setAlias (GenericPort& gp); 
Set gp to be my alias. The aliasFrom pointer of gp is set to point to me.

6.1.3 GenericPort protected members

GenericPort* translateAliases(); 
The above is a protected function. If this function is called on a port with no alias, the address of the port itself is returned; otherwise, alias()->translateAliases() is returned.

Top Up Prev Next Bottom Contents Index Search

Copyright © 1990-1997, University of California. All rights reserved.