In embedded graphics, performance is critical. A generic SPIBus class might safely encapsulate its transmit buffer as private to prevent data corruption by general code. However, the DisplayDriver is a trusted, high-performance module that requires direct access to this buffer to write pixel data rapidly, bypassing the overhead of public setter methods.
Your task is to implement this relationship:
SPIBus:int buffer[2].dump() to print the buffer contents.DisplayDriver as a friend class.DisplayDriver:void fastWrite(SPIBus& bus, int v1, int v2).v1 and v2 into bus.buffer[0] and bus.buffer[1].Program Flow:
SPIBus and DisplayDriver.N.N times.cmd.cmd is "WRITE": Read two integers, call driver.fastWrite.cmd is "SHOW": Call bus.dump().Input Format:
N.N lines: String cmd ("WRITE", "SHOW"), followed by values.Output Format:
Buffer: [ <val0> <val1> ]Example: Example 1
Input:
3
SHOW
WRITE 55 99
SHOWOutput:
Buffer: [ 0 0 ]
Buffer: [ 55 99 ]Constraints:
buffer must be private in SPIBus.DisplayDriver must access buffer directly (no public setters in SPIBus).
Input
3 SHOW WRITE 55 99 SHOW
Expected Output
Buffer: [ 0 0 ] Buffer: [ 55 99 ]