-
Notifications
You must be signed in to change notification settings - Fork 3
/
iterator.h
56 lines (41 loc) · 1.42 KB
/
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
48
49
50
51
52
53
54
55
//-< ITERATOR.H >----------------------------------------------------*--------*
// Created: 05-Apr-03 Johan Sorensen * / [] \ *
// Last update: 05-Apr-03 Johan Sorensen * GARRET *
//-------------------------------------------------------------------*--------*
// Iterator implementation
//-------------------------------------------------------------------*--------*
#ifndef __ITERATOR_H__
#define __ITERATOR_H__
#include "ttree.h"
#include "dnmarr.h"
BEGIN_POST_NAMESPACE
// it should be possible (and quite easy) to make iterators for any kind of container
// using this generic "interface"
template<class T>
class basic_iterator
{
public:
virtual bool IsValid () const = 0;
virtual T* operator* () = 0;
virtual T* operator++ () = 0;
virtual T* operator-- () = 0;
};
// here is a concrete instantiation for the Ttree container
class Ttree_iterator : public basic_iterator<object>
{
public:
Ttree_iterator(dbTtree *t,
bool bReverseOrder = false); // for backwards traversal
virtual~Ttree_iterator();
bool IsValid () const;
object* operator* ();
object* operator++ ();
object* operator-- ();
private:
dbTtreeNode* m_CurrNode;
long m_CurrPos; // -1 --> "invalid"
dnm_array<dbTtreeNode*> m_NodeStack;
dnm_array<long> m_PositionStack;
};
END_POST_NAMESPACE
#endif // __ITERATOR_H