source: git/libpolys/coeffs/Enumerator.h @ 560a3d

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