source: git/libpolys/polys/PolyEnumerator.h @ 975db18

spielwiese
Last change on this file since 975db18 was 975db18, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
implementing PolyCoeffsEnumerator: enumerator for simple iteration over coefficients of a (non-zero) polynomial. add: added dummy stubs for calling n_ClearContent and n_ClearDenominators from p_Content and p_Cleardenom
  • Property mode set to 100644
File size: 3.2 KB
Line 
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 * @internal @version \$Id$
12 *
13 **/
14/*****************************************************************************/
15
16#ifndef POLYENUMERATOR_H
17#define POLYENUMERATOR_H
18
19// include basic definitions
20#include <coeffs/Enumerator.h>
21#include <polys/monomials/monomials.h>
22
23/** @class CBasePolyEnumerator
24 *
25 * Base polynomial enumerator for simple iteration over terms of
26 * (non-zero) polynomials.
27 *
28 * Note that the first element must exist directly after Reset() call.
29 * Moreover, it doesn't inherit from IAccessor and thus doesn't
30 * override Current().
31 *
32 * @sa IBaseEnumerator, @sa CPolyCoeffsEnumerator
33 */
34class CBasePolyEnumerator: public virtual IBaseEnumerator
35{
36  private:
37    const poly m_poly;
38
39  protected:
40    poly m_position;
41   
42    inline void Iterate()
43    {
44      if( m_position != NULL )
45        pIter( m_position );
46    }   
47  public:
48    CBasePolyEnumerator(poly p): m_poly(p), m_position(p) { assume(p != NULL); }
49   
50    /// Sets the position marker to the leading term.
51    virtual void Reset() { assume(m_poly!= NULL); m_position = m_poly; }
52
53    /// Advances the position to the next term of the polynomial.
54    /// returns true if the position marker was successfully advanced to the
55    /// next term;
56    /// false if the position marker has passed the end of the
57    /// polynomial.
58    virtual bool MoveNext()
59    {
60      assume( m_position != NULL );
61      Iterate();
62      return (m_position != NULL);
63    }
64};
65
66
67/// This is the interface we use in coeffs.h for ClearDenominators and
68/// ClearContent.
69typedef IEnumerator<number> IPolyCoeffsEnumerator;
70
71/** @class CPolyCoeffsEnumerator
72 *
73 * This is a polynomial enumerator for simple iteration over
74 * coefficients of (non-zero) polynomials.
75 *
76 * It is required to inherit this class from IEnumerator<number> for
77 * its use in coeffs and implement IAccessor<number> interface.
78 *
79 * Note also the virtual multiple inheritance due to the diamond
80 * problem of inheriting both CBasePolyEnumerator and IEnumerator<T>
81 * from IBaseEnumerator.
82 *
83 * @sa CBasePolyEnumerator, @sa IEnumerator
84 */
85class CPolyCoeffsEnumerator: public CBasePolyEnumerator, public virtual IPolyCoeffsEnumerator
86{
87  public:
88    CPolyCoeffsEnumerator(poly p): CBasePolyEnumerator(p) { assume(p != NULL); }
89   
90    /// Gets the current element in the collection (read and write).
91    virtual IPolyCoeffsEnumerator::reference Current()
92    {
93      assume( m_position != NULL );
94      return pGetCoeff(m_position);     
95    }
96
97    /// Gets the current element in the collection (read only).
98    virtual IPolyCoeffsEnumerator::const_reference Current() const
99    {
100      assume( m_position != NULL );
101      return pGetCoeff(m_position);
102    }
103};
104
105#endif
106/* #ifndef POLYENUMERATOR_H */
107
108// Vi-modeline: vim: filetype=c:syntax:shiftwidth=2:tabstop=8:textwidth=0:expandtab
109
Note: See TracBrowser for help on using the repository browser.