- A Logic Circuit Simulation Library in C++





(Topic Guide) Reading bus line states


The lines states of lcs::Bus and lcs::InputBus objects can be read using the overloaded operator[] of the class lcs::InputBus (recollect that lcs::Bus is derived from lcs::InputBus). The usage is very similar to how one would read the element values from a standard data type array. The overloaded operator returns a const lcs::LineState value corresponding the state of bus line indicated by the index passed to the operator []. However, since a const LineState value, and not a non-const reference to the LineState value is returned, one cannot set the line states using the operator [].

An example of reading the line states from the lines of a bus is as follows.

lcs::Bus<8> bus(128); // The bus lines are initialised to a binary equivalent of the decimal integer 
                      // 128.

lcs::LineState bit0 = bus[0], bit5 = bus[5]; // Reading the line states of the bus.

bus[1] = lcs::HIGH; // Error!! Line states cannot be set using lcs::InputBus::operator[].

Copyright © 2006, 2007 Siva Chandra