shell-cmd v1.2
Recursively find files matching a regex and execute a shell command for each match.
Loading...
Searching...
No Matches
Argz< String > Class Template Reference

#include <argz.hpp>

Collaboration diagram for Argz< String >:

Public Member Functions

 Argz ()=default
 Argz (int argc, char **argv)
 Argz (const Argz< String > &a)
Argz< String > & operator= (const Argz< String > &a)
 Argz (Argz< String > &&a)
Argz< String > & operator= (Argz< String > &&a)
Argz< String > & initArgs (int argc, char **argv)
void reset ()
Argz< String > & addOptionSingle (const int &c, const String &description)
Argz< String > & addOptionSingleValue (const int &c, const String &description)
Argz< String > & addOptionDouble (const int &code, const String &value, const String &description)
Argz< String > & addOptionDoubleValue (const int &code, const String &value, const String &description)
int lookUpCode (const String &value)
int proc (Argument< String > &a)
template<typename T>
void help (T &cout)

Protected Attributes

ArgumentData< String > arg_data
std::unordered_map< int, Argument< String > > arg_info

Private Attributes

int index = 0
int cindex = 1

Detailed Description

template<StringType String>
class Argz< String >

Definition at line 91 of file argz.hpp.

Constructor & Destructor Documentation

◆ Argz() [1/4]

template<StringType String>
Argz< String >::Argz ( )
default

Referenced by addOptionDouble(), addOptionDoubleValue(), addOptionSingle(), addOptionSingleValue(), Argz(), Argz(), initArgs(), operator=(), and operator=().

Here is the caller graph for this function:

◆ Argz() [2/4]

template<StringType String>
Argz< String >::Argz ( int argc,
char ** argv )
inline

Definition at line 94 of file argz.hpp.

94{ initArgs(argc, argv); }
Definition argz.hpp:91
Argz< String > & initArgs(int argc, char **argv)
Definition argz.hpp:120

References initArgs().

Here is the call graph for this function:

◆ Argz() [3/4]

template<StringType String>
Argz< String >::Argz ( const Argz< String > & a)
inline

Definition at line 95 of file argz.hpp.

std::unordered_map< int, Argument< String > > arg_info
Definition argz.hpp:386
ArgumentData< String > arg_data
Definition argz.hpp:385
int cindex
Definition argz.hpp:389
int index
Definition argz.hpp:389

References arg_data, arg_info, Argz(), cindex, and index.

Here is the call graph for this function:

◆ Argz() [4/4]

template<StringType String>
Argz< String >::Argz ( Argz< String > && a)
inline

Definition at line 110 of file argz.hpp.

References arg_data, arg_info, Argz(), cindex, and index.

Here is the call graph for this function:

Member Function Documentation

◆ operator=() [1/2]

template<StringType String>
Argz< String > & Argz< String >::operator= ( const Argz< String > & a)
inline

Definition at line 97 of file argz.hpp.

97 {
99 if (!arg_info.empty()) {
100 arg_info.erase(arg_info.begin(), arg_info.end());
101 }
102 for (const auto &i : a.arg_info) {
103 arg_info[i.first] = i.second;
104 }
105 index = a.index;
106 cindex = a.cindex;
107 return *this;
108 }

References arg_data, arg_info, Argz(), cindex, and index.

Here is the call graph for this function:

◆ operator=() [2/2]

template<StringType String>
Argz< String > & Argz< String >::operator= ( Argz< String > && a)
inline

Definition at line 112 of file argz.hpp.

112 {
115 index = a.index;
116 cindex = a.cindex;
117 return *this;
118 }

References arg_data, arg_info, Argz(), cindex, and index.

Here is the call graph for this function:

◆ initArgs()

template<StringType String>
Argz< String > & Argz< String >::initArgs ( int argc,
char ** argv )
inline

Definition at line 120 of file argz.hpp.

120 {
121 arg_data.argc = argc;
123 for (int i = 1; i < argc; ++i) {
124 const char *a = argv[i];
125 arg_data.args.push_back(a);
126 }
127 reset();
128 return *this;
129 }
131 for (int i = 1; i < argc; ++i) {
132 const char *a = argv[i];
133 String data;
134 for (size_t z = 0; a[z] != 0; ++z) {
135 data += static_cast<typename String::value_type>(a[z]);
136 }
137 arg_data.args.push_back(data);
138 }
139 reset();
140 return *this;
141 }
142 reset();
143 return *this;
144 }
void reset()
Definition argz.hpp:146

References arg_data, Argz(), and reset().

Referenced by Argz().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset()

template<StringType String>
void Argz< String >::reset ( )
inline

Definition at line 146 of file argz.hpp.

146 {
147 index = 0;
148 cindex = 1;
149 }

References cindex, and index.

Referenced by initArgs().

Here is the caller graph for this function:

◆ addOptionSingle()

template<StringType String>
Argz< String > & Argz< String >::addOptionSingle ( const int & c,
const String & description )
inline

Definition at line 151 of file argz.hpp.

