libLCS Tutorial and User Guide


This section is under construction. See also the Examples of Using libLCS for more information.

1. Display the line states of lcs::Bus and lcs::InputBus objects
2. Setting and reading the line states of a bus


1. Display the line states of lcs::Bus and lcs::InputBus objects

Both lcs::Bus and lcs::InputBus classes are provided with an overloaded operator '<<' which can be used to display the line states onto the std::stdout device. The usage is very similar to how one would use the '<<' operator for display of the standard data types.

lcs::Bus<3> bus;
cout << bus;

The above code will print xxx on the stdout device. Each x denotes the lcs::UNKNOWN state of the 3 lines of the bus. Similarly, the following code will print 101 on the stdout device.

lcs::Bus<3> bus;

bus = 5;
cout << bus;


2. Setting and reading the line states of a bus

Line states can be set only for lcs::Bus objects. lcs::InputBus objects are readonly busses. Both these classes are provided with overloaded '[]' operators for reading and setting the line states. (Line states can only be read from an lcs::InputBus object.) In case of an lcs::InputBus object, the overloaded '[]' operator returns a const lcs::LineState variable, corresponding to the line index passed to the operator. Hence, the line state can be read as follows.

lcs::InputBus<8> bus;
lcs::LineState bit0 = bus[0], bit5 = bus[5];

in case of a lcs::Bus object, a reference to a lcs::Line object corresponding to the line index passed to the operator is returned . The lcs::Line class is provided with overloaded assignment operators which facilitates an intuitive way to set the lines states of a lcs::Bus object as follows.

lcs::Bus<3> bus;
b[0] = lcs::HIGH; 
b[1] = lcs::LOW;

The lcs::Line class and the lcs::LineState enumerations are also provided with bitwise logical operators which facilitate bitwise logic operations like in the following snippet (see the API reference of lcs::Line and lcs::LineState for more information):

lcs::Bus<5> bus;
lcs::LineState result = (bus[0] & bus[1]) ^ (bus[2] | bus[3]) & (bus[4] ^ bus[0]);

An overloaded assignment operator for lcs::Bus class is provided using which one can assign integers directly to busses. The binary equivalent of the integer is mapped in a little-endian format onto the lines of the bus. Note that, throughout libLCS, the bus lines are conceptually understood to be little-endian with lower indices representing the LSB bits. An example of assigning integers to an lcs::Bus object is as follows.

lcs::Bus<4> bus;

bus = 13;
cout << bus;

The above code snippet will print 1101 on the stdout device.


Generated on Wed Sep 20 00:49:12 2006 for libLCS by  doxygen 1.4.7