blob: d858acae4ddc3d83b1f5e8f789aacfc0021759c3 (
plain) (
blame)
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
|
/*
* File: direction.h
* -----------------
* This file exports an enumerated type called <code>Direction</code>
* whose elements are the four compass points: <code>NORTH</code>,
* <code>EAST</code>, <code>SOUTH</code>, and <code>WEST</code>.
*/
#ifndef _direction_h
#define _direction_h
#include <iostream>
#include <string>
#include "foreach.h"
/*
* Type: Direction
* ---------------
* This enumerated type is used to represent the four compass directions.
*/
enum Direction { NORTH, EAST, SOUTH, WEST };
/*
* Function: leftFrom
* Usage: Direction newdir = leftFrom(dir);
* ----------------------------------------
* Returns the direction that is to the left of the argument.
*/
Direction leftFrom(Direction dir);
/*
* Function: rightFrom
* Usage: Direction newdir = rightFrom(dir);
* -----------------------------------------
* Returns the direction that is to the right of the argument.
*/
Direction rightFrom(Direction dir);
/*
* Function: opposite
* Usage: Direction newdir = opposite(dir);
* ----------------------------------------
* Returns the direction that is opposite to the argument.
*/
Direction opposite(Direction dir);
/*
* Function: directionToString
* Usage: string str = directionToString(dir);
* -------------------------------------------
* Returns the name of the direction as a string.
*/
std::string directionToString(Direction dir);
/*
* Operator: <<
* Usage: os << dir;
* -----------------
* Overloads the <code><<</code> operator so that it is able
* to display <code>Direction</code> values.
*/
std::ostream & operator<<(std::ostream & os, const Direction & dir);
/*
* Operator: >>
* Usage: is >> dir;
* -----------------
* Overloads the <code>>></code> operator so that it is able
* to read <code>Direction</code> values.
*/
std::istream & operator>>(std::istream & os, Direction & dir);
/*
* Operator: ++
* Usage: dir++
* ------------
* Overloads the suffix version of the <code>++</code> operator to
* work with <code>Direction</code> values. The sole purpose of this
* definition is to support the idiom
*
*<pre>
* for (Direction dir = NORTH; dir <= WEST; dir++) ...
*</pre>
*/
Direction operator++(Direction & dir, int);
#endif
|