151 {
153 a.arg_letter = c;
154 a.arg_type = ArgType::ARG_SINGLE;
155 a.desc = description;
156 arg_info[c] = a;
157 return *this;
158 }

References arg_info, Argument< String >::arg_letter, ARG_SINGLE, Argument< String >::arg_type, Argz(), and Argument< String >::desc.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addOptionSingleValue()

template<StringType String>
Argz< String > & Argz< String >::addOptionSingleValue ( const int & c,
const String & description )
inline

Definition at line 160 of file argz.hpp.

160 {
162 a.arg_letter = c;
163 a.arg_type = ArgType::ARG_SINGLE_VALUE;
164 a.desc = description;
165 arg_info[c] = a;
166 return *this;
167 }

References arg_info, Argument< String >::arg_letter, ARG_SINGLE_VALUE, Argument< String >::arg_type, Argz(), and Argument< String >::desc.

Here is the call graph for this function:

◆ addOptionDouble()

template<StringType String>
Argz< String > & Argz< String >::addOptionDouble ( const int & code,
const String & value,
const String & description )
inline

Definition at line 169 of file argz.hpp.

169 {
171 a.arg_letter = code;
172 a.arg_type = ArgType::ARG_DOUBLE;
173 a.desc = description;
174 a.arg_name = value;
175 arg_info[code] = a;
176 return *this;
177 }

References ARG_DOUBLE, arg_info, Argument< String >::arg_letter, Argument< String >::arg_name, Argument< String >::arg_type, Argz(), and Argument< String >::desc.

Here is the call graph for this function:

◆ addOptionDoubleValue()

template<StringType String>
Argz< String > & Argz< String >::addOptionDoubleValue ( const int & code,
const String & value,
const String & description )
inline

Definition at line 179 of file argz.hpp.

179 {
181 a.arg_letter = code;
182 a.arg_type = ArgType::ARG_DOUBLE_VALUE;
183 a.desc = description;
184 a.arg_name = value;
185 arg_info[code] = a;
186 return *this;
187 }

References ARG_DOUBLE_VALUE, arg_info, Argument< String >::arg_letter, Argument< String >::arg_name, Argument< String >::arg_type, Argz(), and Argument< String >::desc.

Here is the call graph for this function:

◆ lookUpCode()

template<StringType String>
int Argz< String >::lookUpCode ( const String & value)
inline

Definition at line 189 of file argz.hpp.

189 {
190 for (const auto &i : arg_info) {
191 if (i.second.arg_name == value) {
192 return i.second.arg_letter;
193 }
194 }
195 return -1;
196 }

References arg_info.

Referenced by proc().

Here is the caller graph for this function:

◆ proc()

template<StringType String>
int Argz< String >::proc ( Argument< String > & a)
inline

Definition at line 198 of file argz.hpp.

198 {
199 if (index < static_cast<int>(arg_data.args.size())) {
200 const String &type{arg_data.args[index]};
201 if (type.length() > 3 && type[0] == '-' && type[1] == '-') {
202 String name{};
203 for (size_t z = 2; z < type.length(); ++z)
204 name += type[z];
205 int code = lookUpCode(name);
206 if (code != -1) {
207 auto pos = arg_info.find(code);
208 if (pos != arg_info.end()) {
209 if (pos->second.arg_type == ArgType::ARG_DOUBLE) {
210 a = pos->second;
211 a.arg_name = name;
212 index++;
213 return code;
214 } else {
215 a = pos->second;
216 a.arg_name = name;
217 if (++index < static_cast<int>(arg_data.args.size()) && arg_data.args[index][0] != '-') {
218 a.arg_name = name;
219 a.arg_value = arg_data.args[index];
220 index++;
221 return code;
222 } else {
224 throw ArgException<String>("Expected Value");
225 }
226 }
227 }
228 }
229 } else {
231 String value = "Error argument: ";
232 value += name;
233 value += " switch not found";
235 }
237 String value = L"Error argument: ";
238 value += name;
239 value += L" switch not found";
241 }
242 }
243 } else if (type.length() == 1 && type[0] == '-') {
245 throw ArgException<String>("Expected Value found -");
246 }
248 throw ArgException<String>(L"Expected Value found -");
249 }
250 } else if (type.length() > 1 && (type[0] == '-')) {
251 const int c{type[cindex]};
252 const auto pos{arg_info.find(c)};
253 cindex++;
254 if (cindex >= static_cast<int>(type.length())) {
255 cindex = 1;
256 index++;
257 }
259 name_val += static_cast<typename String::value_type>(c);
260 if (pos != arg_info.end()) {
261 if (pos->second.arg_type == ArgType::ARG_SINGLE) {
262 a = pos->second;
263 a.arg_name = name_val;
264 return c;
265 } else if (pos->second.arg_type == ArgType::ARG_SINGLE_VALUE) {
266 if (index < static_cast<int>(arg_data.args.size())) {
267 const String &s{arg_data.args[index]};
268 if (s.length() > 1 && s[0] == '-' && !(s[1] >= '0' && s[1] <= '9')) {
270 throw ArgException<String>("Expected value");
271 }
273 throw ArgException<String>(L"Expected value");
274 }
275 } else if (s.length() == 1 && s[0] == '-') {
277 throw ArgException<String>("Expected Value found -");
278 }
280 throw ArgException<String>(L"Expected Value found -");
281 }
282 }
283 if (s.length() > 0) {
284 a = pos->second;
285 a.arg_value = s;
286 a.arg_name = name_val;
287 index++;
288 return c;
289 }
290 } else {
292 throw ArgException<String>("Expected Value");
293 }
295 throw ArgException<String>(L"Expected Value");
296 }
297 }
298 } else {
300 throw ArgException<String>("Invalid switch not found!");
301 }
303 throw ArgException<String>(L"Invalid switch not found!");
304 }
305 }
306 } else {
309 value = "Error argument ";
310 value += static_cast<typename String::value_type>(c);
311 value += " switch not found.";
313 }
316 value = L"Error argument ";
317 value += static_cast<typename String::value_type>(c);
318 value += L" switch not found.";
320 }
321 }
322 } else {
324 a.arg_name = String{};
325 a.arg_type = ArgType::ARG_NONE;
326 a.arg_name = a.arg_value = arg_data.args.at(index);
327 index++;
328 return '-';
329 }
330 }
331 return -1;
332 }
int lookUpCode(const String &value)
Definition argz.hpp:189

