base_cursor.hpp 1.79 KB
Newer Older
1
// Software License for MTL
2
//
3
4
5
6
7
// Copyright (c) 2007 The Trustees of Indiana University.
//               2008 Dresden University of Technology and the Trustees of Indiana University.
//               2010 SimuNova UG (haftungsbeschränkt), www.simunova.com.
// All rights reserved.
// Authors: Peter Gottschling and Andrew Lumsdaine
8
//
9
// This file is part of the Matrix Template Library
10
//
11
12
13
14
15
16
17
18
// See also license.mtl.txt in the distribution.

#ifndef MTL_BASE_CURSOR_INCLUDE
#define MTL_BASE_CURSOR_INCLUDE

namespace mtl { namespace detail {

// base class for different cursors, works with pointers and integers
19
template <class Key> class base_cursor
20
21
22
23
24
{
 public:
    typedef Key          key_type;
    typedef base_cursor  self;

25
    base_cursor () {}
26
27
    base_cursor (key_type key) : key(key) {}

28
29
30
    key_type operator*() const
    {
      return key;
31
32
    }

33
34
35
    key_type value() const
    {
      return key;
36
37
    }

38
39
40
    self& operator++ ()
    {
      ++key; return *this;
41
    }
42
43
44
45
46
    self operator++ (int)
    {
      self tmp = *this;
      ++key;
      return tmp;
47
    }
48
49
50
51
    self& operator-- ()
    {
      --key;
      return *this;
52
    }
53
54
55
56
57
    self operator-- (int)
    {
      self tmp = *this;
      --key;
      return tmp;
58
    }
59
60
61
62
    self& operator+=(int n)
    {
      key += n;
      return *this;
63
    }
64

65
66
67
68
69
70
    self operator+(int n) const
    {
	self tmp = *this;
	tmp+= n;
	return tmp;
    }
71
72
73
74
75

    self& operator-=(int n)
    {
      key -= n;
      return *this;
76
77
    }

78
    int operator-(const self& cc) const
79
80
81
82
    {
	return this->key - cc.key;
    }

83
    bool operator==(const self& cc) const
84
    {
85
      return key == cc.key;
86
87
    }

88
    bool operator!=(const self& cc) const
89
    {
90
      return !(*this == cc);
91
    }
92
93


94
95
96
97
98
99
100


    key_type key;
}; // base_cursor



101
}} // namespace mtl::detail
102

103
#endif // MTL_BASE_CURSOR_INCLUDE
104
105