00001
00002
00015
00016
00017 #ifndef polybori_iterators_CTermGenerator_h_
00018 #define polybori_iterators_CTermGenerator_h_
00019
00020
00021 #include <polybori/pbori_defs.h>
00022
00023
00024 #include <polybori/routines/pbori_func.h>
00025
00026
00027
00028
00029
00030 BEGIN_NAMESPACE_PBORI
00031
00032
00033 template <class TermType, class BehaviourTag>
00034 class CTermGeneratorBase__;
00035
00036
00037 class BooleExponent;
00038 template <class TermType>
00039 class CTermGeneratorBase__<TermType, type_tag<BooleExponent> > {
00040
00041 public:
00042 typedef TermType value_type;
00043 typedef value_type result_type;
00044
00045 template <class SequenceType>
00046 result_type operator()(const SequenceType& seq) const{
00047
00048 value_type result;
00049 result.reserve(seq.deg());
00050 typename SequenceType::const_iterator
00051 start(seq.begin()), finish(seq.end());
00052
00053 while (start != finish){
00054 result.push_back(*start);
00055 ++start;
00056 }
00057 return result;
00058 }
00059 };
00060
00061 template <class TermType>
00062 class CTermGeneratorBase__<TermType, type_tag<CTypes::size_type> > {
00063 public:
00064 typedef TermType value_type;
00065 typedef value_type result_type;
00066
00067 template <class SequenceType>
00068 result_type operator()(const SequenceType& seq) const{
00069 return seq.deg();
00070 }
00071 };
00072
00073
00074 template <class TermType>
00075 class CTermGeneratorBase__<TermType, type_tag<CTypes::deg_type> > {
00076 public:
00077 typedef TermType value_type;
00078 typedef value_type result_type;
00079
00080 template <class SequenceType>
00081 result_type operator()(const SequenceType& seq) const{
00082 return seq.deg();
00083 }
00084 };
00085
00086
00088
00089
00090 template <class TermType>
00091 class CTermGeneratorBase__<TermType, type_tag<BooleMonomial> >{
00092
00093 public:
00094 typedef TermType value_type;
00095 typedef value_type result_type;
00096
00097
00098
00099
00100 typedef BoolePolyRing data_type;
00101 typedef data_type::dd_type dd_type;
00102
00103
00104 data_type m_data;
00106
00107 CTermGeneratorBase__(const data_type& data): m_data(data) {}
00108
00109 CTermGeneratorBase__(): m_data() {}
00110
00111 template <class SequenceType>
00112 result_type operator()(const SequenceType& seq) const {
00114
00115
00116 PBORI_ASSERT(!seq.isZero());
00117
00118
00119 typedef typename value_type::ring_type ring_type;
00121
00122 value_type result((ring_type)(m_data));
00123
00124 typename SequenceType::stack_reverse_iterator
00125 start(seq.stackRBegin()), finish(seq.stackREnd());
00126
00127 #ifndef PBORI_NO_TERMS_BY_TAIL
00128 typename BooleSet::navigator navi(result.diagram().navigation());
00129
00130 PBORI_ASSERT((start == finish) || !start->isConstant());
00131 while((start != finish) &&
00132 (start->elseBranch().isEmpty()) && (start->thenBranch() == navi) ) {
00133 navi = *start;
00134 ++start;
00135 }
00136
00137 result = value_type(dd_type(m_data, navi));
00138 #endif
00139
00140 while (start != finish){
00141 result = result.change(**start);
00142 ++start;
00143 }
00144
00145 return result;
00146 }
00147 };
00148
00149
00150 template <class TermType>
00151 class CTermGeneratorBase:
00152 public CTermGeneratorBase__<TermType, type_tag<TermType> > {
00153
00154 };
00155
00156
00157 template <class TermType>
00158 class CTermGenerator:
00159 public CTermGeneratorBase<TermType> {
00160 public:
00161 typedef CTermGeneratorBase<TermType> base;
00162
00163 typedef BoolePolyRing data_type;
00164
00165 CTermGenerator(const data_type&): base() {}
00166 CTermGenerator(const CTermGenerator& rhs): base(rhs) {}
00167 CTermGenerator(): base() {}
00168
00169 };
00170
00171
00172 template <>
00173 class CTermGenerator<BooleMonomial>:
00174 public CTermGeneratorBase__<BooleMonomial, type_tag<BooleMonomial> > {
00175 public:
00176 typedef BooleMonomial term_type;
00177 typedef CTermGeneratorBase__<BooleMonomial, type_tag<BooleMonomial> > base;
00178
00179 typedef base::data_type data_type;
00180
00181 CTermGenerator(const data_type& data): base(data) {}
00182 CTermGenerator(const CTermGenerator& rhs): base(rhs) {}
00183
00184 };
00185
00186 END_NAMESPACE_PBORI
00187
00188 #endif