next up previous contents
Next: The Port Class Up: Classification of Circuit Components Previous: The Connector Class

The Wire Class

As mentioned, the Wire class is derived from the Connector class. In our model, wires connect components together and also maintain a history of signals which have travelled through them during the course of the simulation. Connections to components are achieved through the fan_out data member as inherited from the Connector class. However, in order for the class to keep track of all the signals that have passed through it, it must maintain a linked list of signals. Hence a new class, Signal_List is created for this purpose. The Signal and Signal_List classes are described later in the next chapter.

The Wire class itself is as follows:

class Wire : public Connector
{
public:
        Wire(char* = "Wire");
        Wire(Signal s[], int, char* = "Wire");
        virtual Signal  get_Signal(ckt_time);
        virtual void    send_Signal(Signal);
        void            display();
private:
        Signal_List     signals;
};

The Wire class defines two constructors. The first one accepts an optional name and simply passes that name up to its base class, Connector, for initialization. The linked list of signals is then initialized and a single signal is added to the wire to represent its initial value.

Wire::Wire(char *name) :
        Connector(name)
{
        signals.add(Signal(X, INIT_TIME));
}

The second constructor is used to actually place signals onto the wire. This constructor is invoked when a user wants to create a wire which has a series of test inputs which will later be ``hooked-up'' to a circuit. The signals are stored in an array of signals of size num. Its constructor is as follows:

Wire::Wire(Signal s[], int num, char *name) :
        Connector(name)
{
        signals.add(Signal(X, INIT_TIME));
        for (int i = 0; i < num; i++)
                signals.add(s[i]);
}

Note that in both cases the default constructor for Signal_List is implicitly called to initialize the linked list before either of the Wire constructor bodies are executed.

The get_Signal() and send_Signal() virtual methods inherited from Connector are redefined by this class. Doing this makes it possible to instantiate objects of type Wire. These two methods are discussed in the next chapter.

The final method in the Wire class is display() which provides the user with a means of seeing what values are currently in the wire. This method sends a message to the signal list asking it to dump all it signal values to the standard output.

void
Wire::display()
{
        cout << "Wire: " << name << "\n";
        signals.dump();
}

Wires will be represented by elongated rectangles in the diagrams of this report.


next up previous contents
Next: The Port Class Up: Classification of Circuit Components Previous: The Connector Class

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