BlockIterator.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2008 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // dspsr/Kernel/Classes/dsp/BlockIterator.h
10 
11 #ifndef __BlockIterator_h
12 #define __BlockIterator_h
13 
15 template <typename T>
17 {
18  public:
19 
21  inline BlockIterator (T* start_of_first_block)
22  {
23  current = start_of_first_block;
24  end_of_data = 0;
25 
26  data_size = 0;
27  block_size = 0;
28  increment = 1;
29  }
30 
31  inline BlockIterator (const BlockIterator& copy)
32  {
33  operator = (copy);
34 
35  data_size = copy.data_size;
36  block_size = copy.block_size;
37  increment = copy.increment;
38  }
39 
40  inline const BlockIterator& operator = (const BlockIterator& copy)
41  {
42  // data_size, block_size and increment are set only by copy constructor
43 
44  current = copy.current;
45  end_of_data = copy.end_of_data;
46  return *this;
47  }
48 
49  void set_data_size (unsigned size)
50  {
51  data_size = size;
52 
53  if (data_size > 1)
54  end_of_data = current + data_size;
55  }
56 
57  unsigned get_data_size () const { return data_size; }
58 
59  void set_block_size (unsigned size)
60  {
61  block_size = size;
62  }
63 
64  unsigned get_block_size () const { return block_size; }
65 
66  void set_increment (unsigned step)
67  {
68  increment = step;
69  }
70 
71  const void* ptr ()
72  {
73  return current;
74  }
75 
76  inline void operator ++ ()
77  {
78  current += increment;
79 
80  if (end_of_data && current == end_of_data)
81  {
82  end_of_data += block_size;
83  current += block_size - data_size;
84  }
85  }
86 
87  inline T operator * () const
88  {
89  return *current;
90  }
91 
92  protected:
93 
94  T* current;
95  T* end_of_data;
96 
97  unsigned data_size;
98  unsigned block_size;
99  unsigned increment;
100 
101 };
102 
103 #endif
BlockIterator(T *start_of_first_block)
Construct from base pointer.
Definition: BlockIterator.h:26
An iterator that strides non-contiguous blocks of data.
Definition: BlockIterator.h:16

Generated using doxygen 1.8.17