diff options
Diffstat (limited to 'src/direction.h')
-rw-r--r-- | src/direction.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/direction.h b/src/direction.h new file mode 100644 index 0000000..0fe3e5a --- /dev/null +++ b/src/direction.h | |||
@@ -0,0 +1,22 @@ | |||
1 | #ifndef DIRECTION_H_42BDAFB9 | ||
2 | #define DIRECTION_H_42BDAFB9 | ||
3 | |||
4 | #include <string_view> | ||
5 | #include <stdexcept> | ||
6 | |||
7 | enum class Direction { | ||
8 | up, | ||
9 | down, | ||
10 | left, | ||
11 | right | ||
12 | }; | ||
13 | |||
14 | inline Direction directionFromString(std::string_view str) { | ||
15 | if (str == "up") return Direction::up; | ||
16 | if (str == "right") return Direction::right; | ||
17 | if (str == "down") return Direction::down; | ||
18 | if (str == "left") return Direction::left; | ||
19 | throw std::invalid_argument("Invalid direction: " + std::string(str)); | ||
20 | } | ||
21 | |||
22 | #endif /* end of include guard: DIRECTION_H_42BDAFB9 */ | ||