145. Fast Buffer Access

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:

  1. Class SPIBus:
    • Has a private array int buffer[2].
    • Has a public method dump() to print the buffer contents.
    • Declares DisplayDriver as a friend class.
  2. Class DisplayDriver:
    • Has a method void fastWrite(SPIBus& bus, int v1, int v2).
    • This method directly writes v1 and v2 into bus.buffer[0] and bus.buffer[1].

Program Flow:

  1. Instantiate SPIBus and DisplayDriver.
  2. Read integer N.
  3. Loop N times.
  4. Read string cmd.
  5. If cmd is "WRITE": Read two integers, call driver.fastWrite.
  6. If cmd is "SHOW": Call bus.dump().

Input Format:

  • First line: Integer N.
  • Next N lines: String cmd ("WRITE", "SHOW"), followed by values.
  • Input is provided via standard input (stdin).

Output Format:

  • For "SHOW": Buffer: [ <val0> <val1> ]
  • Each output on a new line.

Example: Example 1

Input:

3
SHOW
WRITE 55 99
SHOW

Output:

Buffer: [ 0 0 ]
Buffer: [ 55 99 ]

Constraints:

  • buffer must be private in SPIBus.
  • DisplayDriver must access buffer directly (no public setters in SPIBus).

 

 

 

Loading...

Input

3 SHOW WRITE 55 99 SHOW

Expected Output

Buffer: [ 0 0 ] Buffer: [ 55 99 ]