next up previous contents
Next: The Port_List Class Up: The Port Class Previous: The Port Class

The Input and Output Class

The Input and Output classes are almost the same with just one minor difference, as can be seen from the following class declarations:

class Input : public Port
{
public:
        Input(Component *, Connector &, char* = "Input");
        virtual void    send_Signal(Signal);
};

class Output : public Port
{
public:
        Output(Component *, Connector &, char* = "Output");
};

Input inherits Port's virtual get_Signal() method, but defines its own send_Signal() method. This is because a signal cannot be sent out through an input port. Therefore, this method outputs a warning whenever an attempt is made to send a signal from an input port. Output, however, inherits both virtual methods from Port, so it is possible to both send a signal to and get a signal from an output port. This is useful to model bidirectionality.

The constructors for the two ports are trivially implemented. The Port base constructor is first called with the appropriate arguments and the I/O port is added to the corresponding Port_List of the component.

Input::Input(Component *cmp, Connector &con, char *name) :
        Port(cmp, con, name)
{
        cmp->I_List.add(this);
}

Output::Output(Component *cmp, Connector &con, char *name) :
        Port(cmp, con, name)
{ 
        cmp->O_List.add(this);
}



Donald Craig
Sat Jul 13 16:02:11 NDT 1996