1 | // -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
---|
2 | /*****************************************************************************\ |
---|
3 | * Computer Algebra System SINGULAR |
---|
4 | \*****************************************************************************/ |
---|
5 | /** @file PolyEnumerator.h |
---|
6 | * |
---|
7 | * Concrete implementation of enumerators over polynomials |
---|
8 | * |
---|
9 | * @author Oleksandr Motsak |
---|
10 | * |
---|
11 | * |
---|
12 | **/ |
---|
13 | /*****************************************************************************/ |
---|
14 | |
---|
15 | #ifndef POLYENUMERATOR_H |
---|
16 | #define POLYENUMERATOR_H |
---|
17 | |
---|
18 | // include basic definitions |
---|
19 | #include <coeffs/Enumerator.h> |
---|
20 | #include <polys/monomials/monomials.h> |
---|
21 | |
---|
22 | /** @class CBasePolyEnumerator |
---|
23 | * |
---|
24 | * Base polynomial enumerator for simple iteration over terms of |
---|
25 | * (non-zero) polynomials. |
---|
26 | * |
---|
27 | * Note that the first element must exist directly after Reset() call. |
---|
28 | * Moreover, it doesn't inherit from IAccessor and thus doesn't |
---|
29 | * override Current(). |
---|
30 | * |
---|
31 | * @sa IBaseEnumerator, @sa CPolyCoeffsEnumerator |
---|
32 | */ |
---|
33 | class CBasePolyEnumerator: public virtual IBaseEnumerator |
---|
34 | { |
---|
35 | private: |
---|
36 | const poly m_poly; |
---|
37 | |
---|
38 | protected: |
---|
39 | poly m_position; |
---|
40 | |
---|
41 | inline void Iterate() |
---|
42 | { |
---|
43 | if( m_position != NULL ) |
---|
44 | pIter( m_position ); |
---|
45 | } |
---|
46 | public: |
---|
47 | CBasePolyEnumerator(poly p): m_poly(p), m_position(p) { assume(p != NULL); } |
---|
48 | |
---|
49 | /// Sets the position marker to the leading term. |
---|
50 | virtual void Reset() { assume(m_poly!= NULL); m_position = m_poly; } |
---|
51 | |
---|
52 | /// Advances the position to the next term of the polynomial. |
---|
53 | /// returns true if the position marker was successfully advanced to the |
---|
54 | /// next term; |
---|
55 | /// false if the position marker has passed the end of the |
---|
56 | /// polynomial. |
---|
57 | virtual bool MoveNext() |
---|
58 | { |
---|
59 | assume( m_position != NULL ); |
---|
60 | Iterate(); |
---|
61 | return (m_position != NULL); |
---|
62 | } |
---|
63 | }; |
---|
64 | |
---|
65 | |
---|
66 | /// This is the interface we use in coeffs.h for ClearDenominators and |
---|
67 | /// ClearContent. |
---|
68 | typedef IEnumerator<number> IPolyCoeffsEnumerator; |
---|
69 | |
---|
70 | /** @class CPolyCoeffsEnumerator |
---|
71 | * |
---|
72 | * This is a polynomial enumerator for simple iteration over |
---|
73 | * coefficients of (non-zero) polynomials. |
---|
74 | * |
---|
75 | * It is required to inherit this class from IEnumerator<number> for |
---|
76 | * its use in coeffs and implement IAccessor<number> interface. |
---|
77 | * |
---|
78 | * Note also the virtual multiple inheritance due to the diamond |
---|
79 | * problem of inheriting both CBasePolyEnumerator and IEnumerator<T> |
---|
80 | * from IBaseEnumerator. |
---|
81 | * |
---|
82 | * @sa CBasePolyEnumerator, @sa IEnumerator |
---|
83 | */ |
---|
84 | class CPolyCoeffsEnumerator: public CBasePolyEnumerator, public virtual IPolyCoeffsEnumerator |
---|
85 | { |
---|
86 | public: |
---|
87 | CPolyCoeffsEnumerator(poly p): CBasePolyEnumerator(p) { assume(p != NULL); } |
---|
88 | |
---|
89 | /// Gets the current element in the collection (read and write). |
---|
90 | virtual IPolyCoeffsEnumerator::reference Current() |
---|
91 | { |
---|
92 | assume( m_position != NULL ); |
---|
93 | return pGetCoeff(m_position); |
---|
94 | } |
---|
95 | |
---|
96 | /// Gets the current element in the collection (read only). |
---|
97 | virtual IPolyCoeffsEnumerator::const_reference Current() const |
---|
98 | { |
---|
99 | assume( m_position != NULL ); |
---|
100 | return pGetCoeff(m_position); |
---|
101 | } |
---|
102 | }; |
---|
103 | |
---|
104 | #endif |
---|
105 | /* #ifndef POLYENUMERATOR_H */ |
---|
106 | |
---|
107 | // Vi-modeline: vim: filetype=c:syntax:shiftwidth=2:tabstop=8:textwidth=0:expandtab |
---|
108 | |
---|