TuringSim
C++ framework to simulate abstract computing models
Public Member Functions | List of all members
TuringSim::Memory::Tape::TapeObserver< T > Class Template Reference

Observer for the Tape class. More...

#include <memory/tape.h>

Public Member Functions

constexpr TapeObserver (const Tape< T > &tape)
 Construct an observer to the tape in parameter. More...
 
constexpr size_t getRightSize () const
 Get the size of the right part of the tape. More...
 
constexpr size_t getLeftSize () const
 Get the size of the left part of the tape. More...
 
constexpr const std::vector< T > & getRightTape () const
 Get the right part of the tape. More...
 
constexpr const std::vector< T > & getLeftTape () const
 Get the left part of the tape. More...
 
constexpr const std::vector< T > * getCurrentTape () const
 Get the current tape. May be the right of the left tape. More...
 
constexpr size_t getSizeFactor () const
 Get the resizing factor of the tape. More...
 
constexpr const T & getBlank () const
 Get the blank symbol. More...
 
constexpr bool isOnRight () const
 Check if the I/O head is on the right half-tape. More...
 
constexpr size_t getAbsolutePosition () const
 Return the current absolute position. More...
 
constexpr long long int getPosition () const
 Return the current position. More...
 
constexpr const T & operator[] (long long int position) const
 Return a const reference to a cell of the tape. More...
 

Detailed Description

template<typename T>
class TuringSim::Memory::Tape::TapeObserver< T >

Observer for the Tape class.

Template Parameters
Tthe type of the alphabet of the observed tape.

The observer allows to access private members. For instance, it can be useful to print the content of the tape. These getters are in the observer because these features does not belongs to the abstract model of the tape.

Definition at line 426 of file tape.h.

Constructor & Destructor Documentation

◆ TapeObserver()

template<typename T >
constexpr TuringSim::Memory::Tape::TapeObserver< T >::TapeObserver ( const Tape< T > &  tape)
inlineconstexpr

Construct an observer to the tape in parameter.

Parameters
[in]tapeThe tape to observe. It is captured by const reference to track any modification to the tape.

The behaviour of the observer is undefined (and will probably segfault) once the tape destroyed.

Complexity of \(\mathcal{O}(1)\).

Definition at line 437 of file tape.h.

Member Function Documentation

◆ getAbsolutePosition()

template<typename T >
constexpr size_t TuringSim::Memory::Tape::TapeObserver< T >::getAbsolutePosition ( ) const
inlineconstexpr

Return the current absolute position.

Returns
The position of the I/O head as the index of the current half-tape

If the position is non negative positive, the absolution position is the same. But if the position is negative, the absolute position is \(-\texttt{position}-1\)

Complexity of \(\mathcal{O}(1)\).

Definition at line 512 of file tape.h.

◆ getBlank()

template<typename T >
constexpr const T& TuringSim::Memory::Tape::TapeObserver< T >::getBlank ( ) const
inlineconstexpr

Get the blank symbol.

Returns
A const reference to an instance of the blank symbol.

Complexity of \(\mathcal{O}(1)\).

Definition at line 495 of file tape.h.

◆ getCurrentTape()

template<typename T >
constexpr const std::vector<T>* TuringSim::Memory::Tape::TapeObserver< T >::getCurrentTape ( ) const
inlineconstexpr

Get the current tape. May be the right of the left tape.

Returns
a cont pointer to the current tape.

Definition at line 478 of file tape.h.

◆ getLeftSize()

template<typename T >
constexpr size_t TuringSim::Memory::Tape::TapeObserver< T >::getLeftSize ( ) const
inlineconstexpr

Get the size of the left part of the tape.

Returns
The number of box allocated for the left tape.

The left part of the part is the half-tape made of boxed with negative index.

Complexity of \(\mathcal{O}(1)\).

Definition at line 455 of file tape.h.

◆ getLeftTape()

template<typename T >
constexpr const std::vector<T>& TuringSim::Memory::Tape::TapeObserver< T >::getLeftTape ( ) const
inlineconstexpr

Get the left part of the tape.

Returns
A const reference to the vector containing the left part of the tape.

For all negative index i, we have leftTape[i] == Tape[-i-1] .

Complexity of \(\mathcal{O}(1)\).

Definition at line 473 of file tape.h.

◆ getPosition()

template<typename T >
constexpr long long int TuringSim::Memory::Tape::TapeObserver< T >::getPosition ( ) const
inlineconstexpr

Return the current position.

Returns
The position of the I/O head

Complexity of \(\mathcal{O}(1)\).

Definition at line 519 of file tape.h.

◆ getRightSize()

template<typename T >
constexpr size_t TuringSim::Memory::Tape::TapeObserver< T >::getRightSize ( ) const
inlineconstexpr

Get the size of the right part of the tape.

Returns
The number of box allocated for the right tape.

The right part of the part is the half-tape made of boxed with non negative index.

Complexity of \(\mathcal{O}(1)\).

Definition at line 446 of file tape.h.

◆ getRightTape()

template<typename T >
constexpr const std::vector<T>& TuringSim::Memory::Tape::TapeObserver< T >::getRightTape ( ) const
inlineconstexpr

Get the right part of the tape.

Returns
A const reference to the vector containing the right part of the tape.

For all non negative index i, we have rightTape[i] == Tape[i] .

Complexity of \(\mathcal{O}(1)\).

Definition at line 464 of file tape.h.

◆ getSizeFactor()

template<typename T >
constexpr size_t TuringSim::Memory::Tape::TapeObserver< T >::getSizeFactor ( ) const
inlineconstexpr

Get the resizing factor of the tape.

Returns
The resizing factor

The resizing factor is the factor by which an half-tape is enlarged when the I/O head hit the end. This resizing method ensures an amortized complexity of \(\mathcal{O}(1)\) for move operations.

Complexity of \(\mathcal{O}(1)\).

Definition at line 488 of file tape.h.

◆ isOnRight()

template<typename T >
constexpr bool TuringSim::Memory::Tape::TapeObserver< T >::isOnRight ( ) const
inlineconstexpr

Check if the I/O head is on the right half-tape.

Returns
A bool indicating if the I/O head position is non negative.

Complexity of \(\mathcal{O}(1)\).

Definition at line 502 of file tape.h.

◆ operator[]()

template<typename T >
constexpr const T& TuringSim::Memory::Tape::TapeObserver< T >::operator[] ( long long int  position) const
inlineconstexpr

Return a const reference to a cell of the tape.

Parameters
positionthe position of the requested cell.
Returns
A const reference to the cell.

The reference may be invalid after shrinking the tape.

Definition at line 529 of file tape.h.


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