#include "gridlocation.h"

struct GridLocation

This struct contains two integer-valued fields, row and col. A GridLocation can be used to represent a location in a two-dimensional grid.
Fields
row
 
col
 
Constructor
GridLocation()
GridLocation(rowcol) 
Creates a GridLocation with the specified row and col.
Methods
toString() Returns a printable string representation of this GridLocation.
Operators
loc1 == loc2  Returns true if loc1 and loc2 are the same location.
loc1 != loc2  Returns true if loc1 and loc2 are different locations.
ostream << loc Outputs the location to the given output stream.
istream >> loc Reads a location from the given input stream.

Constructor detail


GridLocation();
GridLocation(int row, int col);
Creates a GridLocation object with the specified row and col location. If the row and col are not supplied, the default constructor sets these fields to 0. The GridLocation fields row and col can also directly accessed using dot notation.

Usage:

GridLocation origin;
GridLocation loc(5, 10);

origin.col = 0;
if (loc.row == loc.col) ...

Method detail


string toString() const;
Returns a printable string for this GridLocation in the form "r5c8".

Usage:

string str = loc.toString();

ostream& operator<<(const GridLocation& loc);
Outputs the GridLocation to the given output stream. The output is in the form r5c8.

Usage:

cout << loc << endl;

istream& operator>>(GridLocation& loc);
Reads a GridLocation from the given input stream. The input is expected to be in the form r5c8. If unable to read a proper location from the stream, the operation results in a stream fail state.

Usage:

if (infile >> loc) ...