-
Notifications
You must be signed in to change notification settings - Fork 0
/
RowIterator.cpp
127 lines (106 loc) · 3.65 KB
/
RowIterator.cpp
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//
// Created by mfbut on 11/17/2019.
//
#include "RowIterator.h"
#include "Matrix.h"
//create a RowIterator over the specified matrix starting at the specified row
Matrix::RowIterator::RowIterator(Matrix* matrix, int row) {
this->matrix = matrix;
this->row = row;
}
//return a ConstRowIterator over the same matrix and at the same row
Matrix::RowIterator::operator ConstRowIterator() const {
return *(new ConstRowIterator(matrix, row));
}
//return a reference to the row that you are on
Matrix::ConstVectorRef Matrix::RowIterator::operator*() const {
//make sure that we call the const at method on matrix
return const_cast<const Matrix*>(matrix)->rowAt(row);
}
//return a reference to the row offset past your current row
Matrix::ConstVectorRef Matrix::RowIterator::operator[](int offset) const {
//make sure that we call the const at method on matrix
return const_cast<const Matrix*>(matrix)->rowAt(row + offset);
}
//return a reference to the row that you are on
Matrix::RowIterator::value_type Matrix::RowIterator::operator*() {
return *(new VectorRef(matrix->rowAt(row)));
}
//return a reference to the row offset past your current row
Matrix::RowIterator::value_type Matrix::RowIterator::operator[](int offset) {
return *(new VectorRef(matrix->rowAt(row + offset)));
}
//move to the next row
Matrix::RowIterator& Matrix::RowIterator::operator++() {
row++;
return *this;
}
//move to the next row
const Matrix::RowIterator Matrix::RowIterator::operator++(int) {
const RowIterator iterator = *this;
row++;
return iterator;
}
//move to the previous row
Matrix::RowIterator& Matrix::RowIterator::operator--() {
row--;
return *this;
}
//move to the previous row
const Matrix::RowIterator Matrix::RowIterator::operator--(int) {
const RowIterator iterator = *this;
row--;
return iterator;
}
//move forward amount rows
Matrix::RowIterator& Matrix::RowIterator::operator+=(int amount) {
row += amount;
return *this;
}
//move forward amount rows
Matrix::RowIterator Matrix::RowIterator::operator+(int amount) const {
const int index = this->row + amount;
return this[index];
}
//move backward amount rows
Matrix::RowIterator& Matrix::RowIterator::operator-=(int amount) {
row -= amount;
return *this;
}
//move backward amount rows
Matrix::RowIterator Matrix::RowIterator::operator-(int amount) const {
const int index = this->row - amount;
return this[index];
}
//return the number of rows between yourself and rhs
//for example if you were at row 10 and rhs was at row 7
//the difference would be 3
Matrix::RowIterator::difference_type Matrix::RowIterator::operator-(const RowIterator& rhs) {
return rhs.row - this->row;
}
//you are equal to rhs if you are both over the same matrix
//and you are on the same row
bool Matrix::RowIterator::operator==(const RowIterator& rhs) const {
return (rhs.matrix == this->matrix) && (rhs.row == this->row);
}
//you are equal to rhs if you are both over the same matrix
//and you are on the same row
bool Matrix::RowIterator::operator!=(const RowIterator& rhs) const {
return !(rhs.matrix == this->matrix && rhs.row == this->row);
}
//are you at a row before rhs?
bool Matrix::RowIterator::operator<(const RowIterator& rhs) const {
return this->row < rhs.row;
}
//are you at a row before rhs?
bool Matrix::RowIterator::operator<=(const RowIterator& rhs) const {
return this->row <= rhs.row;
}
//are you at a row after rhs?
bool Matrix::RowIterator::operator>(const RowIterator& rhs) const {
return this->row > rhs.row;
}
//are you at a row after rhs?
bool Matrix::RowIterator::operator>=(const RowIterator& rhs) const {
return this->row >= rhs.row;
}