PolyBoRi
|
00001 // -*- c++ -*- 00002 //***************************************************************************** 00042 //***************************************************************************** 00043 00044 // get standard header 00045 #include <stack> 00046 #include <utility> 00047 00048 // include basic definitions 00049 #include "pbori_defs.h" 00050 00051 // Get forward term iterator 00052 #include "CTermIter.h" 00053 00054 00055 #ifndef CBidirectTermIter_h_ 00056 #define CBidirectTermIter_h_ 00057 00058 BEGIN_NAMESPACE_PBORI 00059 00060 template<class NavigatorType> 00061 class handle_else : 00062 public std::deque<NavigatorType> { 00063 public: 00064 00065 typedef NavigatorType navigator_type; 00066 typedef std::deque<NavigatorType> base; 00067 00068 void operator()(const navigator_type& navi) { 00069 00070 while(!base::empty() && (*top() >= *navi) ) 00071 base::pop_back(); 00072 00073 base::push_back(navi); 00074 } 00075 void push(const navigator_type& navi) { base::push_back(navi); } 00076 void pop() { base::pop_back(); } 00077 00078 const navigator_type& top() const { return base::back(); }; 00079 00080 void append(const handle_else& rhs) { 00081 assert(base::empty() || rhs.empty() || ((**rhs.begin()) > (*top())) ); 00082 base::insert(base::end(), rhs.begin(), rhs.end()); 00083 } 00084 }; 00085 00086 #if 0 00087 00093 template <class TermType, class NavigatorType, 00094 class ForwardOp, class BackwardOp, 00095 class TerminalValueOp = project_ith<2> > 00096 class CBidirectTermIter: 00097 public CTermIter<TermType, NavigatorType, 00098 ForwardOp, BackwardOp, 00099 TerminalValueOp, 00100 handle_else<NavigatorType> >{ 00101 00102 public: 00103 00105 typedef TermType term_type; 00106 00108 typedef NavigatorType navigator_type; 00109 00111 typedef ForwardOp forwardop_type; 00112 00114 typedef BackwardOp backwardop_type; 00115 00117 typedef TerminalValueOp termvalop_type; 00118 00120 typedef handle_else<navigator_type> elsehandle_type; 00121 00123 typedef CBidirectTermIter<term_type, navigator_type, 00124 forwardop_type, backwardop_type, termvalop_type> self; 00125 00127 typedef CTermIter<term_type, navigator_type, 00128 forwardop_type, backwardop_type, termvalop_type, 00129 elsehandle_type> base; 00130 00132 00133 typedef std::bidirectional_iterator_tag iterator_category; 00134 typedef typename base::difference_type difference_type; 00135 typedef typename base::pointer pointer; 00136 typedef typename base::reference reference; 00138 00140 using base::handleElse; 00141 00143 CBidirectTermIter(): 00144 base() {} 00145 00147 CBidirectTermIter(navigator_type navi, 00148 forwardop_type fop_ = forwardop_type(), 00149 backwardop_type bop_ = backwardop_type(), 00150 termvalop_type tvop_ = termvalop_type() ): 00151 base(navi, fop_, bop_, tvop_) {} 00152 00154 CBidirectTermIter(navigator_type navi, dummy_iterator): 00155 base() { 00156 if(navi.isValid()) { 00157 followElse(navi); 00158 terminate(navi); 00159 } 00160 } 00161 00163 CBidirectTermIter(const self& rhs): 00164 base(rhs) {}; 00165 00167 ~CBidirectTermIter() {}; 00168 00170 self& operator++() { 00171 base::operator++(); 00172 return *this; 00173 } 00174 00176 self operator++(int dummy) { 00177 return base::operator++(dummy); 00178 }; 00179 00181 self& operator--() { 00182 00183 if (!handleElse.empty()){ 00184 navigator_type navi = handleElse.top(); 00185 base::popToIndex(*navi); 00186 00187 00188 handleElse.pop(); 00189 base::nextThen(navi); 00190 00191 followElse(navi); 00192 } 00193 else 00194 base::clear(); 00195 return *this; 00196 } 00197 00199 self operator--(int) { 00200 self tmp(*this); 00201 operator--(); 00202 return tmp; 00203 }; 00204 00205 protected: 00206 00207 00208 void followElse(navigator_type& navi) { 00209 while( !navi.isConstant() ) { // if still in interior of a path 00210 if(!navi.elseBranch().isEmpty()) { 00211 handleElse.push(navi); 00212 navi.incrementElse(); // go in direction of last term, if possible 00213 } 00214 else 00215 base::nextThen(navi); 00216 } 00217 } 00218 00219 }; 00220 00221 #endif 00222 00223 END_NAMESPACE_PBORI 00224 00225 #endif