class GridLocationRange
GridLocationRange range(0, 0, 10, 5); for (GridLocation loc : range) { cout << loc << endl; // print location itself }The
locations()
method of the Grid
class returns a GridLocationRange
for the entire grid.
for (GridLocation loc : grid.locations()) { cout << grid[loc] << endl; // access grid element at each location and print it }
Constructor | |
GridLocationRange(startRow, startCol, endRow, endCol) | Creates a GridLocationRange with the specified boundaries. |
Methods | |
Returns true if loc is contained in this range. | Returns the last column in this range, inclusive. | Returns the last row/column location in this range, inclusive. | Returns the last row in this range, inclusive. | Returns true if this range contains no rows or columns. | Returns the count of columns in this range. | Returns the count of rows in this range. | Returns the total number of locations in this range. | Returns the first column in this range, inclusive. | Returns the first row/column location in this range, inclusive. | Returns the first row in this range, inclusive. | Returns a printable string representation of this range. | Operators |
Outputs a range to the given output stream. | |
Reads a range from the given input stream. |
GridLocationRange(int startRow, int startCol, int endRow, int endCol); GridLocationRange(GridLocation startLocation, GridLocation endLocation);
GridLocationRange
object with the specified boundaries. The range of locations extends from the corner at (startRow, startCol)
to the corner at (endRow, endCol)
inclusive.
Usage:
GridLocationRange row(0, 0, 0, 10); GridLocationRange box(2, 3, 7, 9); GridLocationRange byCorners(GridLocation(2, 3), GridLocation(7, 9)); GridLocationRange range; // no arguments initializes to default 0,0,0,0 range = GridLocationRange(0, 0, 5, 5); // set range to have new boundaries
bool contains(GridLocation loc) const;
true
if the specified location is contained in this range.
Usage:
if (range.contains(loc)) ...
bool isEmpty() const;
true
if this range contains no rows or columns.
Usage:
if (range.isEmpty()) ...
int endCol() const;
Usage:
int last = range.endCol();
GridLocation endLocation() const;
Usage:
GridLocation last = range.endLocation();
int endRow() const;
Usage:
int last = range.endRow();
int numCols() const;
Usage:
int n = range.numCols();
int numRows() const;
Usage:
int n = range.numRows();
int size() const;
Usage:
int n = range.size();
int startCol() const;
Usage:
int first = range.startCol();
GridLocation startLocation() const;
Usage:
GridLocation first = range.startLocation();
int startRow() const;
Usage:
int first = range.startRow();
string toString() const;
GridLocationRange
in the form
"r5c8...r6c9"
.
Usage:
string str = range.toString();
ostream& operator<<(const GridLocationRange& range);Outputs the
GridLocationRange
to the given output stream.
The output is in the form r5c8...r6c9
.
Usage:
cout << range << endl;
istream& operator>>(GridLocationRange& range);Reads a
GridLocationRange
from the given input stream.
The input is expected to be in the form r5c8...r6c9
. If unable to read a proper
range from the stream, the operation results in a stream fail state.
Usage:
if (infile >> range) ...