source: git/libpolys/coeffs/Enumerator.h

spielwiese
Last change on this file was e256b4, checked in by Hans Schoenemann <hannes@…>, 6 years ago
move ssiInfo to s_buff.h
  • Property mode set to 100644
File size: 5.9 KB
RevLine 
[98474f]1// -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2/*****************************************************************************\
[fea494]3 * Computer Algebra System SINGULAR
[98474f]4\*****************************************************************************/
5/** @file Enumerator.h
6 *
7 * Abstract API for enumerators.
[fea494]8 *
[98474f]9 * ABSTRACT: Abstract interface for forward iteratable containers (enumerators)
10 * of standalone objects (e.g. polynomials as sets of numbers), without any
[fea494]11 * knowledge of their internals.
[98474f]12 *
13 * @author Oleksandr Motsak
14 *
15 *
16 **/
17/*****************************************************************************/
18
19#ifndef ENUMERATOR_H
20#define ENUMERATOR_H
21
22/** @class IBaseEnumerator
[fea494]23 *
[9952bd]24 * Base enumerator interface for simple iteration over a generic collection.
[98474f]25 *
[9952bd]26 * Abstract API of enumerators for enumerable collections of standalone objects.
27 * Just like IEnumerator from C#. Usage pattern can be as follows:
[98474f]28 *
29 * @code
[9952bd]30 *   IBaseEnumerator& itr = ...;
31 *   itr.Reset(); // goes to the "-1" element
32 *   // NOTE: itr is not useable here!
33 *   while( itr.MoveNext() )
[98474f]34 *   {
35 *      do something custom with itr...
36 *   }
37 * @endcode
38 *
[fea494]39 * Note that the Reset()
[98474f]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.
[fea494]50    virtual bool MoveNext() = 0;
[98474f]51
[9952bd]52    /// Sets the enumerator to its initial position: -1,
53    /// which is before the first element in the collection.
[98474f]54    virtual void Reset() = 0;
[9952bd]55
[dc79bd]56    /// Current position is inside the collection (not -1 or past the end)
57    virtual bool IsValid() const = 0;
[fea494]58
[9952bd]59  private:
[88615db]60    /// disable copy constructor and assignment operator
[9952bd]61    IBaseEnumerator(const IBaseEnumerator&);
62    void operator=(const IBaseEnumerator&);
63
64  protected:
65    IBaseEnumerator(){}
[dc79bd]66    ~IBaseEnumerator() {} // TODO: needed?
67
[9952bd]68
[98474f]69};
70
71
72/** @class IAccessor
[fea494]73 *
[98474f]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;
[9952bd]93
[dc79bd]94 protected:
[fea494]95    IAccessor(){}
[dc79bd]96    ~IAccessor() {} // TODO: needed?
[fea494]97
[98474f]98};
99
100/** @class IEnumerator
[fea494]101 *
[9952bd]102 * Templated enumerator interface for simple iteration over a generic collection of T's.
[98474f]103 *
[9952bd]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
[98474f]106 * follows:
107 *
108 * @code
[9952bd]109 *   IEnumerator<T>& itr = ...;
[fea494]110 *
[9952bd]111 *   itr.Reset(); // goes before the first element, thus no itr.Current() is available here!
[fea494]112 *
[9952bd]113 *   while( itr.MoveNext() )
[98474f]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
132// include basic definitions
133//??// #include <iterator>
134
135/** @class IBaseIterator
[fea494]136 *
[98474f]137 * A base abstract iterator API with virtualized standard iterator operators
138 *
139 * Abstract API for iterators that should work with STL and BOOST.
140 *
141 * @sa STL iterators
142 */
143template <class A>
144class IBaseIterator //??// : public std::iterator<std::forward_iterator_tag, A>
145{
146  public:
147    typedef IBaseIterator<A> self;
148    typedef self& self_reference;
149    typedef const self_reference const_self_reference;
150
151    virtual bool operator==(const_self_reference rhs) = 0;
152
153    /// ++itr, goes to the next state, returns the new state
154    virtual self_reference operator++() = 0;
155
156    /// itr++, goes to the next state, returns the previous state
157    virtual self_reference operator++(int) = 0;
158
159    virtual A& operator*() = 0;
160    virtual A* operator->() = 0;
161
162    inline bool operator!=(const_self_reference rhs){ return !((*this) == rhs); }
163};
164
165/** @class AIterator
[fea494]166 *
[88615db]167 * An abstract iterator with virtualized assignment operator and
[98474f]168 * constructors.
169 *
170 * Abstract API for iterators that should work with STL and BOOST.
171 *
172 * @sa STL iterators
173 */
174template <class A>
175class IIterator: public IBaseIterator<A>
176{
177  public:
178    typedef IIterator<A> self;
179    typedef self& self_reference;
180    typedef const self_reference const_self_reference;
181
182    IIterator(){ void_constructor(); }
183
184    IIterator(const_self_reference itr) { copy_constructor(itr); }
185
186    virtual self_reference operator=(const_self_reference other) = 0;
187
188  private:
189    virtual void void_constructor() = 0;
190    virtual void copy_constructor(const_self_reference itr) = 0;
191};
192
193/** @class IContainer
[fea494]194 *
[98474f]195 * Container of standalone objects
196 *
197 * Abstract API for containers of objects and their iterators
198 *
199 * @sa STL containers and iterators
200 */
201template <class T>
202class IContainer
203{
204  public:
205    typedef T value_type;
206    typedef value_type& reference;
207    typedef const value_type& const_reference;
[fea494]208//??//    typedef std::size_t size_type;
[98474f]209//??//    virtual size_type size() const = 0;
210    virtual bool empty() const = 0;
211
212    typedef IIterator<reference> iterator;
213    virtual iterator begin() = 0;
214    virtual iterator end() = 0;
215
216    typedef IIterator<const_reference> const_iterator;
217    virtual const_iterator begin() const = 0;
218    virtual const_iterator end() const = 0;
219};
[fea494]220#endif
[98474f]221
222
[fea494]223#endif
[98474f]224/* #ifndef ENUMERATOR_H */
225
226// Vi-modeline: vim: filetype=c:syntax:shiftwidth=2:tabstop=8:textwidth=0:expandtab
Note: See TracBrowser for help on using the repository browser.