Maze Builder Docs 6.7.5
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
11namespace mazes {
12
17class args final {
18public:
19
20 static constexpr const char* ALGO_ID_FLAG_STR = "-a";
21 static constexpr const char* ALGO_ID_OPTION_STR = "--algo";
22 static constexpr const char* ALGO_ID_WORD_STR = "algo";
23 static constexpr const char* ALGO_ID_SHORT_STR = "a";
24
25 static constexpr const char* BLOCK_ID_FLAG_STR = "-b";
26 static constexpr const char* BLOCK_ID_OPTION_STR = "--block";
27 static constexpr const char* BLOCK_ID_WORD_STR = "block";
28 static constexpr const char* BLOCK_ID_SHORT_STR = "b";
29
30 static constexpr const char* ROW_FLAG_STR = "-r";
31 static constexpr const char* ROW_OPTION_STR = "--rows";
32 static constexpr const char* ROW_WORD_STR = "rows";
33 static constexpr const char* ROW_SHORT_STR = "r";
34
35 static constexpr const char* COLUMN_FLAG_STR = "-c";
36 static constexpr const char* COLUMN_OPTION_STR = "--columns";
37 static constexpr const char* COLUMN_WORD_STR = "columns";
38 static constexpr const char* COLUMN_SHORT_STR = "c";
39
40 static constexpr const char* LEVEL_FLAG_STR = "-l";
41 static constexpr const char* LEVEL_OPTION_STR = "--levels";
42 static constexpr const char* LEVEL_WORD_STR = "levels";
43 static constexpr const char* LEVEL_SHORT_STR = "l";
44
45 // JSON related constants
46 static constexpr const char* JSON_FLAG_STR = "-j";
47 static constexpr const char* JSON_OPTION_STR = "--json";
48 static constexpr const char* JSON_WORD_STR = "json";
49 static constexpr const char* JSON_SHORT_STR = "j";
50
51 // Output related constants
52 static constexpr const char* OUTPUT_ID_FLAG_STR = "-o";
53 static constexpr const char* OUTPUT_ID_OPTION_STR = "--output";
54 static constexpr const char* OUTPUT_ID_WORD_STR = "output";
55 static constexpr const char* OUTPUT_ID_SHORT_STR = "o";
56 static constexpr const char* DEFAULT_OUTPUT_FILENAME = "output.json";
57
58 // Seed related constants
59 static constexpr const char* SEED_FLAG_STR = "-s";
60 static constexpr const char* SEED_OPTION_STR = "--seed";
61 static constexpr const char* SEED_WORD_STR = "seed";
62 static constexpr const char* SEED_SHORT_STR = "s";
63
64 // Distances related constants
65 static constexpr const char* DISTANCES_FLAG_STR = "-d";
66 static constexpr const char* DISTANCES_OPTION_STR = "--distances";
67 static constexpr const char* DISTANCES_WORD_STR = "distances";
68 static constexpr const char* DISTANCES_SHORT_STR = "d";
69 static constexpr const char* DISTANCES_START_STR = "distances_start";
70 static constexpr const char* DISTANCES_END_STR = "distances_end";
71 static constexpr const char* DISTANCES_DEFAULT_START = "0";
72 static constexpr const char* DISTANCES_DEFAULT_END = "-1";
73
74 // Help related constants
75 static constexpr const char* HELP_FLAG_STR = "-h";
76 static constexpr const char* HELP_OPTION_STR = "--help";
77 static constexpr const char* HELP_WORD_STR = "help";
78 static constexpr const char* HELP_SHORT_STR = "h";
79
80 // Version related constants
81 static constexpr const char* VERSION_FLAG_STR = "-v";
82 static constexpr const char* VERSION_OPTION_STR = "--version";
83 static constexpr const char* VERSION_WORD_STR = "version";
84 static constexpr const char* VERSION_SHORT_STR = "v";
85
86 // Special values
87 static constexpr const char* TRUE_VALUE = "true";
88
91 args() noexcept;
92
95 ~args();
96
99 args(const args& other);
100
104 args& operator=(const args& other);
105
108 args(args&& other) noexcept = default;
109
113 args& operator=(args&& other) noexcept = default;
114
118 bool parse(const std::vector<std::string>& arguments) noexcept;
119
123 bool parse(const std::string& arguments) noexcept;
124
129 bool parse(int argc, char** argv) noexcept;
130
132 void clear() noexcept;
133
137 std::optional<std::string> get(const std::string& key) const noexcept;
138
141 const std::unordered_map<std::string, std::string>& get() const noexcept;
142
145 bool has_multiple_configurations() const noexcept;
146
149 size_t get_configuration_count() const noexcept;
150
154 std::optional<std::unordered_map<std::string, std::string>> get_configuration(size_t index) const noexcept;
155
158 std::vector<std::unordered_map<std::string, std::string>> get_all_configurations() const noexcept;
159
164 bool add_option(const std::string& flags, const std::string& description) noexcept;
165
170 bool add_flag(const std::string& flags, const std::string& description) noexcept;
171
172private:
173
178 bool parse_sliced_array(const std::string& value, std::unordered_map<std::string, std::string>& args_map) noexcept;
179
184 std::string generate_output_filename(const std::string& input_value, bool is_string_input) const noexcept;
185
191 bool process_json_input(const std::string& json_input, bool is_string_input, const std::string& key) noexcept;
192
193 // Private implementation class (PIMPL idiom)
194 class impl;
195 std::unique_ptr<impl> pimpl;
196};
197
198}
199#endif // ARGS_H
Command-line argument handler with JSON support.
Definition args.h:17
bool parse(const std::vector< std::string > &arguments) noexcept
Parse program arguments from a vector of strings.
std::vector< std::unordered_map< std::string, std::string > > get_all_configurations() const noexcept
Get all configurations as a vector.
const std::unordered_map< std::string, std::string > & get() const noexcept
Get entire args map.
std::optional< std::unordered_map< std::string, std::string > > get_configuration(size_t index) const noexcept
Get configuration by index (0-based)
bool add_option(const std::string &flags, const std::string &description) noexcept
Add a new option to the CLI parser.
void clear() noexcept
Clear the arguments map.
args() noexcept
Default constructor.
bool add_flag(const std::string &flags, const std::string &description) noexcept
Add a new flag to the CLI parser.
size_t get_configuration_count() const noexcept
Get the number of configurations stored.
bool has_multiple_configurations() const noexcept
Check if we have multiple configurations (from JSON array)
Namespace for the maze builder.
Definition algo_interface.h:9