Main Page | Modules | Alphabetical List | Compound List | File List | Compound Members | Related Pages

infinite_tape< T > Class Template Reference
[TuringMachineDefinition]

an auto-expanding wrapper for an std::list. More...

#include <infinite_tape.hpp>

Collaboration diagram for infinite_tape< T >:

Collaboration graph
[legend]
List of all members.

Public Types

enum  direction { left, right, do_nothing, halt_move }

Public Member Functions

 infinite_tape ()
 default Constructor.

 infinite_tape (T new_default_value)
 construct a tape of start_size with each value set to default value.

 infinite_tape (typename std::list< T >::size_type new_size, T new_default_value)
 construct a tape of new_size with each value set to default_value.

 infinite_tape (const infinite_tape< T > &rhs)
 copy constructor.

const infinite_tape< T > & operator= (const infinite_tape< T > &rhs)
 assignment operator.

 ~infinite_tape ()
 trivial destructor

read () const
 Read the value held by the cell under the read-head.

void clear ()
 Clears the tape.

void write (T to_write)
 Writes a value to the current location on the tape.

void move (direction which)
 Move the head one position to the left xor to the right of the current position.

void reset_head ()
 moves the read-head to the cardinal position.

bool is_blank () const
 Checks if the tape is blank.

bool is_contiguous () const
 Are the symbols on the tape in the format ()*()*()*?.

bool on_blank () const
 Is the read-head on a blank?.

bool symbols_to_direction (direction which) const
 Are there any symbols to the of the read-head?.

bool in_standard_position () const
 Is the tape in standard position?.

std::list< T >::size_type count_occurrences (T to_count) const
 How many occurrences are there of to_count on the tape?.

void show (std::ostream &out) const
 provides the old-style display using a very simple pre-defined inflexible format.

template<typename delim_type1, typename delim_type2, typename delim_type3, typename delim_type4, typename delim_type5, typename delim_type6, typename delim_type7, typename delim_type8> void show (std::ostream &out, const delim_type1 &before_delim, const delim_type2 &between_delim, const delim_type3 &after_delim, const delim_type4 &before_cardinal, const delim_type5 &after_cardinal, const delim_type6 &before_head, const delim_type7 &after_head, const delim_type8 &blank_delim, bool extra_between_delims) const
 wow, could it possibly get more complicated?.

void reset ()
 Clears the tape to setting each location to the default value.

void setCurrentLocation (typename std::list< T >::iterator location)
 Sets the read-head to location.

defaultValue ()
 default_value accessor.

std::list< T >::iterator currentLocation ()
 Returns the read-head.

std::list< T >::iterator begin ()
 Returns the beginning of the tape.

std::list< T >::const_iterator begin () const
 Returns the beginning of the tape.

bool find (typename std::list< T >::iterator find)
 Finds an iterator in the tape.

bool repeatConfigRight (infinite_tape< T > &rhs, typename std::list< T >::iterator lhsLeftBound)
 tests for a simple loop repeat configuration in rhs.

bool repeatConfigLeft (infinite_tape< T > &rhs, typename std::list< T >::iterator lhsRightBound)
 tests for a simple loop repeat configuration in rhs (mirror of repeatConfigRight).

void checkIteratorLeft (typename std::list< T >::iterator leftEdge)
 Expands the tape if the iterator is at the left edge of the tape.

void checkIteratorRight (typename std::list< T >::iterator rightEdge)
 Expands the tape if the iterator is at the right edge of the tape.


Protected Member Functions

void tape_check (direction which)
 check to see if tape needs to be expanded and call expansion function if so.

void expand_tape (direction which, typename std::list< T >::size_type how_many)
 Expands the tape.


Protected Attributes

std::list< T > tape
 the cells of the tape

std::list< T >::iterator current
 location of read-head on tape

std::list< T >::iterator cardinal
 location of read-head on tape

std::list< T >::size_type counter
 number of moves made counter.

default_value
 default value when creating a new cell

std::list< T >::size_type non_blank_count
 count the number of non-blank symbols


Static Protected Attributes

const std::list< T >::size_type start_size = 101
 arbitrary start size of tape.


Detailed Description

template<typename T>
class infinite_tape< T >

an auto-expanding wrapper for an std::list.

provides constant amortised time operations assumes small types for storage (e.g. int, bool, etc.) since parameters are passed by value

Definition at line 62 of file infinite_tape.hpp.


Constructor & Destructor Documentation

template<typename T>
infinite_tape< T >::infinite_tape  )  [inline]
 

default Constructor.

Author:
Owen Kellett

Definition at line 71 of file infinite_tape.hpp.