References arg_data, ARG_DOUBLE, arg_info, Argument< String >::arg_name, ARG_NONE, ARG_SINGLE, ARG_SINGLE_VALUE, Argument< String >::arg_type, Argument< String >::arg_value, cindex, index, and lookUpCode().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ help()

template<StringType String>
template<typename T>
void Argz< String >::help ( T & cout)
inline

Definition at line 335 of file argz.hpp.

335 {
339 for (const auto &i : arg_info) {
340 if (i.second.arg_type == ArgType::ARG_SINGLE || i.second.arg_type == ArgType::ARG_SINGLE_VALUE)
341 v.push_back(i.second);
342 else if (i.second.arg_type == ArgType::ARG_DOUBLE || i.second.arg_type == ArgType::ARG_DOUBLE_VALUE)
343 v2.push_back(i.second);
344 }
345 std::sort(v.begin(), v.end());
346 std::sort(v2.begin(), v2.end());
348 farg.reserve(v.size() + v2.size());
349 std::copy(v.begin(), v.end(), std::back_inserter(farg));
350 std::copy(v2.begin(), v2.end(), std::back_inserter(farg));
351 for (auto a = farg.begin(); a != farg.end(); ++a) {
352 if (a->arg_type == ArgType::ARG_SINGLE || a->arg_type == ArgType::ARG_SINGLE_VALUE) {
354 String item;
355 item += static_cast<char_type>(a->arg_letter);
356 cout << "-" << std::setfill(' ') << std::setw(9) << std::left << item << "\t";
357 cout << std::setfill(' ') << std::left << std::setw(10) << a->desc;
358 cout << '\n';
359 } else if constexpr (std::is_same<char_type, wchar_t>::value) {
360 String item;
361 item += static_cast<char_type>(a->arg_letter);
362 cout << L"-" << std::setfill(L' ') << std::setw(9) << std::left << item << L"\t";
363 cout << std::setfill(L' ') << std::setw(10) << a->desc;
364 cout << L'\n';
365 }
366 } else {
368 cout << "--";
369 cout << std::setfill(' ') << std::left << std::setw(10) << a->arg_name;
370 cout << "\t";
371 cout << std::setw(10) << a->desc;
372 cout << '\n';
373 } else if constexpr (std::is_same<char_type, wchar_t>::value) {
374 cout << L"--";
375 cout << std::setfill(L' ') << std::left << std::setw(10) << a->arg_name;
376 cout << L"\t";
377 cout << std::setw(10) << std::left << a->desc;
378 cout << L'\n';
379 }
380 }
381 }
382 }

References ARG_DOUBLE, ARG_DOUBLE_VALUE, arg_info, ARG_SINGLE, and ARG_SINGLE_VALUE.

Member Data Documentation

◆ arg_data

template<StringType String>
ArgumentData<String> Argz< String >::arg_data
protected

Definition at line 385 of file argz.hpp.

Referenced by Argz(), Argz(), initArgs(), operator=(), operator=(), and proc().

◆ arg_info

template<StringType String>
std::unordered_map<int, Argument<String> > Argz< String >::arg_info
protected

◆ index

template<StringType String>
int Argz< String >::index = 0
private

Definition at line 389 of file argz.hpp.

Referenced by Argz(), Argz(), operator=(), operator=(), proc(), and reset().

◆ cindex

template<StringType String>
int Argz< String >::cindex = 1
private

Definition at line 389 of file argz.hpp.

Referenced by Argz(), Argz(), operator=(), operator=(), proc(), and reset().


The documentation for this class was generated from the following file: