Files Classes Functions Hierarchy
#include <snakeindex.h>
Public Member Functions | |
| snakeindex (T const _columns, T const _length, bool forward=true) | |
| Pass in the number of columns and length of the matrix, configure the iterator forwards or backwards. | |
| void | reset () |
| Reset the iterator. | |
| boolc | operator! () const |
| Is the iterator valid? | |
| void | operator++ () |
| Increment the iterator. | |
| void | pos (T &row, T &col) const |
| The current position as a 2D indexed point. | |
| void | pos (T &k2) const |
| The current position as an index from the start. | |
Public Attributes | |
| T const | rows |
| The number of rows. | |
| T const | columns |
| The number of columns. | |
| T const | length |
| The length of the 2D matrix. | |
Two combinations of itterating a 2D matrix are made.
To get the other two combinations, take a N by M matrix and consecutively label the elements from 0, then transpose it so it is now an M by N matrix.
Now construct a M by N snakeindex iterator and the other two combinations are realized by indexing on the transposed matrix.
Definition at line 22 of file snakeindex.h.
| snakeindex< T >::snakeindex | ( | T const | _columns, | |
| T const | _length, | |||
| bool | forward = true | |||
| ) |
Pass in the number of columns and length of the matrix, configure the iterator forwards or backwards.
| boolc snakeindex< T >::operator! | ( | ) | const [inline] |
Is the iterator valid?
Definition at line 50 of file snakeindex.h.
References snakeindex< T >::length.
00051 { return (current>=0)&&(current<length); }
| void snakeindex< T >::operator++ | ( | ) | [inline] |
| void snakeindex< T >::pos | ( | T & | k2 | ) | const [inline] |
The current position as an index from the start.
Definition at line 67 of file snakeindex.h.
References snakeindex< T >::columns, and snakeindex< T >::pos().
| void snakeindex< T >::pos | ( | T & | row, | |
| T & | col | |||
| ) | const [inline] |
The current position as a 2D indexed point.
Definition at line 76 of file snakeindex.h.
References snakeindex< T >::columns.
Referenced by snakeindex< T >::pos(), snakeindextest::test01(), snakeindextest::test02(), and snakeindextest::test03().
00077 { 00078 row = (current - (current % columns))/columns; 00079 col = current-row*columns; 00080 if ((row % 2)==1) 00081 col = columns-1-col; 00082 }
| void snakeindex< T >::reset | ( | ) | [inline] |
Reset the iterator.
Definition at line 85 of file snakeindex.h.
References snakeindex< T >::length.
Referenced by snakeindextest::test01(), snakeindextest::test02(), and snakeindextest::test03().
00086 { 00087 if (dcurrent>0) 00088 current=0; 00089 else 00090 current=length-1; 00091 }
| T const snakeindex< T >::columns |
The number of columns.
Definition at line 33 of file snakeindex.h.
Referenced by snakeindex< T >::pos().
| T const snakeindex< T >::length |
The length of the 2D matrix.
Definition at line 35 of file snakeindex.h.
Referenced by snakeindex< T >::operator!(), and snakeindex< T >::reset().
| T const snakeindex< T >::rows |
1.5.8