editor Class Reference

#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.


Constructor & Destructor Documentation

editor::editor size_t  maxText = 10  ) 
 

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".

Parameters:
maxText number of text characters that can be stored.


Member Function Documentation

void editor::assign char  c  ) 
 

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.

Parameters:
c new character value

void editor::backward  ) 
 

Move cursor backward, if not already at the beginning.

If cursor is at beginning, leave it there. (do not generate an error)

void editor::begin  ) 
 

Moves cursor to the beginning.

This is the location of the first text character if any, or equivalent to end when text is empty.

void editor::end  ) 
 

Moves cursor to the end.

The end represents the hypothetical position which is just beyond the last character of text.

void editor::erase  ) 
 

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)

void editor::forward  ) 
 

Advances the cursor, if not already at the end.

If cursor is at end, leave it there. (do not generate an error)

void editor::insert char  c  ) 
 

Inserts a new character immediate BEFORE current cursor position.

The cursor should remain unchanged by the insertion.

Parameters:
c new character to insert.
Exceptions:
bad_alloc when out of space

void editor::rawDump std::ostream &  out  )  const
 

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.

Parameters:
out the output stream on which to insert your representation.

std::string editor::toString  )  const
 

Generates a string based on the implicit contents of the editor.

Returns:
string of zero or more characters, ordered appropriately.


Member Data Documentation

size_t editor::cursor [private]
 

The cursor position within the text.

Represented as an index to the relevant cell of the memory.

size_t editor::head [private]
 

The head of the linked list.

Represented simply as an index to the relevant cell of the memory.

std::vector<size_t> editor::memory [private]
 

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.

size_t editor::tail [private]
 

The tail of the linked list.

Represented simply as an index to the relevant cell of the memory.


Generated on Mon Feb 19 16:40:06 2007 by doxygen 1.3.4