Maze Builder Docs 8.10.23
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 using arg_map = std::unordered_map<std::string, std::string>;
22
23 static constexpr auto APP_KEY = "app";
24
25 static constexpr auto ALGO_ID_FLAG_STR = "-a";
26 static constexpr auto ALGO_ID_OPTION_STR = "--algo";
27 static constexpr auto ALGO_ID_WORD_STR = "algo";
28
29 static constexpr auto ROW_FLAG_STR = "-r";
30 static constexpr auto ROW_OPTION_STR = "--rows";
31 static constexpr auto ROW_WORD_STR = "rows";
32
33 static constexpr auto COLUMN_FLAG_STR = "-c";
34 static constexpr auto COLUMN_OPTION_STR = "--columns";
35 static constexpr auto COLUMN_WORD_STR = "columns";
36
37 static constexpr auto LEVEL_FLAG_STR = "-l";
38 static constexpr auto LEVEL_OPTION_STR = "--levels";
39 static constexpr auto LEVEL_WORD_STR = "levels";
40
41 // JSON related constants
42 static constexpr auto JSON_FLAG_STR = "-j";
43 static constexpr auto JSON_OPTION_STR = "--json";
44 static constexpr auto JSON_WORD_STR = "json";
45
46 // Output related constants
47 static constexpr auto OUTPUT_ID_FLAG_STR = "-o";
48 static constexpr auto OUTPUT_ID_OPTION_STR = "--output";
49 static constexpr auto OUTPUT_ID_WORD_STR = "output";
50
51 // Seed related constants
52 static constexpr auto SEED_FLAG_STR = "-s";
53 static constexpr auto SEED_OPTION_STR = "--seed";
54 static constexpr auto SEED_WORD_STR = "seed";
55
56 // Distances related constants
57 static constexpr auto DISTANCES_FLAG_STR = "-d";
58 static constexpr auto DISTANCES_OPTION_STR = "--distances";
59 static constexpr auto DISTANCES_WORD_STR = "distances";
60 static constexpr auto DISTANCES_START_VAL_STR = "distances_start";
61 static constexpr auto DISTANCES_END_VAL_STR = "distances_end";
62
63 // Mask related constants
64 static constexpr auto MASK_FLAG_STR = "-m";
65 static constexpr auto MASK_OPTION_STR = "--mask";
66 static constexpr auto MASK_WORD_STR = "mask";
67
68 // Holds the unparsed user input until parsing_state processes it
69 static constexpr auto RAW_WORD_STR = "raw";
70
71 // Special values
72 static constexpr auto TRUE_VALUE = "true";
73
76 args() noexcept;
77
80 ~args();
81
84 args(const args &other);
85
89 args &operator=(const args &other);
90
93 args(args &&other) noexcept;
94
98 args &operator=(args &&other) noexcept;
99
104 bool parse(const std::vector<std::string> &arguments,
105 bool has_program_name_as_first_arg = false) const noexcept;
106
111 bool parse(const std::string &arguments, bool has_program_name_as_first_arg = false) const noexcept;
112
118 bool parse(int argc, char **argv, bool has_program_name_as_first_arg = false) const noexcept;
119
122 void set(std::vector<arg_map> maps) const noexcept;
123
125 void clear() const noexcept;
126
130 [[nodiscard]] std::optional<std::string> get(const std::string &key) const noexcept;
131
134 [[nodiscard]] arg_map front() const noexcept;
135
138 bool pop_front() const noexcept;
139
142 [[nodiscard]] std::vector<arg_map> get() const noexcept;
143
146 [[nodiscard]] std::size_t count() const noexcept;
147
148 private:
149 class impl;
150 std::unique_ptr<impl> pimpl;
151 };
152}
153#endif // ARGS_H
bool pop_front() const noexcept
Remove the first parsed argument map.
arg_map front() const noexcept
Get args from front.
void clear() const noexcept
Clear the arguments map.
std::optional< std::string > get(const std::string &key) const noexcept
Get a value.
std::size_t count() const noexcept
Get the number of argument maps.
void set(std::vector< arg_map > maps) const noexcept
Replace all argument maps.
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.
args() noexcept
Default constructor.