COrderedIter.h
Go to the documentation of this file.
// -*- c++ -*-
//*****************************************************************************
//*****************************************************************************
#ifndef polybori_iterators_COrderedIter_h_
#define polybori_iterators_COrderedIter_h_
// include basic definitions
#include <polybori/pbori_defs.h>
#include <polybori/routines/pbori_algo.h>
#include <polybori/BoolePolynomial.h>
#include "CBidirectTermIter.h"
#include <algorithm>
#include "CStackSelector.h"
#include "CTermGenerator.h"
BEGIN_NAMESPACE_PBORI
template <class NavigatorType>
class CAbstractStackBase {
public:
typedef NavigatorType navigator;
typedef CAbstractStackBase<NavigatorType> self;
typedef CTermStackBase<NavigatorType, self> iterator_core;
typedef boost::shared_ptr<iterator_core> core_pointer;
virtual void increment() = 0;
virtual core_pointer copy() const = 0;
virtual ~CAbstractStackBase() {}
};
template <class StackType>
class CWrappedStack:
public StackType {
public:
typedef StackType base;
typedef CWrappedStack<StackType> self;
typedef typename base::navigator navigator;
typedef typename base::iterator_core iterator_core;
typedef boost::shared_ptr<iterator_core> core_pointer;
template <class MgrType>
CWrappedStack(navigator navi, const MgrType& mgr):
base(navi, mgr) {
base::init();
}
// CWrappedStack(): base() {}
CWrappedStack(const self& rhs): base(rhs) {}
core_pointer copy() const {
return core_pointer(new self(*this));
}
};
// template<class SequenceType>
// void get_term(BooleMonomial& monom, const SequenceType& seq) {
// typename SequenceType::const_reverse_iterator start(seq.rbegin()),
// finish(seq.rend());
// while (start != finish){
// monom.changeAssign(*start);
// ++start;
// }
// }
// template<class SequenceType>
// void get_term(BooleExponent& termexp, const SequenceType& seq) {
// termexp.reserve(seq.deg());
// typename SequenceType::const_iterator start(seq.begin()),
// finish(seq.end());
// while (start != finish){
// termexp.push_back(*start);
// ++start;
// }
// }
// template<class SequenceType>
// void get_term(typename CTypes::size_type& termdeg, const SequenceType& seq) {
// termdeg = seq.deg();
// }
template <class NavigatorType, class MonomType>
class COrderedIter:
public boost::iterator_facade<
COrderedIter<NavigatorType, MonomType>,
MonomType, std::forward_iterator_tag, MonomType
> {
public:
typedef COrderedIter<NavigatorType, MonomType> self;
typedef CAbstractStackBase<NavigatorType> stack_base;
typedef CTermStackBase<NavigatorType, stack_base> iterator_core;
typedef CTermGenerator<MonomType> term_generator;
typedef typename iterator_core::const_iterator const_iterator;
typedef typename iterator_core::const_reverse_iterator
const_reverse_iterator;
typedef typename iterator_core::size_type size_type;
typedef typename iterator_core::deg_type deg_type;
typedef typename iterator_core::idx_type idx_type;
typedef NavigatorType navigator;
// Store shared pointer of iterator
typedef boost::shared_ptr<iterator_core> core_pointer;
typedef bool bool_type;
// Constructor
COrderedIter(core_pointer rhs,
const term_generator & getTerm):
m_getTerm(getTerm), p_iter(rhs) {}
// Destructor
~COrderedIter() {}
bool equal(const self& rhs) const {
return p_iter->equal(*rhs.p_iter); }
void increment() {
if (!p_iter.unique()) {
core_pointer tmp(p_iter->copy());
p_iter = tmp;
}
p_iter->increment();
}
bool_type isOne() const { return p_iter->isOne(); }
bool_type isZero() const { return p_iter->isZero(); }
bool_type isEnd() const { return isZero(); }
MonomType dereference() const {
return m_getTerm(*p_iter);
}
const_iterator begin() const { return p_iter->begin(); }
const_iterator end() const { return p_iter->end(); }
const_reverse_iterator rbegin() const { return p_iter->rbegin(); }
const_reverse_iterator rend() const { return p_iter->rend(); }
deg_type deg() const { return p_iter->deg(); }
idx_type firstIndex() const { return *begin(); }
navigator navigation() const {
return p_iter->navigation();
}
protected:
term_generator m_getTerm;
core_pointer p_iter;
};
template <class OrderType, class NavigatorType, class MonomType>
class CGenericOrderedIter:
public COrderedIter<NavigatorType, MonomType> {
public:
typedef CAbstractStackBase<NavigatorType> stack_base;
typedef typename CStackSelector<OrderType, NavigatorType, stack_base>::type
ordered_iter_base;
typedef CWrappedStack<ordered_iter_base> ordered_iter_type;
typedef COrderedIter<NavigatorType, MonomType> base;
typedef typename base::iterator_core iterator_core;
typedef typename base::core_pointer core_pointer;
typedef typename base::term_generator term_generator;
template <class MgrType>
CGenericOrderedIter(NavigatorType navi, const MgrType& gen):
base( core_pointer(new ordered_iter_type(navi, gen) ), gen) {}
// CGenericOrderedIter(): base( core_pointer(new ordered_iter_type()),
// term_generator() ) {}
CGenericOrderedIter(const CGenericOrderedIter& rhs): base(rhs) {}
};
template <class OrderType, class NavigatorType>
class CGenericOrderedIter<OrderType, NavigatorType, BooleExponent> :
public COrderedIter<NavigatorType, BooleExponent> {
public:
typedef CAbstractStackBase<NavigatorType> stack_base;
typedef typename CStackSelector<OrderType, NavigatorType, stack_base>::type
ordered_iter_base;
typedef CWrappedStack<ordered_iter_base> ordered_iter_type;
typedef COrderedIter<NavigatorType, BooleExponent> base;
typedef typename base::iterator_core iterator_core;
typedef typename base::core_pointer core_pointer;
typedef typename base::term_generator term_generator;
template <class MgrType>
CGenericOrderedIter(NavigatorType navi, const MgrType& mgr):
base( core_pointer(new ordered_iter_type(navi, mgr)),
term_generator() ) {}
// CGenericOrderedIter(): base( core_pointer(new ordered_iter_type()),
// term_generator() ) {}
CGenericOrderedIter(const CGenericOrderedIter& rhs): base(rhs) {}
};
END_NAMESPACE_PBORI
#endif
polybori::CTermStackBase::const_iterator
boost::indirect_iterator< typename stack_type::const_iterator, typename navigator::value_type, boost::use_default, typename navigator::reference > const_iterator
Definition: CTermStack.h:156
polybori::CAbstractStackBase::navigator
NavigatorType navigator
Definition: COrderedIter.h:36
polybori::CGenericOrderedIter< OrderType, NavigatorType, BooleExponent >::ordered_iter_type
CWrappedStack< ordered_iter_base > ordered_iter_type
Definition: COrderedIter.h:233
CTermGenerator.h
polybori::CGenericOrderedIter::CGenericOrderedIter
CGenericOrderedIter(const CGenericOrderedIter &rhs)
Definition: COrderedIter.h:223
polybori::CGenericOrderedIter::ordered_iter_base
CStackSelector< OrderType, NavigatorType, stack_base >::type ordered_iter_base
Definition: COrderedIter.h:208
polybori::BooleExponent
This class is just a wrapper for using variables for storing indices as interim data structure for Bo...
Definition: BooleExponent.h:34
polybori::COrderedIter::deg
deg_type deg() const
Definition: COrderedIter.h:185
END_NAMESPACE_PBORI
#define END_NAMESPACE_PBORI
Finish project's namespace.
Definition: pbori_defs.h:77
polybori::COrderedIter::m_getTerm
term_generator m_getTerm
The functional which defines the dereferecing operation.
Definition: COrderedIter.h:195
polybori::CGenericOrderedIter::core_pointer
base::core_pointer core_pointer
Definition: COrderedIter.h:213
polybori::CGenericOrderedIter< OrderType, NavigatorType, BooleExponent >::term_generator
base::term_generator term_generator
Definition: COrderedIter.h:239
polybori::CWrappedStack::core_pointer
boost::shared_ptr< iterator_core > core_pointer
Definition: COrderedIter.h:60
polybori::COrderedIter::p_iter
core_pointer p_iter
A shared pointer to the stack, which carries the current path.
Definition: COrderedIter.h:198
polybori::COrderedIter::term_generator
CTermGenerator< MonomType > term_generator
Type for functional, which generates actual term, for current path.
Definition: COrderedIter.h:125
BEGIN_NAMESPACE_PBORI
#define BEGIN_NAMESPACE_PBORI
Start project's namespace.
Definition: pbori_defs.h:74
polybori::CGenericOrderedIter::ordered_iter_type
CWrappedStack< ordered_iter_base > ordered_iter_type
Definition: COrderedIter.h:209
polybori::COrderedIter::increment
void increment()
Incrementation.
Definition: COrderedIter.h:156
polybori::COrderedIter::iterator_core
CTermStackBase< NavigatorType, stack_base > iterator_core
Definition: COrderedIter.h:122
polybori::COrderedIter::firstIndex
idx_type firstIndex() const
Definition: COrderedIter.h:186
polybori::CWrappedStack::base
StackType base
Definition: COrderedIter.h:54
CStackSelector.h
polybori::COrderedIter::size_type
iterator_core::size_type size_type
Definition: COrderedIter.h:130
polybori::CGenericOrderedIter::stack_base
CAbstractStackBase< NavigatorType > stack_base
Definition: COrderedIter.h:206
polybori::COrderedIter::COrderedIter
COrderedIter(core_pointer rhs, const term_generator &getTerm)
Definition: COrderedIter.h:145
polybori::COrderedIter::navigator
NavigatorType navigator
Fix type of direct iterator.
Definition: COrderedIter.h:136
polybori::CGenericOrderedIter< OrderType, NavigatorType, BooleExponent >::base
COrderedIter< NavigatorType, BooleExponent > base
Definition: COrderedIter.h:235
polybori::COrderedIter::const_iterator
iterator_core::const_iterator const_iterator
Definition: COrderedIter.h:127
polybori::CStackSelector::type
on_same_type< block_prop, valid_tag, block_type, nonblock_type >::type type
The resulting type for iterator's stack.
Definition: CStackSelector.h:67
polybori::COrderedIter::stack_base
CAbstractStackBase< NavigatorType > stack_base
Definition: COrderedIter.h:121
polybori::CGenericOrderedIter< OrderType, NavigatorType, BooleExponent >::CGenericOrderedIter
CGenericOrderedIter(const CGenericOrderedIter &rhs)
Definition: COrderedIter.h:249
polybori::CAbstractStackBase
Definition: COrderedIter.h:34
polybori::CWrappedStack::CWrappedStack
CWrappedStack(navigator navi, const MgrType &mgr)
Definition: COrderedIter.h:63
polybori::CGenericOrderedIter< OrderType, NavigatorType, BooleExponent >::ordered_iter_base
CStackSelector< OrderType, NavigatorType, stack_base >::type ordered_iter_base
Definition: COrderedIter.h:232
polybori::COrderedIter::dereference
MonomType dereference() const
Dereferencing operation.
Definition: COrderedIter.h:175
polybori::CTermGenerator< MonomType >
polybori::CWrappedStack::navigator
base::navigator navigator
Definition: COrderedIter.h:57
polybori::COrderedIter
Definition: BoolePolynomial.h:63
polybori::CTermStackBase::const_reverse_iterator
boost::indirect_iterator< typename stack_type::const_reverse_iterator, typename navigator::value_type, boost::use_default, typename navigator::reference > const_reverse_iterator
Definition: CTermStack.h:166
polybori::COrderedIter::navigation
navigator navigation() const
Get navigator of term start.
Definition: COrderedIter.h:189
pbori_defs.h
polybori::CTermStackBase::idx_type
navigator::idx_type idx_type
Type for indices.
Definition: CTermStack.h:138
polybori::CGenericOrderedIter< OrderType, NavigatorType, BooleExponent >::iterator_core
base::iterator_core iterator_core
Definition: COrderedIter.h:236
polybori::COrderedIter::const_reverse_iterator
iterator_core::const_reverse_iterator const_reverse_iterator
Definition: COrderedIter.h:129
polybori::CGenericOrderedIter< OrderType, NavigatorType, BooleExponent >::core_pointer
base::core_pointer core_pointer
Definition: COrderedIter.h:237
CBidirectTermIter.h
polybori::COrderedIter::core_pointer
boost::shared_ptr< iterator_core > core_pointer
Definition: COrderedIter.h:139
polybori::COrderedIter::deg_type
iterator_core::deg_type deg_type
Definition: COrderedIter.h:131
polybori::CGenericOrderedIter::iterator_core
base::iterator_core iterator_core
Definition: COrderedIter.h:212
polybori::COrderedIter::end
const_iterator end() const
Definition: COrderedIter.h:181
polybori::CAbstractStackBase::iterator_core
CTermStackBase< NavigatorType, self > iterator_core
Definition: COrderedIter.h:39
polybori::CGenericOrderedIter< OrderType, NavigatorType, BooleExponent >::CGenericOrderedIter
CGenericOrderedIter(NavigatorType navi, const MgrType &mgr)
Definition: COrderedIter.h:242
polybori::COrderedIter::rend
const_reverse_iterator rend() const
Definition: COrderedIter.h:183
BoolePolynomial.h
polybori::CAbstractStackBase::~CAbstractStackBase
virtual ~CAbstractStackBase()
Definition: COrderedIter.h:45
polybori::CWrappedStack::copy
core_pointer copy() const
Definition: COrderedIter.h:71
polybori::COrderedIter::idx_type
iterator_core::idx_type idx_type
Definition: COrderedIter.h:132
polybori::CTermStackBase::size_type
navigator::size_type size_type
Type for lengths.
Definition: CTermStack.h:141
polybori::COrderedIter::equal
bool equal(const self &rhs) const
Definition: COrderedIter.h:152
polybori::CWrappedStack::CWrappedStack
CWrappedStack(const self &rhs)
Definition: COrderedIter.h:68
polybori::CGenericOrderedIter::term_generator
base::term_generator term_generator
Definition: COrderedIter.h:215
polybori::CGenericOrderedIter::base
COrderedIter< NavigatorType, MonomType > base
Definition: COrderedIter.h:211
polybori::COrderedIter::~COrderedIter
~COrderedIter()
Definition: COrderedIter.h:150
polybori::CTermStackBase
This class defines an iterator for the monomials in a Boolean polynomial.
Definition: CTermStack.h:126
polybori::CWrappedStack
Definition: COrderedIter.h:51
polybori::COrderedIter::isEnd
bool_type isEnd() const
Check, whether end of iteration is reached.
Definition: COrderedIter.h:172
polybori::CAbstractStackBase::core_pointer
boost::shared_ptr< iterator_core > core_pointer
Definition: COrderedIter.h:40
polybori::CWrappedStack::iterator_core
base::iterator_core iterator_core
Definition: COrderedIter.h:59
polybori::COrderedIter::rbegin
const_reverse_iterator rbegin() const
Definition: COrderedIter.h:182
pbori_algo.h
polybori::CGenericOrderedIter< OrderType, NavigatorType, BooleExponent >::stack_base
CAbstractStackBase< NavigatorType > stack_base
Definition: COrderedIter.h:230
polybori::COrderedIter::bool_type
bool bool_type
Extract plain Boolean type.
Definition: COrderedIter.h:142
polybori::COrderedIter::begin
const_iterator begin() const
Definition: COrderedIter.h:180
polybori::CGenericOrderedIter
Definition: COrderedIter.h:203
polybori::COrderedIter::isZero
bool_type isZero() const
Determine whether term is zero (without explicit constructing)
Definition: COrderedIter.h:169
polybori::COrderedIter::isOne
bool_type isOne() const
Determine whether term is one (without explicit constructing)
Definition: COrderedIter.h:166
polybori::CGenericOrderedIter::CGenericOrderedIter
CGenericOrderedIter(NavigatorType navi, const MgrType &gen)
Definition: COrderedIter.h:218
polybori::CTermStackBase::deg_type
navigator::deg_type deg_type
Definition: CTermStack.h:142