template<typename T>
infinite_tape< T >::infinite_tape new_default_value  )  [inline]
 

construct a tape of start_size with each value set to default value.

set current iterators to the middle element, start at this index, and counter to zero

Parameters:
new_default_value default value for tape
Author:
Kyle Ross

Definition at line 92 of file infinite_tape.hpp.

template<typename T>
infinite_tape< T >::infinite_tape typename std::list< T >::size_type  new_size,
new_default_value
[inline]
 

construct a tape of new_size with each value set to default_value.

set current iterators to the middle element, start at this index, and counter to zero

Parameters:
new_size initial size of tape
new_default_value default value of tape
Author:
Kyle Ross

Definition at line 114 of file infinite_tape.hpp.

template<typename T>
infinite_tape< T >::infinite_tape const infinite_tape< T > &  rhs  )  [inline]
 

copy constructor.

Precondition:
rhs is a valid tape
Postcondition:
*this is a tape functionally equivalent to rhs
Parameters:
rhs valid infinite_tape to copy
Author:
Kyle Ross

Definition at line 136 of file infinite_tape.hpp.

template<typename T>
infinite_tape< T >::~infinite_tape  )  [inline]
 

trivial destructor

Author:
Kyle Ross

Definition at line 179 of file infinite_tape.hpp.


Member Function Documentation

template<typename T>
std::list<T>::const_iterator infinite_tape< T >::begin  )  const [inline]
 

Returns the beginning of the tape.

Returns:
a const_iterator pointing to the beginning of the tape
Author:
Owen Kellett

Definition at line 871 of file infinite_tape.hpp.

template<typename T>
std::list<T>::iterator infinite_tape< T >::begin  )  [inline]
 

Returns the beginning of the tape.

Returns:
an iterator pointing to the beginning of the tape
Author:
Owen Kellett

Definition at line 861 of file infinite_tape.hpp.

Referenced by tapeBoundsTriple< T >::tapeBoundsTriple().

template<typename T>
void infinite_tape< T >::checkIteratorLeft typename std::list< T >::iterator  leftEdge  )  [inline]
 

Expands the tape if the iterator is at the left edge of the tape.

Parameters:
leftEdge location on the tape to check
Author:
Owen Kellett

Definition at line 1087 of file infinite_tape.hpp.

template<typename T>
void infinite_tape< T >::checkIteratorRight typename std::list< T >::iterator  rightEdge  )  [inline]
 

Expands the tape if the iterator is at the right edge of the tape.

Parameters:
rightEdge location on the tape to check
Author:
Owen Kellett

Definition at line 1102 of file infinite_tape.hpp.

template<typename T>
void infinite_tape< T >::clear  )  [inline]
 

Clears the tape.

Author:
Kyle Ross

Definition at line 200 of file infinite_tape.hpp.

template<typename T>
std::list<T>::size_type infinite_tape< T >::count_occurrences to_count  )  const [inline]
 

How many occurrences are there of to_count on the tape?.

Parameters:
to_count symbol to count on the tape
Returns:
number of occurences of to_count on the tape
Author:
Kyle Ross

Definition at line 376 of file infinite_tape.hpp.

template<typename T>
std::list<T>::iterator infinite_tape< T >::currentLocation  )  [inline]
 

Returns the read-head.

Returns:
an iterator pointing to the current tape position
Author:
Owen Kellett

Definition at line 851 of file infinite_tape.hpp.

template<typename T>
T infinite_tape< T >::defaultValue  )  [inline]
 

default_value accessor.

Returns:
the default value used for the tape
Author:
Owen Kellett

Definition at line 841 of file infinite_tape.hpp.

template<typename T>
void infinite_tape< T >::expand_tape direction  which,
typename std::list< T >::size_type  how_many
[inline, protected]
 

Expands the tape.

Postcondition:
the tape has been expanded by how_many to the left if which==left xor has been expanded how_many to the right if which==right
Parameters:
which direction to expand
how_many number of additional cells to add
Author:
Kyle Ross

Definition at line 1174 of file infinite_tape.hpp.

Referenced by direction::checkIteratorLeft(), direction::checkIteratorRight(), and direction::tape_check().

template<typename T>
bool infinite_tape< T >::find typename std::list< T >::iterator  find  )  [inline]
 

Finds an iterator in the tape.

used mainly for debugging purposes

Parameters:
find iterator to search for
Returns:
true if find points to a location in the tape
Author:
Owen Kellett

Definition at line 883 of file infinite_tape.hpp.

template<typename T>
bool infinite_tape< T >::in_standard_position  )  const [inline]
 

