CBidirectTermIter.h
Go to the documentation of this file.
// -*- c++ -*-
//*****************************************************************************
//*****************************************************************************
#ifndef polybori_iterators_CBidirectTermIter_h_
#define polybori_iterators_CBidirectTermIter_h_
// get standard header
#include <stack>
#include <utility>
// include basic definitions
#include <polybori/pbori_defs.h>
// Get forward term iterator
#include "CTermIter.h"
BEGIN_NAMESPACE_PBORI
template<class NavigatorType>
class handle_else :
public std::deque<NavigatorType> {
public:
typedef NavigatorType navigator_type;
typedef std::deque<NavigatorType> base;
void operator()(const navigator_type& navi) {
while(!base::empty() && (*top() >= *navi) )
base::pop_back();
base::push_back(navi);
}
void push(const navigator_type& navi) { base::push_back(navi); }
void pop() { base::pop_back(); }
const navigator_type& top() const { return base::back(); };
void append(const handle_else& rhs) {
PBORI_ASSERT(base::empty() || rhs.empty() || ((**rhs.begin()) > (*top())) );
base::insert(base::end(), rhs.begin(), rhs.end());
}
};
#if 0
template <class TermType, class NavigatorType,
class ForwardOp, class BackwardOp,
class TerminalValueOp = project_ith<2> >
class CBidirectTermIter:
public CTermIter<TermType, NavigatorType,
ForwardOp, BackwardOp,
TerminalValueOp,
handle_else<NavigatorType> >{
public:
typedef TermType term_type;
typedef NavigatorType navigator_type;
typedef ForwardOp forwardop_type;
typedef BackwardOp backwardop_type;
typedef TerminalValueOp termvalop_type;
typedef handle_else<navigator_type> elsehandle_type;
typedef CBidirectTermIter<term_type, navigator_type,
forwardop_type, backwardop_type, termvalop_type> self;
typedef CTermIter<term_type, navigator_type,
forwardop_type, backwardop_type, termvalop_type,
elsehandle_type> base;
typedef std::bidirectional_iterator_tag iterator_category;
typedef typename base::difference_type difference_type;
typedef typename base::pointer pointer;
typedef typename base::reference reference;
using base::handleElse;
CBidirectTermIter():
base() {}
CBidirectTermIter(navigator_type navi,
forwardop_type fop_ = forwardop_type(),
backwardop_type bop_ = backwardop_type(),
termvalop_type tvop_ = termvalop_type() ):
base(navi, fop_, bop_, tvop_) {}
CBidirectTermIter(navigator_type navi, dummy_iterator):
base() {
if(navi.isValid()) {
followElse(navi);
terminate(navi);
}
}
CBidirectTermIter(const self& rhs):
base(rhs) {};
~CBidirectTermIter() {};
self& operator++() {
base::operator++();
return *this;
}
self operator++(int dummy) {
return base::operator++(dummy);
};
self& operator--() {
if (!handleElse.empty()){
navigator_type navi = handleElse.top();
base::popToIndex(*navi);
handleElse.pop();
base::nextThen(navi);
followElse(navi);
}
else
base::clear();
return *this;
}
self operator--(int) {
self tmp(*this);
operator--();
return tmp;
};
protected:
void followElse(navigator_type& navi) {
while( !navi.isConstant() ) { // if still in interior of a path
if(!navi.elseBranch().isEmpty()) {
handleElse.push(navi);
navi.incrementElse(); // go in direction of last term, if possible
}
else
base::nextThen(navi);
}
}
};
#endif
END_NAMESPACE_PBORI
#endif
polybori::handle_else::top
const navigator_type & top() const
Definition: CBidirectTermIter.h:48
END_NAMESPACE_PBORI
#define END_NAMESPACE_PBORI
Finish project's namespace.
Definition: pbori_defs.h:77
BEGIN_NAMESPACE_PBORI
#define BEGIN_NAMESPACE_PBORI
Start project's namespace.
Definition: pbori_defs.h:74
CTermIter.h
polybori::handle_else
Definition: CBidirectTermIter.h:31
polybori::handle_else::navigator_type
NavigatorType navigator_type
Definition: CBidirectTermIter.h:35
pbori_defs.h
polybori::handle_else::push
void push(const navigator_type &navi)
Definition: CBidirectTermIter.h:45
PBORI_ASSERT
#define PBORI_ASSERT(arg)
Definition: pbori_defs.h:118
polybori::handle_else::base
std::deque< NavigatorType > base
Definition: CBidirectTermIter.h:36
polybori::handle_else::operator()
void operator()(const navigator_type &navi)
Definition: CBidirectTermIter.h:38
polybori::handle_else::pop
void pop()
Definition: CBidirectTermIter.h:46
polybori::handle_else::append
void append(const handle_else &rhs)
Definition: CBidirectTermIter.h:50