source: git/libpolys/coeffs/Enumerator.h @ 975db18

spielwiese
Last change on this file since 975db18 was 98474f, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
Abstract iterator/enumerator interfaces + dummies for ClearContent and ClearDenominators
  • Property mode set to 100644
File size: 5.7 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 * @internal @version \$Id$
16 *
17 **/
18/*****************************************************************************/
19
20#ifndef ENUMERATOR_H
21#define ENUMERATOR_H
22
23/** @class IBaseEnumerator
24 *
25 * Base enumerator interface for simple iteration over a generic non-empty collection.
26 *
27 * Abstract API of enumerators for non-empty enumerable collections of standalone
28 * objects. Inspired by IEnumerator from C#. Usage parrten can be as
29 * follows:
30 *
31 * @code
32 *   IBaseEnumerator itr = ...;
33 *   itr.Reset(); // goes to the first element (must exist)
34 *   do
35 *   {
36 *      do something custom with itr...
37 *   }
38 *   while( itr.MoveNext() )
39 * @endcode
40 *
41 * Note that the first element must exist and available directly after Reset() call.
42 *
43 * @sa IEnumerator
44 */
45class IBaseEnumerator // IDisposable
46{
47  public:
48    /// Advances the enumerator to the next element of the collection.
49    /// returns true if the enumerator was successfully advanced to the
50    /// next element;
51    /// false if the enumerator has passed the end of the collection.
52    virtual bool MoveNext() = 0;   
53
54    /// Sets the enumerator to its initial position, which is at the first element in the collection.
55    virtual void Reset() = 0;
56//    virtual ~IEnumerator() {} // TODO: needed?
57};
58
59
60/** @class IAccessor
61 *
62 * Templated accessor interface for accessing individual data (for instance, of an enumerator).
63 *
64 * T is the type of objects to access, available via the Current() method.
65 *
66 * @sa IBaseEnumerator
67 */
68template <typename T>
69class IAccessor // IDisposable
70{
71  public:
72    typedef T value_type;
73    typedef value_type& reference;
74    typedef const value_type& const_reference;
75
76    /// Gets the current element in the collection (read and write).
77    virtual reference Current() = 0;
78
79    /// Gets the current element in the collection (read only).
80    virtual const_reference Current() const = 0;
81};
82
83/** @class IEnumerator
84 *
85 * Templated enumerator interface for simple iteration over a generic non-empty collection of T's.
86 *
87 * Abstract API of enumerators for non-empty enumerable collections of standalone
88 * objects. Inspired by IEnumerator from C#. Usage parrten can be as
89 * follows:
90 *
91 * @code
92 *   IEnumerator<T> itr = ...;
93 *   itr.Reset(); // goes to the first element (must exist)
94 *   do
95 *   {
96 *      use/change itr.Current()...
97 *   }
98 *   while( itr.MoveNext() )
99 * @endcode
100 *
101 * T is the type of objects to enumerate, available via Current() method
102 *
103 * @sa IBaseEnumerator
104 */
105template <typename T>
106class IEnumerator: public virtual IBaseEnumerator, public virtual IAccessor<T>
107{
108  public:
109};
110
111#if 0
112// the following is not used for now //
113// the following is not used for now //
114// the following is not used for now //
115// the following is not used for now //
116// the following is not used for now //
117
118// include basic definitions
119//??// #include <iterator>
120
121/** @class IBaseIterator
122 *
123 * A base abstract iterator API with virtualized standard iterator operators
124 *
125 * Abstract API for iterators that should work with STL and BOOST.
126 *
127 * @sa STL iterators
128 */
129template <class A>
130class IBaseIterator //??// : public std::iterator<std::forward_iterator_tag, A>
131{
132  public:
133    typedef IBaseIterator<A> self;
134    typedef self& self_reference;
135    typedef const self_reference const_self_reference;
136
137    virtual bool operator==(const_self_reference rhs) = 0;
138
139    /// ++itr, goes to the next state, returns the new state
140    virtual self_reference operator++() = 0;
141
142    /// itr++, goes to the next state, returns the previous state
143    virtual self_reference operator++(int) = 0;
144
145    virtual A& operator*() = 0;
146    virtual A* operator->() = 0;
147
148    inline bool operator!=(const_self_reference rhs){ return !((*this) == rhs); }
149};
150
151/** @class AIterator
152 *
153 * An abstract iterator with virtualized assigment operator and
154 * constructors.
155 *
156 * Abstract API for iterators that should work with STL and BOOST.
157 *
158 * @sa STL iterators
159 */
160template <class A>
161class IIterator: public IBaseIterator<A>
162{
163  public:
164    typedef IIterator<A> self;
165    typedef self& self_reference;
166    typedef const self_reference const_self_reference;
167
168    IIterator(){ void_constructor(); }
169
170    IIterator(const_self_reference itr) { copy_constructor(itr); }
171
172    virtual self_reference operator=(const_self_reference other) = 0;
173
174  private:
175    virtual void void_constructor() = 0;
176    virtual void copy_constructor(const_self_reference itr) = 0;
177};
178
179/** @class IContainer
180 *
181 * Container of standalone objects
182 *
183 * Abstract API for containers of objects and their iterators
184 *
185 * @sa STL containers and iterators
186 */
187template <class T>
188class IContainer
189{
190  public:
191    typedef T value_type;
192    typedef value_type& reference;
193    typedef const value_type& const_reference;
194//??//    typedef std::size_t size_type;   
195//??//    virtual size_type size() const = 0;
196    virtual bool empty() const = 0;
197
198    typedef IIterator<reference> iterator;
199    virtual iterator begin() = 0;
200    virtual iterator end() = 0;
201
202    typedef IIterator<const_reference> const_iterator;
203    virtual const_iterator begin() const = 0;
204    virtual const_iterator end() const = 0;
205};
206#endif
207
208
209#endif
210/* #ifndef ENUMERATOR_H */
211
212// Vi-modeline: vim: filetype=c:syntax:shiftwidth=2:tabstop=8:textwidth=0:expandtab
Note: See TracBrowser for help on using the repository browser.