|
| 1 | +#include <iostream> |
| 2 | + |
| 3 | +#include <set> |
| 4 | +#include <stack> |
| 5 | +#include <queue> |
| 6 | +#include <deque> |
| 7 | +#include <list> |
| 8 | +#include <vector> |
| 9 | +#include <forward_list> |
| 10 | +#include <unordered_set> |
| 11 | + |
| 12 | +#include "simple-args-parser.hpp" |
| 13 | + |
| 14 | +/* -- Helpers functions -- */ |
| 15 | +template <typename T> |
| 16 | +void GetAndPrintIterableContainer(const args::Parser &parser, const std::string &name); |
| 17 | + |
| 18 | +template <typename T> |
| 19 | +void GetAndPrintStack(const args::Parser &parser, const std::string &name); |
| 20 | + |
| 21 | +template <typename T> |
| 22 | +void GetAndPrintDeque(const args::Parser &parser, const std::string &name); |
| 23 | + |
| 24 | +template <typename T> |
| 25 | +void GetAndPrintQueue(const args::Parser &parser, const std::string &name); |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +int main(int argc, char **argv) |
| 30 | +{ |
| 31 | + args::Parser args_parser(args::ParserMode::IGNORE_UNKNOWN_ARGUMENTS); |
| 32 | + |
| 33 | + args_parser.SetOpt<std::stack<float>> ({"--stack"} , args::ArgType::ARGS_OPTIONAL, "Stack of float description" ); |
| 34 | + args_parser.SetOpt<std::deque<long>> ({"--deque"} , args::ArgType::ARGS_OPTIONAL, "Deque of long description" ); |
| 35 | + args_parser.SetOpt<std::queue<unsigned int>> ({"--queue"} , args::ArgType::ARGS_OPTIONAL, "Queue of unsigned int description" ); |
| 36 | + args_parser.SetOpt<std::set<double>> ({"--set"} , args::ArgType::ARGS_OPTIONAL, "Set of double description" ); |
| 37 | + args_parser.SetOpt<std::forward_list<std::string>> ({"--forwardlist"}, args::ArgType::ARGS_OPTIONAL, "Forward list of sting description" ); |
| 38 | + args_parser.SetOpt<std::list<int>> ({"--list"} , args::ArgType::ARGS_OPTIONAL, "List of int description" ); |
| 39 | + args_parser.SetOpt<std::vector<int>> ({"--vector"} , args::ArgType::ARGS_OPTIONAL, "Vector of int description" ); |
| 40 | + args_parser.SetOpt<std::unordered_set<std::string>>({"--hashset"} , args::ArgType::ARGS_OPTIONAL, "Unordered set of string description"); |
| 41 | + |
| 42 | + args_parser.Parse(argc, argv); |
| 43 | + |
| 44 | + GetAndPrintStack<std::stack<float>> (args_parser, "--stack" ); |
| 45 | + GetAndPrintDeque<std::deque<long>> (args_parser, "--deque" ); |
| 46 | + GetAndPrintQueue<std::queue<unsigned int>> (args_parser, "--queue" ); |
| 47 | + GetAndPrintIterableContainer<std::set<double>> (args_parser, "--set" ); |
| 48 | + GetAndPrintIterableContainer<std::forward_list<std::string>> (args_parser, "--forwardlist"); |
| 49 | + GetAndPrintIterableContainer<std::list<int>> (args_parser, "--list" ); |
| 50 | + GetAndPrintIterableContainer<std::vector<int>> (args_parser, "--vector" ); |
| 51 | + GetAndPrintIterableContainer<std::unordered_set<std::string>>(args_parser, "--hashset" ); |
| 52 | + |
| 53 | + return 0; |
| 54 | +} |
| 55 | + |
| 56 | + |
| 57 | +template <typename T> |
| 58 | +void GetAndPrintQueue(const args::Parser &parser, const std::string &name) |
| 59 | +{ |
| 60 | + auto val = parser.GetOptValue<T>(name); |
| 61 | + |
| 62 | + if (val) |
| 63 | + { |
| 64 | + std::cout << "Option (" << name << ") - value:"; |
| 65 | + |
| 66 | + while (val->size()) |
| 67 | + { |
| 68 | + std::cout << " " << val->front() << " "; |
| 69 | + val->pop(); |
| 70 | + } |
| 71 | + |
| 72 | + std::cout << std::endl; |
| 73 | + } |
| 74 | + else |
| 75 | + { |
| 76 | + std::cout << "No option (" << name << ")" << std::endl; |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +template <typename T> |
| 81 | +void GetAndPrintDeque(const args::Parser &parser, const std::string &name) |
| 82 | +{ |
| 83 | + auto val = parser.GetOptValue<T>(name); |
| 84 | + |
| 85 | + if (val) |
| 86 | + { |
| 87 | + std::cout << "Option (" << name << ") - value:"; |
| 88 | + |
| 89 | + while (val->size()) |
| 90 | + { |
| 91 | + std::cout << " " << val->front() << " "; |
| 92 | + val->pop_front(); |
| 93 | + } |
| 94 | + |
| 95 | + std::cout << std::endl; |
| 96 | + } |
| 97 | + else |
| 98 | + { |
| 99 | + std::cout << "No option (" << name << ")" << std::endl; |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | +template <typename T> |
| 104 | +void GetAndPrintStack(const args::Parser &parser, const std::string &name) |
| 105 | +{ |
| 106 | + auto val = parser.GetOptValue<T>(name); |
| 107 | + |
| 108 | + if (val) |
| 109 | + { |
| 110 | + std::cout << "Option (" << name << ") - value:"; |
| 111 | + |
| 112 | + while (val->size()) |
| 113 | + { |
| 114 | + std::cout << " " << val->top() << " "; |
| 115 | + val->pop(); |
| 116 | + } |
| 117 | + |
| 118 | + std::cout << std::endl; |
| 119 | + } |
| 120 | + else |
| 121 | + { |
| 122 | + std::cout << "No option (" << name << ")" << std::endl; |
| 123 | + } |
| 124 | +} |
| 125 | + |
| 126 | +template <typename T> |
| 127 | +void GetAndPrintIterableContainer(const args::Parser &parser, const std::string &name) |
| 128 | +{ |
| 129 | + auto val = parser.GetOptValue<T>(name); |
| 130 | + |
| 131 | + if (val) |
| 132 | + { |
| 133 | + std::cout << "Option (" << name << ") - value:"; |
| 134 | + |
| 135 | + for (auto &element : *val) |
| 136 | + { |
| 137 | + std::cout << " " << element << " "; |
| 138 | + } |
| 139 | + |
| 140 | + std::cout << std::endl; |
| 141 | + } |
| 142 | + else |
| 143 | + { |
| 144 | + std::cout << "No option (" << name << ")" << std::endl; |
| 145 | + } |
| 146 | +} |
0 commit comments