Maze Builder Docs 7.5.6
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 <string_view>
9#include <unordered_map>
10#include <vector>
11
12namespace mazes
13{
14
19 class args final
20 {
21 public:
22 static constexpr const auto APP_KEY = "app";
23
24 static constexpr const auto ALGO_ID_FLAG_STR = "-a";
25 static constexpr const auto ALGO_ID_OPTION_STR = "--algo";
26 static constexpr const auto ALGO_ID_WORD_STR = "algo";
27
28 static constexpr const auto BLOCK_ID_FLAG_STR = "-b";
29 static constexpr const auto BLOCK_ID_OPTION_STR = "--block";
30 static constexpr const auto BLOCK_ID_WORD_STR = "block";
31
32 static constexpr const auto ROW_FLAG_STR = "-r";
33 static constexpr const auto ROW_OPTION_STR = "--rows";
34 static constexpr const auto ROW_WORD_STR = "rows";
35
36 static constexpr const auto COLUMN_FLAG_STR = "-c";
37 static constexpr const auto COLUMN_OPTION_STR = "--columns";
38 static constexpr const auto COLUMN_WORD_STR = "columns";
39
40 static constexpr const auto LEVEL_FLAG_STR = "-l";
41 static constexpr const auto LEVEL_OPTION_STR = "--levels";
42 static constexpr const auto LEVEL_WORD_STR = "levels";
43
44 // JSON related constants
45 static constexpr const auto JSON_FLAG_STR = "-j";
46 static constexpr const auto JSON_OPTION_STR = "--json";
47 static constexpr const auto JSON_WORD_STR = "json";
48
49 // Output related constants
50 static constexpr const auto OUTPUT_ID_FLAG_STR = "-o";
51 static constexpr const auto OUTPUT_ID_OPTION_STR = "--output";
52 static constexpr const auto OUTPUT_ID_WORD_STR = "output";
53 static constexpr const auto DEFAULT_OUTPUT_FILENAME = "maze.txt";
54
55 // Output filename related constants
56 static constexpr const auto OUTPUT_FILENAME_WORD_STR = "output_filename";
57
58 // Seed related constants
59 static constexpr const auto SEED_FLAG_STR = "-s";
60 static constexpr const auto SEED_OPTION_STR = "--seed";
61 static constexpr const auto SEED_WORD_STR = "seed";
62
63 // Distances related constants
64 static constexpr const auto DISTANCES_FLAG_STR = "-d";
65 static constexpr const auto DISTANCES_OPTION_STR = "--distances";
66 static constexpr const auto DISTANCES_WORD_STR = "distances";
67 static constexpr const auto DISTANCES_START_STR = "distances_start";
68 static constexpr const auto DISTANCES_END_STR = "distances_end";
69
70 // Help related constants
71 static constexpr const auto HELP_FLAG_STR = "-h";
72 static constexpr const auto HELP_OPTION_STR = "--help";
73 static constexpr const auto HELP_WORD_STR = "help";
74
75 // Version related constants
76 static constexpr const auto VERSION_FLAG_STR = "-v";
77 static constexpr const auto VERSION_OPTION_STR = "--version";
78 static constexpr const auto VERSION_WORD_STR = "version";
79
80 // Special values
81 static constexpr const auto TRUE_VALUE = "true";
82 static constexpr const auto FALSE_VALUE = "false";
83
86 args() noexcept;
87
90 ~args();
91
94 args(const args &other);
95
99 args &operator=(const args &other);
100
103 args(args &&other) noexcept = default;
104
108 args &operator=(args &&other) noexcept = default;
109
114 bool parse(const std::vector<std::string> &arguments, bool has_program_name_as_first_arg = false) noexcept;
115
120 bool parse(const std::string &arguments, bool has_program_name_as_first_arg = false) noexcept;
121
127 bool parse(int argc, char **argv, bool has_program_name_as_first_arg = false) noexcept;
128
130 void clear() noexcept;
131
135 std::optional<std::string> get(const std::string &key) const noexcept;
136
139 std::optional<std::unordered_map<std::string, std::string>> get() const noexcept;
140
143 std::optional<std::vector<std::unordered_map<std::string, std::string>>> get_array() const noexcept;
144
145 private:
151 bool process_json_input(std::string_view json_input) noexcept;
152
153 // Private implementation class (PIMPL idiom)
154 class impl;
155 std::unique_ptr<impl> pimpl;
156 };
157
158}
159#endif // ARGS_H
Command-line argument handler with JSON support.
Definition args.h:20
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)
std::optional< std::unordered_map< std::string, std::string > > get() const noexcept
Get entire args map (from front)
void clear() noexcept
Clear the arguments map.
args() noexcept
Default constructor.
bool parse(const std::vector< std::string > &arguments, bool has_program_name_as_first_arg=false) noexcept
Parse program arguments from a vector of strings.
Namespace for the maze builder.
Definition algo_interface.h:6