#include <editor.h>
Public Member Functions | |
editor (size_t maxText=10) | |
constructs a new editor instance. | |
void | forward () |
Advances the cursor, if not already at the end. | |
void | backward () |
Move cursor backward, if not already at the beginning. | |
void | begin () |
Moves cursor to the beginning. | |
void | end () |
Moves cursor to the end. | |
void | assign (char c) |
Reassigns character at current cursor position. | |
void | insert (char c) |
Inserts a new character immediate BEFORE current cursor position. | |
void | erase () |
Erases the character at the current cursor position (if any). | |
std::string | toString () const |
Generates a string based on the implicit contents of the editor. | |
void | rawDump (std::ostream &out) const |
Create an appropriate vertical dump of your entire memory. | |
Private Attributes | |
std::vector< size_t > | memory |
We will use a vector of size_t objects as our model of memory. | |
size_t | head |
The head of the linked list. | |
size_t | tail |
The tail of the linked list. | |
size_t | cursor |
The cursor position within the text. |
|
constructs a new editor instance. Initial contents should represent empty string. Initial capacity, measured in text characters, set by parameter. The cursor should be at the "end".
|
|
Reassigns character at current cursor position. The cursor should remain unchanged by the insertion. If cursor is at end of list, should not do anything.
|
|
Move cursor backward, if not already at the beginning. If cursor is at beginning, leave it there. (do not generate an error) |
|
Moves cursor to the beginning. This is the location of the first text character if any, or equivalent to end when text is empty. |
|
Moves cursor to the end. The end represents the hypothetical position which is just beyond the last character of text. |
|
Erases the character at the current cursor position (if any). After the operation, the new cursor position should be the one which follows the deleted character. If current cursor position was end, operation should not do anything (do not generate an error, though) |
|
Advances the cursor, if not already at the end. If cursor is at end, leave it there. (do not generate an error) |
|
Inserts a new character immediate BEFORE current cursor position. The cursor should remain unchanged by the insertion.
|
|
Create an appropriate vertical dump of your entire memory. Ideally it should be formatted so that slots that are "pointers" are printed as integers and slots that are "data" are printed as characters.
|
|
Generates a string based on the implicit contents of the editor.
|
|
The cursor position within the text. Represented as an index to the relevant cell of the memory. |
|
The head of the linked list. Represented simply as an index to the relevant cell of the memory. |
|
We will use a vector of size_t objects as our model of memory. The initial size should be specified as part of the constructor and then never changed. The advantage of using a vector is that the at() method provides error-checking for out of bounds indices. |
|
The tail of the linked list. Represented simply as an index to the relevant cell of the memory. |