My Project
Loading...
Searching...
No Matches
Enumerator.h
Go to the documentation of this file.
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
63
64 protected:
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;
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:
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
132// include basic definitions
133//??// #include <iterator>
134
135/** @class IBaseIterator
136 *
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
166 *
167 * An abstract iterator with virtualized assignment operator and
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
194 *
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;
208//??// typedef std::size_t size_type;
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};
220#endif
221
222
223#endif
224/* #ifndef ENUMERATOR_H */
225
226// Vi-modeline: vim: filetype=c:syntax:shiftwidth=2:tabstop=8:textwidth=0:expandtab
bool operator!=(const Rational &a, const Rational &b)
Definition: GMPrat.cc:318
bool operator==(const Rational &a, const Rational &b)
Definition: GMPrat.cc:312
Templated accessor interface for accessing individual data (for instance, of an enumerator).
Definition: Enumerator.h:82
const value_type & const_reference
Definition: Enumerator.h:86
~IAccessor()
Definition: Enumerator.h:96
T value_type
Definition: Enumerator.h:84
virtual const_reference Current() const =0
Gets the current element in the collection (read only).
value_type & reference
Definition: Enumerator.h:85
virtual reference Current()=0
Gets the current element in the collection (read and write).
Base enumerator interface for simple iteration over a generic collection.
Definition: Enumerator.h:44
virtual bool IsValid() const =0
Current position is inside the collection (not -1 or past the end)
void operator=(const IBaseEnumerator &)
IBaseEnumerator(const IBaseEnumerator &)
disable copy constructor and assignment operator
virtual void Reset()=0
Sets the enumerator to its initial position: -1, which is before the first element in the collection.
virtual bool MoveNext()=0
Advances the enumerator to the next element of the collection. returns true if the enumerator was suc...
Templated enumerator interface for simple iteration over a generic collection of T's.
Definition: Enumerator.h:125
fglmVector operator*(const fglmVector &v, const number n)
Definition: fglmvec.cc:426
STATIC_VAR jList * T
Definition: janet.cc:30
#define A
Definition: sirandom.c:24