00001
00002
00014
00015
00016 #ifndef polybori_orderings_CBlockOrderingFacade_h_
00017 #define polybori_orderings_CBlockOrderingFacade_h_
00018
00019 #include "COrderingFacade.h"
00020
00021 BEGIN_NAMESPACE_PBORI
00022
00027 template <class OrderType, class OrderTag>
00028 class CBlockOrderingFacade:
00029 public COrderingFacade <OrderType, OrderTag> {
00030
00031 typedef CBlockOrderingFacade self;
00032 typedef COrderingFacade<OrderType, OrderTag> base_type;
00033
00034 public:
00035
00037 typedef self base;
00038
00040
00041 typedef typename base_type::order_lead_tag order_lead_tag;
00042 typedef typename base_type::poly_type poly_type;
00043 typedef typename base_type::monom_type monom_type;
00044 typedef typename base_type::exp_type exp_type;
00045 typedef typename base_type::deg_type deg_type;
00046 typedef typename base_type::set_type set_type;
00047 typedef typename base_type::comp_type comp_type;
00049
00051 CBlockOrderingFacade(): base_type(), m_indices() {
00052 m_indices.push_back(0);
00053 m_indices.push_back(CTypes::max_index());
00054 };
00055
00057 CBlockOrderingFacade(const self& rhs): base_type(rhs), m_indices(rhs.m_indices) {};
00058
00060 ~CBlockOrderingFacade() = 0;
00061
00063
00064 COrderingBase::block_iterator blockBegin() const { return m_indices.begin() + 1; }
00065 COrderingBase::block_iterator blockEnd() const { return m_indices.end(); }
00066
00067 void appendBlock(COrderingBase::checked_idx_type idx) {
00068
00069
00070 PBORI_ASSERT(idx <= *(blockEnd() - 1));
00071
00072 if PBORI_UNLIKELY((idx >= CTypes::max_index()) || (idx <= *(blockEnd() - 2)))
00073 throw std::runtime_error("Blocks must be positive and have to be "
00074 "added in a strictly increasing order.");
00075
00076 m_indices.back() = idx;
00077 m_indices.push_back(CTypes::max_index());
00078 }
00079
00080 void clearBlocks() {
00081 m_indices.clear();
00082 m_indices.push_back(0);
00083 m_indices.push_back(CTypes::max_index());
00084 }
00086
00088 monom_type lead(const poly_type& poly) const {
00089
00090 CBlockDegreeCache<set_type> blockDegCache(poly.ring());
00091 CacheManager<order_lead_tag> cache_mgr(poly.ring());
00092 typename base_type::descending_property descending;
00093
00094 return base_type::monom( dd_block_degree_lead(cache_mgr, blockDegCache,
00095 poly.navigation(), m_indices.begin(),
00096 set_type(poly.ring()), descending) );
00097 }
00098
00101 monom_type lead(const poly_type& poly, deg_type) const {
00102 return lead(poly);
00103 }
00104
00106 exp_type leadExp(const poly_type& poly) const {
00107 return lead(poly).exp();
00108 }
00109
00112 exp_type leadExp(const poly_type& poly, deg_type) const {
00113 return leadExp(poly);
00114 }
00115
00116 protected:
00117
00119 template <class TermType, class BinOpType>
00120 comp_type compare_terms(const TermType& lhs, const TermType& rhs,
00121 const BinOpType& idx_comparer) const {
00122
00123 return block_dlex_compare(lhs.begin(), lhs.end(),rhs.begin(), rhs.end(),
00124 blockBegin(), blockEnd(), idx_comparer);
00125 }
00126
00128 COrderingBase::block_idx_type m_indices;
00129 };
00130
00131 template <class OrderType, class OrderTag>
00132 inline CBlockOrderingFacade<OrderType, OrderTag>::~CBlockOrderingFacade() {}
00133
00134 END_NAMESPACE_PBORI
00135
00136 #endif