Fishtank
Public Member Functions | List of all members
StringScreen Class Reference

Serializable implementation of Screen using a 2D character buffer. More...

#include <string-screen.h>

Inheritance diagram for StringScreen:
Inheritance graph
[legend]
Collaboration diagram for StringScreen:
Collaboration graph
[legend]

Public Member Functions

 StringScreen (int width, int height)
 
char charAt (int col, int row) const
 Fetch the character at the given coordinate pair. More...
 
void charAtPut (int col, int row, char value)
 
void clear ()
 
std::string toString () const
 
- Public Member Functions inherited from Screen
 Screen (int width, int height)
 
int width () const
 
int height () const
 

Additional Inherited Members

- Protected Member Functions inherited from Screen
void checkCoordinates (int col, int row) const
 
- Protected Attributes inherited from Screen
int width_
 
int height_
 

Detailed Description

Serializable implementation of Screen using a 2D character buffer.

This class is designed to assist with unit testing of other classes. Although you should still write tests to make sure this class works as expected, you also shouldn't hesitate to instantiate it as part of unit tests for other classes. (Even though it's a separate unit in many senses.)

Definition at line 13 of file string-screen.h.

Constructor & Destructor Documentation

◆ StringScreen()

StringScreen::StringScreen ( int  width,
int  height 
)
explicit

Construct and initialize the buffer. Fill the screen with space (' ') characters.

Definition at line 3 of file string-screen.cpp.

Member Function Documentation

◆ charAt()

char StringScreen::charAt ( int  col,
int  row 
) const

Fetch the character at the given coordinate pair.

Parameters
col0-based column (x) index
row0-based row (y) index
Returns
character at the given position

Definition at line 7 of file string-screen.cpp.

◆ charAtPut()

void StringScreen::charAtPut ( int  col,
int  row,
char  value 
)
virtual

Write a character to the internal buffer. Updates the buffer immediately.

Parameters
col0-based column (x) index
row0-based row (y) index
valuethe character to write

Implements Screen.

Definition at line 12 of file string-screen.cpp.

◆ clear()

void StringScreen::clear ( )
virtual

Fill the screen with space (' ') characters. Updates the buffer immediately.

Implements Screen.

Definition at line 17 of file string-screen.cpp.

◆ toString()

std::string StringScreen::toString ( ) const

Serialize the buffer. Wrap the output in a border:

+----+
| hi |
+----+
Returns
a newline-separated list of lines

Definition at line 25 of file string-screen.cpp.


The documentation for this class was generated from the following files: