source: git/libpolys/coeffs/Enumerator.h @ 2a4a23

fieker-DuValspielwiese
Last change on this file since 2a4a23 was 88615db, checked in by jgmbenoit <quatermaster@…>, 9 years ago
correct some spelling errors: Correct spelling error as reported by lintian in some binraries; meant to silence lintian.
  • Property mode set to 100644
File size: 6.0 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 assignment 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 assignment 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.