summaryrefslogtreecommitdiffstats
path: root/raslib/miter.hh
blob: 98ee03c519c7686ecdc3308078f4e0176200b1da (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* This file is part of rasdaman community.
*
* Rasdaman community is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Rasdaman community is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
rasdaman GmbH.
*
* For more information please see <http://www.rasdaman.org>
* or contact Peter Baumann via <baumann@rasdaman.com>.
/
/**
 * INCLUDE: miter.hh
 *
 * MODULE:  raslib
 * CLASS:   r_Miter
 *
*/

#ifndef _D_MITER_
#define _D_MITER_

class r_Minterval;

//@ManMemo: Module: {\bf raslib}

/*@Doc:
  r_Miter is used for iterating through parts of 
  multidimensional intervals. It is given the domain of
  the object to be iterated through, the size of the base
  base type, the address of the first cell in the Tile and
  an Minterval specifying the area to be iterated through.

  Going to the next cell is done with nextCell() which 
  returns the adress of the next cell. Test for the end 
  is done with isDone(). The iterator can be reset with
  reset().
*/

class r_Miter
{
public:
  /// constructor.
  inline r_Miter( const r_Minterval* newAreaIter, 
		  const r_Minterval* newAreaTile, r_Bytes newCellSize, 
		  const char* newFirstCell );
  /**
    The pointers are stored, do not delete the objects as long
    as the iterator is used!
  */
  
  /// destructor.
  inline ~r_Miter();                    
  /// resets iterator to first cell.
  inline void reset();
  /// returns current cell and sets iterator to next cell.
  inline char* nextCell();
  /// returns TRUE if iteration is finished.
  inline bool isDone();
protected:
  // structure storing information on iteration for each dimension
  // (perhaps add dimension for reordering later)
  typedef struct {
    int repeat; // total number of repeats
    int inc;    // increment per repeat
    int curr;   // current repeat
  } incArrElem;
  /// area to be iterated through
  const r_Minterval* areaIter;
  /// area of tile.
  const r_Minterval* areaTile;
  /// size of base type.
  r_Bytes cellSize;
  /// offset of first cell in tile.
  const char* firstCell;
  /// array with increments
  incArrElem* incArrIter;
  /// flag set if iteration is finished.
  bool done;
  /// current cell for iteration;
  char* currCell;
  /// counter for position in lowest dimension.
  int lowCount;
};

#include "miter.icc"

#endif