Maze Builder Docs 7.5.6
Loading...
Searching...
No Matches
enums.h
Go to the documentation of this file.
1#ifndef ENUMS
2#define ENUMS
3
4#include <cstdint>
5#include <string>
6#include <string_view>
7#include <stdexcept>
8
11
12namespace mazes
13{
14
16 enum class barriers : char
17 {
18
19 HORIZONTAL = '-',
20
21 VERTICAL = '|',
22
23 CORNER = '+',
24
25 SINGLE_SPACE = ' '
26 };
27
29 enum class output_format : unsigned int
30 {
31
32 PLAIN_TEXT = 0,
33
34 JSON = 1,
35
36 WAVEFRONT_OBJECT_FILE = 2,
37
38 PNG = 3,
39
40 JPEG = 4,
41
42 STDOUT = 5,
43
44 TOTAL = 6
45 };
46
50 inline std::string_view to_sv_from_output_format(output_format of)
51 {
52
53 switch (of)
54 {
55
56 case output_format::PLAIN_TEXT:
57
58 return "txt";
59 case output_format::JSON:
60
61 return "json";
62 case output_format::WAVEFRONT_OBJECT_FILE:
63
64 return "obj";
65 case output_format::PNG:
66
67 return "png";
68 case output_format::JPEG:
69
70 return "jpeg";
71 case output_format::STDOUT:
72
73 return "stdout";
74 default:
75
76 throw std::invalid_argument("Invalid output_format: " + std::to_string(static_cast<unsigned int>(of)));
77 }
78 };
79
83 inline output_format to_output_format_from_sv(std::string_view sv)
84 {
85
86 if (sv.compare("txt") == 0)
87 {
88
89 return output_format::PLAIN_TEXT;
90 }
91 else if (sv.compare("json") == 0)
92 {
93
94 return output_format::JSON;
95 }
96 else if (sv.compare("obj") == 0)
97 {
98
99 return output_format::WAVEFRONT_OBJECT_FILE;
100 }
101 else if (sv.compare("png") == 0)
102 {
103
104 return output_format::PNG;
105 }
106 else if (sv.compare("jpeg") == 0)
107 {
108
109 return output_format::JPEG;
110 }
111 else if (sv.compare("jpg") == 0)
112 {
113
114 return output_format::JPEG;
115 }
116 else if (sv.compare("stdout") == 0)
117 {
118
119 return output_format::STDOUT;
120 }
121 else
122 {
123
124 throw std::invalid_argument("Invalid output_format: " + std::string{sv});
125 }
126 };
127
129 enum class algo : unsigned int
130 {
131 BINARY_TREE = 0,
132 SIDEWINDER = 1,
133 DFS = 2,
134 TOTAL = 3
135 };
136
140 inline std::string_view to_sv_from_algo(algo a)
141 {
142 switch (a)
143 {
144 case algo::BINARY_TREE:
145
146 return "binary_tree";
147 case algo::SIDEWINDER:
148
149 return "sidewinder";
150 case algo::DFS:
151
152 return "dfs";
153 default:
154 throw std::invalid_argument("Invalid algo: " + std::to_string(static_cast<unsigned int>(a)));
155 }
156 };
157
161 inline algo to_algo_from_sv(std::string_view a)
162 {
163 if (a.compare("binary_tree") == 0)
164 {
165 return algo::BINARY_TREE;
166 }
167 else if (a.compare("sidewinder") == 0)
168 {
169 return algo::SIDEWINDER;
170 }
171 else if (a.compare("dfs") == 0)
172 {
173 return algo::DFS;
174 }
175 else
176 {
177 throw std::invalid_argument("Invalid algo: " + std::string{a});
178 }
179 };
180
182 enum class Direction : std::uint8_t
183 {
184 NORTH = 0,
185 SOUTH = 1,
186 EAST = 2,
187 WEST = 3,
188 COUNT
189 };
190} // namespace
191
192#endif // ENUMS
Namespace for the maze builder.
Definition algo_interface.h:6
std::string_view to_sv_from_output_format(output_format of)
Convert an output_format enum to a string.
Definition enums.h:50
barriers
Character representations of walls and barriers in the maze.
Definition enums.h:17
output_format to_output_format_from_sv(std::string_view sv)
Convert a string to an output_format enum.
Definition enums.h:83
Direction
Directional neighbors for grid topology.
Definition enums.h:183
algo
Enum class for maze types by the generating algorithm.
Definition enums.h:130
output_format
Enum class for output_format types.
Definition enums.h:30
algo to_algo_from_sv(std::string_view a)
Convert a string to an algo enum.
Definition enums.h:161
std::string_view to_sv_from_algo(algo a)
Convert the algo enum to a string.
Definition enums.h:140