33 typedef std::shared_ptr<StackIteratorPimpl>
Ptr;
34 typedef std::vector<StackItem::Ptr>::iterator
Iterator;
56 Variable::Ptr asVariable = std::dynamic_pointer_cast<Variable, StackItem>(in);
61 std::set<std::string> varNames;
65 Variable::Ptr itemAsVar = std::dynamic_pointer_cast<Variable, StackItem>(item);
72 auto result = varNames.insert(itemAsVar->getName());
94 pimpl->hint = rhs.pimpl->hint;
99 pimpl->hint = rhs.pimpl->hint;
104 if(pimpl->stack.end() != *
this) {
118 return rhs.pimpl->iter == pimpl->iter;
122 return rhs.pimpl->iter != pimpl->iter;
125 StackIterator::operator bool()
const {
126 return 0 == pimpl->result.getPositionMessages().size();
130 if(pimpl->stack.end() == *
this) {
134 return pimpl->dereference(*pimpl->iter);
146 pimpl->hint = theHint;
151 return pimpl->result;
155 pimpl->addError(position, message);
184 typedef StackType::iterator
Iter;
185 typedef StackType::const_iterator
CIter;
205 return pimpl->stack.size();
209 return pimpl->variables;
214 pimpl->variables.clear();
218 pimpl->stack.clear();
238 pimpl->stack.erase(from, pimpl->stack.end());
242 pimpl->stack.push_back(item);
246 std::ostringstream os;
249 for(
StackPimpl::CIter iter = pimpl->stack.begin(); pimpl->stack.end() != iter; ++iter) {
250 os <<
" " << (*iter)->toString();
Collection of Result information for an operation.
void addPositionMessage(const unsigned int position, const std::string &message)
Add the positional message.
Stack of values to process from.
VariableSet & getVariables()
void push(StackItemPtr item)
Push item onto the stack.
std::string toString() const
Create string representation of the current contents of the Stack.
void popAfter(StackIterator &iter)
Pop all items after iter on the Stack.
void popAll()
Pop all items from the stack.
void reset()
Reset the stack including pop all variables and reset the variables.
unsigned int Count
Count of StackItems.
std::shared_ptr< StackItem > Ptr
Iterator over a Stack from top to bottom.
Hint
Hint for accessing the value at an iterator.
@ DEREFERENCE_NEXT
Dereference the next read.
bool operator!=(const StackIterator &rhs) const
Return true if this iterator is not the same position as rhs.
StackIterator & operator=(const StackIterator &)
const Result & getResult() const
StackIterator & operator++()
Pre-increment: Move to the next position away from the top.
StackItemPtr noDereference()
bool operator==(const StackIterator &rhs) const
Return true if this iterator is the same position as rhs.
StackIterator & setHint(Hint theHint)
Set the current hint for reading the value to theHint.
void addError(unsigned int position, const std::string &message)
Add error message at position.
std::shared_ptr< StackIteratorPimpl > Ptr
void addError(unsigned int position, const std::string &error)
StackIteratorPimpl(Stack &theStack, const Iterator &theIter)
std::vector< StackItem::Ptr >::iterator Iterator
StackItem::Ptr dereference(StackItem::Ptr in)
StackType::const_iterator CIter
VariableSet variables
Variables used in the Stack.
std::vector< StackItem::Ptr > StackType
StackType stack
Implementation of the Stack.
std::shared_ptr< Variable > Ptr
All variables belonging to a Stack.
std::shared_ptr< StackItem > get(const std::string &name) const
Get the value of name, if any.
const std::string VariableReferencesSelf
Variable dereferences to itself directly or indirectly and cannot be read.
const std::string StackUnderflow
Operation required more items than the Stack had available.
const std::string VariableNotSet
Operation required a variable.
Container of Calculator resources.
StackIterator & operator>>(StackIterator &iter, StackIterator::Hint hint)
Set the iter's hint and return the iter.