Is the tape in standard position?.

(not on_blank()) and is_contiguous() and (symbols_to_direction(left) xor symbols_to_direction(right)); the xor'ing is done by checking that the answers to "are there symbols to the left of the read head?" and "are there symbols to the right of the read head?" are different ... which ensures that there are symbols in exactly one direction and not the other ... sneaky, eh?

Precondition:
all requirements for is_blank, is_continuous, symbols_to(left), and symbols_to(right) are met
Postcondition:
true is returned iff the above conditional is satisfied, false else
Author:
Kyle Ross

Definition at line 365 of file infinite_tape.hpp.

template<typename T>
bool infinite_tape< T >::is_blank  )  const [inline]
 

Checks if the tape is blank.

Returns:
true iff tape is blank else false
Author:
Kyle Ross

Definition at line 276 of file infinite_tape.hpp.

template<typename T>
bool infinite_tape< T >::is_contiguous  )  const [inline]
 

Are the symbols on the tape in the format ()*()*()*?.

Precondition:
the tape has zero or more cells
Postcondition:
the function returns true iff the tape's symbols match the regexp above, false else; the minimal number of symbols required to determine the return-value are scanned
Author:
Kyle Ross

Definition at line 287 of file infinite_tape.hpp.

Referenced by direction::in_standard_position().

template<typename T>
void infinite_tape< T >::move direction  which  )  [inline]
 

Move the head one position to the left xor to the right of the current position.

maintains the invariant that the head iterator refers to a valid tape square makes sure that there is tape to the left of the current position to move to then moves

Precondition:
current refers to a valid location on the tape
Postcondition:
current refers to a valid location on the tape; if which==do_nothing then current remains unchanged; if which==left then current is one to the left of its previous position and if which==right then current is one to the right of its previous position, adding additional cells to the tape as necessary to maintain its theoretical infinity
Parameters:
which direction to move the read head
Author:
Kyle Ross

Definition at line 235 of file infinite_tape.hpp.

Referenced by transition_result::perform_transition().

template<typename T>
bool infinite_tape< T >::on_blank  )  const [inline]
 

Is the read-head on a blank?.

Returns:
true is returned iff the read-head is scanning a blank, false else
Author:
Kyle Ross

Definition at line 318 of file infinite_tape.hpp.

Referenced by direction::in_standard_position().

template<typename T>
const infinite_tape<T>& infinite_tape< T >::operator= const infinite_tape< T > &  rhs  )  [inline]
 

assignment operator.

Author:
Kyle Ross

Definition at line 152 of file infinite_tape.hpp.

template<typename T>
T infinite_tape< T >::read  )  const [inline]
 

Read the value held by the cell under the read-head.

Returns:
the value held by the cell under the read-head
Author:
Kyle Ross

Definition at line 191 of file infinite_tape.hpp.

Referenced by transition_result::perform_transition().

template<typename T>
bool infinite_tape< T >::repeatConfigLeft infinite_tape< T > &  rhs,
typename std::list< T >::iterator  lhsRightBound
[inline]
 

tests for a simple loop repeat configuration in rhs (mirror of repeatConfigRight).

Precondition:
this and rhs represent two points during a particular turing_machine execution; the current state at each point in the execution is the same; the current read head symbol at each point in the execution is the same;
Postcondition:
true if this tape and rhs having matching configurations that exhibit left motion simple loop behavior
Parameters:
rhs representation of the tape at some point later on in the execution
lhsRightBound farthest cell to the right on the tape that the read head has been between the two points of execution
Author:
Owen Kellett

Definition at line 1000 of file infinite_tape.hpp.

template<typename T>
bool infinite_tape< T >::repeatConfigRight infinite_tape< T > &  rhs,
typename std::list< T >::iterator  lhsLeftBound
[inline]
 

tests for a simple loop repeat configuration in rhs.

Precondition:
this and rhs represent two points during a particular turing_machine execution; the current state at each point in the execution is the same; the current read head symbol at each point in the execution is the same;
Postcondition:
true if this tape and rhs having matching configurations that exhibit right motion simple loop behavior
Parameters:
rhs representation of the tape at some point later on in the execution
lhsLeftBound farthest cell to the left on the tape that the read head has been between the two points of execution
Author:
Owen Kellett

Definition at line 903 of file infinite_tape.hpp.

template<typename T>
void infinite_tape< T >::reset  )  [inline]
 

Clears the tape to setting each location to the default value.

Author:
Owen Kellett

Definition at line 816 of file infinite_tape.hpp.

template<typename T>
void infinite_tape< T >::reset_head  )  [inline]
 

