Maze Builder Docs 8.2.1
Loading...
Searching...
No Matches
output_formats.h
Go to the documentation of this file.
1#ifndef OUTPUT_FORMATS_H
2#define OUTPUT_FORMATS_H
3
4#include <stdexcept>
5#include <string>
6#include <string_view>
7
10namespace mazes
11{
12 constexpr std::string_view JSON_FILE_FORMAT_STR = "json";
13 constexpr std::string_view WAVEFRONT_OBJECT_FILE_FORMAT_STR = "obj";
14 constexpr std::string_view STDOUT_FORMAT_STR = "stdout";
15 constexpr std::string_view PLAIN_TEXT_FORMAT_STR = "txt";
16
18 enum class output_format : unsigned int
19 {
20 PLAIN_TEXT = 0,
21 JSON_FILE = 1,
22 WAVEFRONT_OBJECT_FILE = 2,
23 STDOUT = 3,
24 TOTAL = 4
25 };
26
30 inline std::string_view to_sv_from_output_format(output_format of)
31 {
32 switch (of)
33 {
34 case output_format::PLAIN_TEXT:
35 return PLAIN_TEXT_FORMAT_STR;
36 case output_format::JSON_FILE:
37 return JSON_FILE_FORMAT_STR;
38 case output_format::WAVEFRONT_OBJECT_FILE:
39 return WAVEFRONT_OBJECT_FILE_FORMAT_STR;
40 case output_format::STDOUT:
41 return STDOUT_FORMAT_STR;
42 default:
43 throw std::invalid_argument("Invalid output_format: " + std::to_string(static_cast<unsigned int>(of)));
44 }
45 }
46
50 inline output_format to_output_format_from_sv(const std::string_view sv)
51 {
52 if (sv == PLAIN_TEXT_FORMAT_STR)
53 {
54 return output_format::PLAIN_TEXT;
55 }
56 if (sv == JSON_FILE_FORMAT_STR)
57 {
58 return output_format::JSON_FILE;
59 }
60 if (sv == WAVEFRONT_OBJECT_FILE_FORMAT_STR)
61 {
62 return output_format::WAVEFRONT_OBJECT_FILE;
63 }
64 if (sv == STDOUT_FORMAT_STR)
65 {
66 return output_format::STDOUT;
67 }
68 throw std::invalid_argument("Invalid output_format: " + std::string{sv});
69 }
70} // namespace mazes
71
72#endif // OUTPUT_FORMATS_H
std::string_view to_sv_from_output_format(output_format of)
Convert an output_format enum to a string.
Definition output_formats.h:30
output_format
Enum class for output_format types.
Definition output_formats.h:19
output_format to_output_format_from_sv(const std::string_view sv)
Convert a string to an output_format enum.
Definition output_formats.h:50