source: git/libpolys/coeffs/Enumerator.h @ 0acf3e

spielwiese
Last change on this file since 0acf3e was dc79bd, checked in by Oleksandr Motsak <motsak@…>, 11 years ago
Major Update for Enumerators + Fixes for Algrbraic & Transcendental extensions General: chg: cleanup + documentation + additional assumes Enumerators: chg: some polish on Enumerators add: CRecursivePolyCoeffsEnumerator<ConverterPolicy> for recursive treatment of converted coeffs as Enumerators Coeffs: chg: use mpz_lcm for readability in nlClearDenominators + cleanup add: nlClear*NoPositiveLead variants should not make LC positive chg: all nlClear* are not static in order to be usable from alg / trans exts. fix: fixed a bug in ndClearContent AlgExt: add: nCoeff_is_Q_algext for checking an alg. ext. of Q add: naClear* for alg. ext. over Q NOTE: coeffs are polynomials in Q[a] - one should simply consider each of them recursively as a collection of numbers... NOTE: compute GCDs over Alg. Ext... + gcds of (int.) numbers!? NOTE: trying to be conform with older Singular: no negative leading coeff. normalization chg: Alg. Ext: use singclap_*gcd (instead of Frank's gcd-stuff) p_poly: add: p_Cleardenom_n/p_Cleardenom also clear content afterwards... chg: major and minor changes to p_Content/p_Cleardenom_n/p_Cleardenom + cleanup add: additionally trying to assure positive leading coeff. after p_Content/p_Cleardenom_n(/p_Cleardenom?) NOTE: which should not be needed as n_ClearDenominators/n_ClearContent are supposed to assure that themselves! add: more assumes to p_polys.cc NOTE: massive usage of enumerators form p_* causes problems - only doing that for Q_a()! NOTE: do -normalization over Q(x...) TransExt: add: ntClear* for trans. ext's fix: correct ntGetDenom/ntGetNumerator (thanks to pSubstPar), NOTE: no negative denominator out of ntGetNumerator/ntGetDenom! add: first inefficient ntClearContent/Q and ntClearDenominators/Q & F_p impl. NOTE: careful with the use of nlClear* ! (only over Q!) add: added ntTest to transext.cc on most in/outs + use ntInit(poly)! NOTE: trying to fix the monic-poly-gcd problem in ntClearDenominators!
  • Property mode set to 100644
File size: 6.1 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 Enumerator.h
6 *
7 * Abstract API for enumerators.
8 *
9 * ABSTRACT: Abstract interface for forward iteratable containers (enumerators)
10 * of standalone objects (e.g. polynomials as sets of numbers), without any
11 * knowledge of their internals.
12 *
13 * @author Oleksandr Motsak
14 *
15 *
16 **/
17/*****************************************************************************/
18
19#ifndef ENUMERATOR_H
20#define ENUMERATOR_H
21
22/** @class IBaseEnumerator
23 *
24 * Base enumerator interface for simple iteration over a generic collection.
25 *
26 * Abstract API of enumerators for enumerable collections of standalone objects.
27 * Just like IEnumerator from C#. Usage pattern can be as follows:
28 *
29 * @code
30 *   IBaseEnumerator& itr = ...;
31 *   itr.Reset(); // goes to the "-1" element
32 *   // NOTE: itr is not useable here!
33 *   while( itr.MoveNext() )
34 *   {
35 *      do something custom with itr...
36 *   }
37 * @endcode
38 *
39 * Note that the Reset()
40 *
41 * @sa IEnumerator
42 */
43class IBaseEnumerator // IDisposable
44{
45  public:
46    /// Advances the enumerator to the next element of the collection.
47    /// returns true if the enumerator was successfully advanced to the
48    /// next element;
49    /// false if the enumerator has passed the end of the collection.
50    virtual bool MoveNext() = 0;   
51
52    /// Sets the enumerator to its initial position: -1,
53    /// which is before the first element in the collection.
54    virtual void Reset() = 0;
55
56    /// Current position is inside the collection (not -1 or past the end)
57    virtual bool IsValid() const = 0;
58   
59  private:
60    /// disable copy constructor and assigment operator
61    IBaseEnumerator(const IBaseEnumerator&);
62    void operator=(const IBaseEnumerator&);
63
64  protected:
65    IBaseEnumerator(){}
66    ~IBaseEnumerator() {} // TODO: needed?
67
68
69};
70
71
72/** @class IAccessor
73 *
74 * Templated accessor interface for accessing individual data (for instance, of an enumerator).
75 *
76 * T is the type of objects to access, available via the Current() method.
77 *
78 * @sa IBaseEnumerator
79 */
80template <typename T>
81class IAccessor // IDisposable
82{
83  public:
84    typedef T value_type;
85    typedef value_type& reference;
86    typedef const value_type& const_reference;
87
88    /// Gets the current element in the collection (read and write).
89    virtual reference Current() = 0;
90
91    /// Gets the current element in the collection (read only).
92    virtual const_reference Current() const = 0;
93
94 protected:
95    IAccessor(){}   
96    ~IAccessor() {} // TODO: needed?
97 
98};
99
100/** @class IEnumerator
101 *
102 * Templated enumerator interface for simple iteration over a generic collection of T's.
103 *
104 * Abstract API of enumerators for generic enumerable collections of standalone
105 * objects of type T. Inspired by IEnumerator from C#. Usage parrten can be as
106 * follows:
107 *
108 * @code
109 *   IEnumerator<T>& itr = ...;
110 *   
111 *   itr.Reset(); // goes before the first element, thus no itr.Current() is available here!
112 *   
113 *   while( itr.MoveNext() )
114 *   {
115 *      use/change itr.Current()...
116 *   }
117 * @endcode
118 *
119 * T is the type of objects to enumerate, available via Current() method
120 *
121 * @sa IBaseEnumerator
122 */
123template <typename T>
124class IEnumerator: public virtual IBaseEnumerator, public virtual IAccessor<T>
125{
126  public:
127};
128
129#if 0
130// the following is not used for now //
131// the following is not used for now //
132// the following is not used for now //
133// the following is not used for now //
134// the following is not used for now //
135
136// include basic definitions
137//??// #include <iterator>
138
139/** @class IBaseIterator
140 *
141 * A base abstract iterator API with virtualized standard iterator operators
142 *
143 * Abstract API for iterators that should work with STL and BOOST.
144 *
145 * @sa STL iterators
146 */
147template <class A>
148class IBaseIterator //??// : public std::iterator<std::forward_iterator_tag, A>
149{
150  public:
151    typedef IBaseIterator<A> self;
152    typedef self& self_reference;
153    typedef const self_reference const_self_reference;
154
155    virtual bool operator==(const_self_reference rhs) = 0;
156
157    /// ++itr, goes to the next state, returns the new state
158    virtual self_reference operator++() = 0;
159
160    /// itr++, goes to the next state, returns the previous state
161    virtual self_reference operator++(int) = 0;
162
163    virtual A& operator*() = 0;
164    virtual A* operator->() = 0;
165
166    inline bool operator!=(const_self_reference rhs){ return !((*this) == rhs); }
167};
168
169/** @class AIterator
170 *
171 * An abstract iterator with virtualized assigment operator and
172 * constructors.
173 *
174 * Abstract API for iterators that should work with STL and BOOST.
175 *
176 * @sa STL iterators
177 */
178template <class A>
179class IIterator: public IBaseIterator<A>
180{
181  public:
182    typedef IIterator<A> self;
183    typedef self& self_reference;
184    typedef const self_reference const_self_reference;
185
186    IIterator(){ void_constructor(); }
187
188    IIterator(const_self_reference itr) { copy_constructor(itr); }
189
190    virtual self_reference operator=(const_self_reference other) = 0;
191
192  private:
193    virtual void void_constructor() = 0;
194    virtual void copy_constructor(const_self_reference itr) = 0;
195};
196
197/** @class IContainer
198 *
199 * Container of standalone objects
200 *
201 * Abstract API for containers of objects and their iterators
202 *
203 * @sa STL containers and iterators
204 */
205template <class T>
206class IContainer
207{
208  public:
209    typedef T value_type;
210    typedef value_type& reference;
211    typedef const value_type& const_reference;
212//??//    typedef std::size_t size_type;   
213//??//    virtual size_type size() const = 0;
214    virtual bool empty() const = 0;
215
216    typedef IIterator<reference> iterator;
217    virtual iterator begin() = 0;
218    virtual iterator end() = 0;
219
220    typedef IIterator<const_reference> const_iterator;
221    virtual const_iterator begin() const = 0;
222    virtual const_iterator end() const = 0;
223};
224#endif
225
226
227#endif
228/* #ifndef ENUMERATOR_H */
229
230// Vi-modeline: vim: filetype=c:syntax:shiftwidth=2:tabstop=8:textwidth=0:expandtab
Note: See TracBrowser for help on using the repository browser.