Selecting which ports to display in the diagram Linking objects via ports with multiplicity Using the example in the previous API illustration if the multiplicity of both ports is 10, you would link the objects as follows: for (int i+0; i a.getSrcAt(i)->setItsJ(b.getMonAt(i)->getItsJ()); b.getMonAt(i)->setItsI(a.getSRcAt(i)->getItsI()); } Advanced-level tasks This section describes the advanced-level APIs used when programming with ports. You use these APIs when the code generator cannot determine how to instantiate the ports. This situation occurs when the port multiplicity is *. Creating ports programmatically By default, ports are created by value.
However, if at design time you do not know how many ports there will be (multiplicity of *), you can create the ports programmatically. For example, to instantiate 10 of the src ports, use the following call: for (int i=0; i // instantiate and add to the container of the owner newSrc(); } Linking behavioral ports to their owning instance Similarly, if you do not know what the multiplicity of the behavioral port at design time, you can specify it programmatically. Behavioral ports are connected to their owning instance using the method connect[ClassName] . For example, to connect behavioral port p to its owner object a (of type A ), use the following call:
a.getP()->connectA(a); If the ports in previous API illustration are behavioral, you would use the following code: for (int i=0; i newSrc(); //hooks the class so it takes care of the messages getSrcAt(i)->connectA(this); } For more efficiency, use the following code: for (int i=0; i newSrc()->connectA(this); Rational Rhapsody 103