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