-
Notifications
You must be signed in to change notification settings - Fork 0
/
Iterator.h
47 lines (40 loc) · 983 Bytes
/
Iterator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once
#ifndef Iterator_H_
#define Iterator_H_
/*! Base class for iterators.
*/
template<class T> class Iterator
{
public:
virtual ~Iterator() {}
virtual void First() = 0;
virtual void Next() = 0;
virtual bool IsDone() = 0;
virtual T Current() = 0;
};
/*! Iterator smart pointer
*/
template <class T> class IteratorPtr
{
public:
IteratorPtr(Iterator<T> * i) : _iter(i) {}
~IteratorPtr() {delete _iter;}
Iterator<T> *operator->() {return _iter;}
Iterator<T> &operator*() {return *_iter;}
private:
IteratorPtr();
IteratorPtr(const IteratorPtr *);
IteratorPtr &operator=(IteratorPtr &);
//! The pointer to the actual iterator
Iterator<T> *_iter;
};
//! General purpose null iterator
template <class T> class CNullIterator : public Iterator<T>
{
public:
virtual void First() {}
virtual void Next() {}
virtual bool IsDone() {return true;}
virtual T Current() {return NULL;}
};
#endif /* Iterator_H_ */