Maze Builder Docs 8.2.1
Loading...
Searching...
No Matches
args.h
Go to the documentation of this file.
1#ifndef ARGS_H
2#define ARGS_H
3
4#include <memory>
5#include <optional>
6#include <ostream>
7#include <string>
8#include <unordered_map>
9#include <vector>
10
13namespace mazes
14{
18 class args final
19 {
20 public:
21 static constexpr auto APP_KEY = "app";
22
23 static constexpr auto ALGO_ID_FLAG_STR = "-a";
24 static constexpr auto ALGO_ID_OPTION_STR = "--algo";
25 static constexpr auto ALGO_ID_WORD_STR = "algo";
26
27 static constexpr auto BLOCK_ID_FLAG_STR = "-b";
28 static constexpr auto BLOCK_ID_OPTION_STR = "--block";
29 static constexpr auto BLOCK_ID_WORD_STR = "block";
30
31 static constexpr auto ROW_FLAG_STR = "-r";
32 static constexpr auto ROW_OPTION_STR = "--rows";
33 static constexpr auto ROW_WORD_STR = "rows";
34
35 static constexpr auto COLUMN_FLAG_STR = "-c";
36 static constexpr auto COLUMN_OPTION_STR = "--columns";
37 static constexpr auto COLUMN_WORD_STR = "columns";
38
39 static constexpr auto LEVEL_FLAG_STR = "-l";
40 static constexpr auto LEVEL_OPTION_STR = "--levels";
41 static constexpr auto LEVEL_WORD_STR = "levels";
42
43 // JSON related constants
44 static constexpr auto JSON_FLAG_STR = "-j";
45 static constexpr auto JSON_OPTION_STR = "--json";
46 static constexpr auto JSON_WORD_STR = "json";
47
48 // Output related constants
49 static constexpr auto OUTPUT_ID_FLAG_STR = "-o";
50 static constexpr auto OUTPUT_ID_OPTION_STR = "--output";
51 static constexpr auto OUTPUT_ID_WORD_STR = "output";
52 static constexpr auto DEFAULT_OUTPUT_FILENAME = "maze.txt";
53
54 // Output filename related constants
55 static constexpr auto OUTPUT_FILENAME_WORD_STR = "output_filename";
56
57 // Seed related constants
58 static constexpr auto SEED_FLAG_STR = "-s";
59 static constexpr auto SEED_OPTION_STR = "--seed";
60 static constexpr auto SEED_WORD_STR = "seed";
61
62 // Distances related constants
63 static constexpr auto DISTANCES_FLAG_STR = "-d";
64 static constexpr auto DISTANCES_OPTION_STR = "--distances";
65 static constexpr auto DISTANCES_WORD_STR = "distances";
66 static constexpr auto DISTANCES_START_STR = "distances_start";
67 static constexpr auto DISTANCES_END_STR = "distances_end";
68
69 // Image dimension related constants
70 static constexpr auto IMAGE_WIDTH_WORD_STR = "image_width";
71 static constexpr auto IMAGE_HEIGHT_WORD_STR = "image_height";
72 static constexpr auto IMAGE_WIDTH_OPTION_STR = "--image-width";
73 static constexpr auto IMAGE_HEIGHT_OPTION_STR = "--image-height";
74 static constexpr auto IMAGE_WIDTH_FLAG_STR = "-W";
75 static constexpr auto IMAGE_HEIGHT_FLAG_STR = "-H";
76
77 // Help related constants
78 static constexpr auto HELP_FLAG_STR = "-h";
79 static constexpr auto HELP_OPTION_STR = "--help";
80 static constexpr auto HELP_WORD_STR = "help";
81
82 // Version related constants
83 static constexpr auto VERSION_FLAG_STR = "-v";
84 static constexpr auto VERSION_OPTION_STR = "--version";
85 static constexpr auto VERSION_WORD_STR = "version";
86
87 // Mask related constants
88 static constexpr auto MASK_FLAG_STR = "-m";
89 static constexpr auto MASK_OPTION_STR = "--mask";
90 static constexpr auto MASK_WORD_STR = "mask";
91
92 // Step visualization constants
93 static constexpr auto SHOW_STEPS_OPTION_STR = "--show-steps";
94 static constexpr auto SHOW_STEPS_WORD_STR = "show_steps";
95
96 // Special values
97 static constexpr auto TRUE_VALUE = "true";
98 static constexpr auto FALSE_VALUE = "false";
99
102 args() noexcept;
103
107
110 args(const args& other);
111
115 args& operator=(const args& other);
116
119 args(args&& other) noexcept;
120
124 args& operator=(args&& other) noexcept;
125
130 bool parse(const std::vector<std::string>& arguments,
131 bool has_program_name_as_first_arg = false) const noexcept;
132
137 bool parse(const std::string& arguments, bool has_program_name_as_first_arg = false) const noexcept;
138
144 bool parse(int argc, char** argv, bool has_program_name_as_first_arg = false) const noexcept;
145
147 void clear() const noexcept;
148
152 [[nodiscard]] std::optional<std::string> get(const std::string& key) const noexcept;
153
156 [[nodiscard]] std::optional<std::unordered_map<std::string, std::string>> get() const noexcept;
157
160 [[nodiscard]] std::optional<std::vector<std::unordered_map<std::string, std::string>>>
161 get_array() const noexcept;
162
163 private:
164 // Private implementation class (PIMPL idiom)
165 class impl;
166 std::unique_ptr<impl> pimpl;
167 };
168}
169#endif // ARGS_H
Command-line argument handler with JSON support.
Definition args.h:19
void clear() const noexcept
Clear the arguments map.
std::optional< std::vector< std::unordered_map< std::string, std::string > > > get_array() const noexcept
Get vector of args maps (useful for JSON parsing with array of objects)
bool parse(const std::vector< std::string > &arguments, bool has_program_name_as_first_arg=false) const noexcept
Parse program arguments from a vector of strings.
std::optional< std::unordered_map< std::string, std::string > > get() const noexcept
Get entire args map (from front)
args() noexcept
Default constructor.