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