summaryrefslogtreecommitdiffstats
path: root/labb8/lib/StanfordCPPLib/direction.h
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2020-12-03 17:11:43 +0100
committerGustav Sörnäs <gustav@sornas.net>2020-12-08 10:21:07 +0100
commit0c39051ba80f04b1177833a006f2d442a7170b56 (patch)
tree9e657946a061b5b305f9cf75634db7b37e979eb3 /labb8/lib/StanfordCPPLib/direction.h
parent7b7f6808a7b2db2ed21103767434c1445f7815c2 (diff)
downloadtddd86-0c39051ba80f04b1177833a006f2d442a7170b56.tar.gz
add initial files l8
Diffstat (limited to 'labb8/lib/StanfordCPPLib/direction.h')
-rwxr-xr-xlabb8/lib/StanfordCPPLib/direction.h95
1 files changed, 95 insertions, 0 deletions
diff --git a/labb8/lib/StanfordCPPLib/direction.h b/labb8/lib/StanfordCPPLib/direction.h
new file mode 100755
index 0000000..d858aca
--- /dev/null
+++ b/labb8/lib/StanfordCPPLib/direction.h
@@ -0,0 +1,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>&lt;&lt;</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>&gt;&gt;</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 &lt;= WEST; dir++) ...
+ *</pre>
+ */
+
+Direction operator++(Direction & dir, int);
+
+#endif