summaryrefslogtreecommitdiff
path: root/omegalib/omega/include/basic/Section.h
blob: 60821d1284cfd448d0fb7816df45df26f18bd690 (plain)
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
56
57
58
59
60
61
62
63
#if ! defined _Section_h
#define _Section_h 1
/*
  Section of an existing collection viewed as a collection
  */

#include <basic/Collection.h>

namespace omega {

template<class T> class Section_Iterator;

template <class T> class Section : public Sequence<T> {
public:
    Section(Sequence<T> *, int start, int length);

    Iterator<T> *new_iterator();

    const T &operator[](int) const;
          T &operator[](int);      

    int index(const T &) const;
    int size() const;

    friend class Section_Iterator<T>;

private:
    Sequence<T> *it;
    int _start, _length;
};

template <class T> class Section_Iterator : public Iterator<T> {
public:
               Section_Iterator(Section<T> &sec);
       virtual ~Section_Iterator() { delete it; }

    const T &  operator*() const	{ return *(*it); }
          T &  operator*()		{ return *(*it); }

       void    operator++(int);
       void    operator++();
    
       bool    live() const;
  Iterator<T> *new_copy() const;

private:
    Section_Iterator(const Section_Iterator<T> &si);
    Iterator<T> *it;
    int remaining;
};

} // namespace

#if ! defined DONT_INCLUDE_TEMPLATE_CODE
#include <basic/Section.c>
#endif

#define instantiate_Section(T)	template class Section<T>; \
				template class Section_Iterator<T>; \
				instantiate_Sequence(T)
#define instantiate_Section_Iterator(T)	  instantiate_Section(T)

#endif