Port mapping for C++ (C++ code)
A Port is an Attribute or Role dictionary item that is set up as a Port, that is, the Port check box is selected on the Property Pages of the Attribute or Role. For information about Attribute and Role mapping, see
This topic demonstrates how ACS generates C++ code for port forwarding and wiring that you have modeled using composite structure diagrams.
If you generate code for the preceding example, ACS generates Class C with three composite parts to represent the parts p0, p1 and p2 on the structure diagram:
class C
{
public:
C();
private:
PA p0;
PA p1;
PB p2;
};
In addition, the default constructor for class C connects (or wires up) p1 to p2 and instructs p0 that it has no connection:
C::C() :
p0(0),
p1(&p2)
{
}
The part p0 is not wired because ACS generates Class PA with a constructor that enables it to be wired to an instance of a class of type PB:
PA::PA(PB* initial_p) :
p(initial_p)
{
}
When you define ports in the composite structure, ACS generates code to wire those ports together and forward calls between those ports. This is illustrated in the following example.
In this example, ACS generates Class A as you might expect, with the m_PortA port generated as a reference of type Interface1:
class A
{
…
A(Interface1 & initial_m_PortA);
Interface1 & m_PortA;
};
When Class A is used in the context of Q there is more information known about it; ACS generates a class named A_Q_a (so named because it is the instance 'a' of Class 'A' in the context of 'Q') that includes code to wire the m_PortA port up:
class A_Q_a : public A
{
…
A_Q_a(Interface1& init_m_PortA_d);
Interface1_ProxyOnlyOne m_PortA_Q_a;
};
The Interface1_ProxyOnlyOne type is a proxy class that forwards calls to another single port or part. ACS generates additional proxies when a port needs to forward calls to a known number of other ports or parts, or an unbounded number.
Likewise, ACS generates a special version of Class B that can receive calls to its port and forward those calls to the c part's port. The c part's port is not a behavior port so requires no special version of its class C; its port just passes calls on to its containing class, which implements Interface1.