Calculator
Extensible stack-based calculator primarily in library form
Calculator::StackIterator Class Reference

Iterator over a Stack from top to bottom. More...

#include <Stack.h>

Public Types

enum class  Hint { DEREFERENCE_NEXT , NO_DEREFERENCE_NEXT }
 Hint for accessing the value at an iterator. More...
 
typedef std::shared_ptr< StackItemStackItemPtr
 Equivalent of StackItem::Ptr;. More...
 

Public Member Functions

 ~StackIterator ()=default
 
 StackIterator (std::shared_ptr< StackIteratorPimpl > thePimpl)
 Create with reference to the variables and the implementint iterator. More...
 
 StackIterator ()=delete
 
 StackIterator (const StackIterator &)
 
 StackIterator (StackIterator &&)=default
 
StackIteratoroperator= (const StackIterator &)
 
StackIteratoroperator= (StackIterator &&)=default
 
StackIteratoroperator++ ()
 Pre-increment: Move to the next position away from the top. More...
 
StackIterator operator++ (int)
 Post-increment: Move to the next position away from the top, but return the a copy of this iterator without the modification. More...
 
bool operator== (const StackIterator &rhs) const
 Return true if this iterator is the same position as rhs. More...
 
bool operator!= (const StackIterator &rhs) const
 Return true if this iterator is not the same position as rhs. More...
 
 operator bool () const
 
StackItemPtr operator* ()
 
StackItemPtr noDereference ()
 
StackIteratorsetHint (Hint theHint)
 Set the current hint for reading the value to theHint. More...
 
template<typename T >
auto as (bool required=true) -> typename T::Ptr
 Convenience method to read the current value by operator->* (respecting the current hint) and return it to a T::Ptr by std::dynamic_pointer_cast. More...
 
const ResultgetResult () const
 
void addError (unsigned int position, const std::string &message)
 Add error message at position. More...
 
void addError (const std::string &message)
 Add error message at current position. More...
 
PimplPtr getPimpl ()
 

Detailed Description

Iterator over a Stack from top to bottom.

Definition at line 35 of file Stack.h.

Member Typedef Documentation

◆ StackItemPtr

Equivalent of StackItem::Ptr;.

Definition at line 41 of file Stack.h.

Member Enumeration Documentation

◆ Hint

Hint for accessing the value at an iterator.

Enumerator
DEREFERENCE_NEXT 

Dereference the next read.

NO_DEREFERENCE_NEXT 

Do not dereference the next read.

Definition at line 44 of file Stack.h.

Constructor & Destructor Documentation

◆ ~StackIterator()

Calculator::StackIterator::~StackIterator ( )
default

◆ StackIterator() [1/4]

Calculator::StackIterator::StackIterator ( std::shared_ptr< StackIteratorPimpl thePimpl)

Create with reference to the variables and the implementint iterator.

Parameters
thePimplinitial data for the StackIterator

Definition at line 86 of file Stack.cpp.

◆ StackIterator() [2/4]

Calculator::StackIterator::StackIterator ( )
delete

◆ StackIterator() [3/4]

Calculator::StackIterator::StackIterator ( const StackIterator rhs)

Definition at line 91 of file Stack.cpp.

◆ StackIterator() [4/4]

Calculator::StackIterator::StackIterator ( StackIterator &&  )
default

Member Function Documentation

◆ addError() [1/2]

void Calculator::StackIterator::addError ( const std::string &  message)

Add error message at current position.

Parameters
messagedescribing the error

Definition at line 158 of file Stack.cpp.

◆ addError() [2/2]

void Calculator::StackIterator::addError ( unsigned int  position,
const std::string &  message 
)

Add error message at position.

Parameters
positionin the stack the error occurred
messagedescribing the error

Definition at line 154 of file Stack.cpp.

◆ as()

template<typename T >
auto Calculator::StackIterator::as ( bool  required = true) -> typename T::Ptr
inline

Convenience method to read the current value by operator->* (respecting the current hint) and return it to a T::Ptr by std::dynamic_pointer_cast.

If the cast fails, the returned value is empty

Template Parameters
Tdesired type to cast the value to
Parameters
requiredif true, conversion failure is logged as a positional message in the Result.
Returns
the current value from operator* as a T::Ptr, which may be empty if the cast failed

Definition at line 128 of file Stack.h.

◆ getPimpl()

StackIterator::PimplPtr Calculator::StackIterator::getPimpl ( )
Returns
the private implementation

Definition at line 162 of file Stack.cpp.

◆ getResult()

const Result & Calculator::StackIterator::getResult ( ) const
Returns
Errors, such as conversion and variable, thus far, if any

Definition at line 150 of file Stack.cpp.

◆ noDereference()

StackItem::Ptr Calculator::StackIterator::noDereference ( )
Returns
the current item without dereferencing, ignoring the hint entirely

Definition at line 141 of file Stack.cpp.

◆ operator bool()

Calculator::StackIterator::operator bool ( ) const
Returns
false if any errors have been reported, otherwise true

Definition at line 125 of file Stack.cpp.

◆ operator!=()

bool Calculator::StackIterator::operator!= ( const StackIterator rhs) const

Return true if this iterator is not the same position as rhs.

Parameters
rhsto compare this iterator to
Returns
false if this iterator and rhs refer to the same position, otherwise true

Definition at line 121 of file Stack.cpp.

◆ operator*()

StackItem::Ptr Calculator::StackIterator::operator* ( )
Returns
the object at the current position as per the current hint and reset the hint for the next read to Hint::DEREFERENCE_NEXT

Definition at line 129 of file Stack.cpp.

◆ operator++() [1/2]

StackIterator & Calculator::StackIterator::operator++ ( )

Pre-increment: Move to the next position away from the top.

Returns
this iterator

Definition at line 103 of file Stack.cpp.

◆ operator++() [2/2]

StackIterator Calculator::StackIterator::operator++ ( int  )

Post-increment: Move to the next position away from the top, but return the a copy of this iterator without the modification.

Returns
a copy of this iterator before the increment.

Definition at line 111 of file Stack.cpp.

◆ operator=() [1/2]

StackIterator & Calculator::StackIterator::operator= ( const StackIterator rhs)

Definition at line 97 of file Stack.cpp.

◆ operator=() [2/2]

StackIterator& Calculator::StackIterator::operator= ( StackIterator &&  )
default

◆ operator==()

bool Calculator::StackIterator::operator== ( const StackIterator rhs) const

Return true if this iterator is the same position as rhs.

Parameters
rhsto compare this iterator to
Returns
true if this iterator and rhs refer to the same position, otherwise false

Definition at line 117 of file Stack.cpp.

◆ setHint()

StackIterator & Calculator::StackIterator::setHint ( Hint  theHint)

Set the current hint for reading the value to theHint.

Parameters
theHintto set the hint for the next read to
Returns
this iterator

Definition at line 145 of file Stack.cpp.


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