moves the read-head to the cardinal position.

Author:
Kyle Ross

Definition at line 263 of file infinite_tape.hpp.

template<typename T>
void infinite_tape< T >::setCurrentLocation typename std::list< T >::iterator  location  )  [inline]
 

Sets the read-head to location.

Parameters:
location iterator of the location to set the read-head
Author:
Owen Kellett

Definition at line 831 of file infinite_tape.hpp.

template<typename T>
template<typename delim_type1, typename delim_type2, typename delim_type3, typename delim_type4, typename delim_type5, typename delim_type6, typename delim_type7, typename delim_type8>
void infinite_tape< T >::show std::ostream &  out,
const delim_type1 &  before_delim,
const delim_type2 &  between_delim,
const delim_type3 &  after_delim,
const delim_type4 &  before_cardinal,
const delim_type5 &  after_cardinal,
const delim_type6 &  before_head,
const delim_type7 &  after_head,
const delim_type8 &  blank_delim,
bool  extra_between_delims
const [inline]
 

wow, could it possibly get more complicated?.

... no, not complicated, *flexible*! ... each delimiter is of an arbitrary type (call it X_type) but must have an std::ostream& operator<<(ostream&, const X_type&) operator defined

Precondition:
the tape contains at least one "cell" and current, cardinal are both valid positions on the tape; all characters held on the tape are printable and out is in a valid output state
Postcondition:
the tape has been printed on out in a well-defined (but, due to its complexity, not explicated here) format
Author:
Kyle Ross

Definition at line 440 of file infinite_tape.hpp.

template<typename T>
void infinite_tape< T >::show std::ostream &  out  )  const [inline]
 

provides the old-style display using a very simple pre-defined inflexible format.

Precondition:
the tape contains at least one "cell" and current, cardinal are both valid positions on the tape
Postcondition:
if the tape is empty, the message "< tape is empty >" has been displayed, else, the symbols on the tape have been displayed, each followed by a single space character and if current==cardinal then "->[" has been displayed before and "]<-" after the head/cardinal, else, "->" is displayed before and "<-" after the head and "[" before and "]" after the cardinal
Author:
Kyle Ross

Definition at line 401 of file infinite_tape.hpp.

template<typename T>
bool infinite_tape< T >::symbols_to_direction direction  which  )  const [inline]
 

Are there any symbols to the of the read-head?.

Precondition:
current refers to a valid cell on the tape
Postcondition:
if which==do_nothing than false is vacuously returned; if which==left then each cell to the left of the read-head have been scanned and true is returned iff there exists at least one non-blank symbol in these cells, false else; if which==right then each cell to the right of the read-head have been scanned and true is returned iff there exists at least one non-blank symbol in these cells, false else
Parameters:
which direction to check for symbols
Author:
Kyle Ross

Definition at line 330 of file infinite_tape.hpp.

Referenced by direction::in_standard_position().

template<typename T>
void infinite_tape< T >::tape_check direction  which  )  [inline, protected]
 

check to see if tape needs to be expanded and call expansion function if so.

Precondition:
current refers to a valid cell on the tape, which==left xor which==right
Postcondition:
if which==left then it is safe to move left at least one position on the tape; if which==right then it is safe to move at least one position right on the tape
Parameters:
which direction to check
Author:
Kyle Ross

Definition at line 1124 of file infinite_tape.hpp.

Referenced by direction::move().

template<typename T>
void infinite_tape< T >::write to_write  )  [inline]
 

Writes a value to the current location on the tape.

Precondition:
current refers to a valid cell of the tape
Postcondition:
to_write has been stored in the cell under the read-head
Parameters:
to_write the symbol to write to the tape

Definition at line 211 of file infinite_tape.hpp.

Referenced by transition_result::perform_transition().


Member Data Documentation

template<typename T>
std::list<T>::size_type infinite_tape< T >::counter [protected]
 

number of moves made counter.

allows constant amortised time moves with expansion

Definition at line 1207 of file infinite_tape.hpp.

Referenced by direction::expand_tape(), direction::infinite_tape(), direction::move(), direction::operator=(), direction::reset(), and direction::tape_check().

template<typename T>
const std::list<T>::size_type infinite_tape< T >::start_size = 101 [static, protected]
 

arbitrary start size of tape.

odd number chosen so that there are 50 cells to each of the right and left of the cardinal ... just to make the numbers a bit easier

Definition at line 1194 of file infinite_tape.hpp.

Referenced by direction::infinite_tape().


The documentation for this class was generated from the following file:
Generated on Thu Nov 20 00:17:33 2003 for BusyBeaver by doxygen 1.3.3