| Leonetienne/Hazelnupp Simple, easy to use, command line parameter interface

CmdArgsInterface.cpp
Go to the documentation of this file.
1 #include "CmdArgsInterface.h"
2 #include "VoidValue.h"
3 #include "IntValue.h"
4 #include "FloatValue.h"
5 #include "StringValue.h"
6 #include "ListValue.h"
7 #include "HazelnuppException.h"
8 #include "Placeholders.h"
9 #include "StringTools.h"
10 #include <iostream>
11 #include <cstdlib>
12
13 using namespace Hazelnp;
14
15 CmdArgsInterface::CmdArgsInterface()
16 {
17 return;
18 }
19
20 CmdArgsInterface::CmdArgsInterface(const int argc, const char* const* argv)
21 {
22 Parse(argc, argv);
23 return;
24 }
25
26 CmdArgsInterface::~CmdArgsInterface()
27 {
28 for (auto& it : parameters)
29 delete it.second;
30
31 parameters.clear();
32
33 return;
34 }
35
36 void CmdArgsInterface::Parse(const int argc, const char* const* argv)
37 {
38 try
39 {
40 // Populate raw arguments
41 PopulateRawArgs(argc, argv);
42
43 // Expand abbreviations
44 ExpandAbbreviations();
45
46 executableName = std::string(rawArgs[0]);
47
48 // Read and parse all parameters
49 std::size_t i = 1;
50 while (i < rawArgs.size())
51 {
52 if ((rawArgs[i].length() > 2) && (rawArgs[i].substr(0, 2) == "--"))
53 {
54 Parameter* param = nullptr;
55 i = ParseNextParameter(i, param);
56
57 parameters.insert(std::pair<std::string, Parameter*>(param->Key(), param));
58 }
59 else
60 i++;
61 }
62
63 // Apply constraints such as default values, and required parameters.
64 // Types have already been enforced.
65 // Dont apply constraints when we are just printind the param docs
66 if ((!catchHelp) || (!HasParam("--help")))
67 ApplyConstraints();
68 }
69 catch (const HazelnuppConstraintIncompatibleParameters& exc)
70 {
71 if (crashOnFail)
72 {
73 std::cout << GenerateDocumentation() << std::endl << std::endl;
74 std::cerr << "Parameter error: " << exc.What() << std::endl;
75 quick_exit(-1000);
76 }
77 else
78 throw exc; // yeet
79 }
80 catch (const HazelnuppConstraintMissingValue& exc)
81 {
82 if (crashOnFail)
83 {
84 std::cout << GenerateDocumentation() << std::endl << std::endl;
85 std::cerr << "Parameter error: " << exc.What() << std::endl;
86 quick_exit(-1001);
87 }
88 else
89 throw exc; // yeet
90 }
91 catch (const HazelnuppConstraintTypeMissmatch& exc)
92 {
93 if (crashOnFail)
94 {
95 std::cout << GenerateDocumentation() << std::endl << std::endl;
96 std::cerr << "Parameter error: " << exc.What() << std::endl;
97 quick_exit(-1002);
98 }
99 else
100 throw exc; // yeet
101 }
102 catch (const HazelnuppConstraintException& exc)
103 {
104 if (crashOnFail)
105 {
106 std::cout << GenerateDocumentation() << std::endl << std::endl;
107 std::cerr << "Parameter error: " << exc.What() << std::endl;
108 quick_exit(-1003);
109 }
110 else
111 throw exc; // yeet
112 }
113 catch (const HazelnuppException& exc)
114 {
115 if (crashOnFail)
116 {
117 std::cout << GenerateDocumentation() << std::endl << std::endl;
118 std::cerr << "Parameter error: " << exc.What() << std::endl;
119 quick_exit(-1004);
120 }
121 else
122 throw exc; // yeet
123 }
124
125 // Catch --help parameter
126 if ((catchHelp) && (HasParam("--help")))
127 {
128 std::cout << GenerateDocumentation() << std::endl;
129 quick_exit(0);
130 }
131
132 return;
133 }
134
135 std::size_t CmdArgsInterface::ParseNextParameter(const std::size_t parIndex, Parameter*& out_Par)
136 {
137 std::size_t i = parIndex;
138 const std::string key = rawArgs[parIndex];
139 std::vector<std::string> values;
140
141 // Get values
142 for (i++; i < rawArgs.size(); i++)
143 // If not another parameter
144 if ((rawArgs[i].length() < 2) || (rawArgs[i].substr(0, 2) != "--"))
145 values.emplace_back(rawArgs[i]);
146 else
147 {
148 break;
149 }
150
151 // Fetch constraint info
152 const ParamConstraint* pcn = GetConstraintForKey(key);
153
154 Value* parsedVal = ParseValue(values, pcn);
155 if (parsedVal != nullptr)
156 {
157 out_Par = new Parameter(key, parsedVal);
158
159 delete parsedVal;
160 parsedVal = nullptr;
161 }
162 else
163 throw std::runtime_error("Unable to parse parameter!");
164
165 return i;
166 }
167
168 void CmdArgsInterface::PopulateRawArgs(const int argc, const char* const* argv)
169 {
170 rawArgs.clear();
171 rawArgs.reserve(argc);
172
173 for (int i = 0; i < argc; i++)
174 rawArgs.emplace_back(std::string(argv[i]));
175
176 return;
177 }
178
179 void CmdArgsInterface::ExpandAbbreviations()
180 {
181 // Abort if no abbreviations
182 if (parameterAbreviations.size() == 0)
183 return;
184
185 for (std::string& arg : rawArgs)
186 {
187 // Is arg registered as an abbreviation?
188 auto abbr = parameterAbreviations.find(arg);
189 if (abbr != parameterAbreviations.end())
190 {
191 // Yes: replace arg with the long form
192 arg = abbr->second;
193 }
194 }
195
196 return;
197 }
198
199 bool CmdArgsInterface::HasParam(const std::string& key) const
200 {
201 return parameters.find(key) != parameters.end();
202 }
203
204 Value* CmdArgsInterface::ParseValue(const std::vector<std::string>& values, const ParamConstraint* constraint)
205 {
206 // This is the raw (unconverted) data type the user provided
207 DATA_TYPE rawInputType;
208
209 // Constraint values
210 const bool constrainType = (constraint != nullptr) && (constraint->constrainType);
211
212 // Void-type
213 if (values.size() == 0)
214 {
215 rawInputType = DATA_TYPE::VOID;
216
217 // Is a list forced via a constraint? If yes, return an empty list
218 if ((constrainType) &&
219 (constraint->requiredType == DATA_TYPE::LIST))
220 return new ListValue();
221
222 // Is a string forced via a constraint? If yes, return an empty string
223 else if ((constrainType) &&
224 (constraint->requiredType == DATA_TYPE::STRING))
225 return new StringValue("");
226
227 // Is an int or float forced via constraint? If yes, throw an exception
228 else if ((constrainType) &&
229 ((constraint->requiredType == DATA_TYPE::INT) ||
230 (constraint->requiredType == DATA_TYPE::FLOAT)))
231 throw HazelnuppConstraintTypeMissmatch(
232 constraint->key,
233 constraint->requiredType,
234 rawInputType,
235 GetDescription(constraint->key)
236 );
237
238 // Else, just return the void type
239 return new VoidValue;
240 }
241
242 // Force void type by constraint
243 else if ((constrainType) &&
244 (constraint->requiredType == DATA_TYPE::VOID))
245 {
246 return new VoidValue;
247 }
248
249 // List-type
250 else if (values.size() > 1)
251 {
252 rawInputType = DATA_TYPE::LIST;
253
254 // Should the type be something other than list?
255 if ((constrainType) &&
256 (constraint->requiredType != DATA_TYPE::LIST))
257 {
258 throw HazelnuppConstraintTypeMissmatch(
259 constraint->key,
260 constraint->requiredType,
261 rawInputType,
262 GetDescription(constraint->key)
263 );
264 }
265
266 ListValue* newList = new ListValue();
267 for (const std::string& val : values)
268 {
269 Value* tmp = ParseValue({ val });
270 newList->AddValue(tmp);
271 delete tmp;
272 }
273 return newList;
274 }
275
276 // Now we're only dealing with a single value
277 const std::string& val = values[0];
278
279 // String
280 if (!Internal::StringTools::IsNumeric(val, true))
281 {
282 rawInputType = DATA_TYPE::STRING;
283
284 // Is the type not supposed to be a string?
285 // void and list are already sorted out
286 if ((constrainType) &&
287 (constraint->requiredType != DATA_TYPE::STRING))
288 {
289 // We can only force a list-value from here
290 if (constraint->requiredType == DATA_TYPE::LIST)
291 {
292 ListValue* list = new ListValue();
293 Value* tmp = ParseValue({ val });
294 list->AddValue(tmp);
295 delete tmp;
296 tmp = nullptr;
297 return list;
298 }
299 // Else it is not possible to convert to a numeric
300 else
301 throw HazelnuppConstraintTypeMissmatch(
302 constraint->key,
303 constraint->requiredType,
304 rawInputType,
305 GetDescription(constraint->key)
306 );
307 }
308
309 return new StringValue(val);
310 }
311
312 // In this case we have a numeric value.
313 // We should still produce a string if requested
314 if ((constrainType) &&
315 (constraint->requiredType == DATA_TYPE::STRING))
316 return new StringValue(val);
317
318 // Numeric
319 bool isInt;
320 long double num;
321
322 if (Internal::StringTools::ParseNumber(val, isInt, num))
323 {
324 rawInputType = isInt ? DATA_TYPE::INT : DATA_TYPE::FLOAT;
325
326 // Is the type constrained?
327 // (only int and float left)
328 if (constrainType)
329 {
330 // Must it be an integer?
331 if (constraint->requiredType == DATA_TYPE::INT)
332 return new IntValue((long long int)num);
333 // Must it be a floating point?
334 else if (constraint->requiredType == DATA_TYPE::FLOAT)
335 return new FloatValue(num);
336 // Else it must be a List
337 else
338 {
339 ListValue* list = new ListValue();
340 Value* tmp = ParseValue({ val });
341 list->AddValue(tmp);
342 delete tmp;
343 tmp = nullptr;
344 return list;
345 }
346 }
347 // Type is not constrained
348 else
349 {
350 // Integer
351 if (isInt)
352 return new IntValue((long long int)num);
353
354 // Double
355 return new FloatValue(num);
356 }
357 }
358
359 // Failed
360 return nullptr;
361 }
362
363 bool CmdArgsInterface::GetCrashOnFail() const
364 {
365 return crashOnFail;
366 }
367
368 void CmdArgsInterface::SetCatchHelp(bool catchHelp)
369 {
370 this->catchHelp = catchHelp;
371 return;
372 }
373
374 bool CmdArgsInterface::GetCatchHelp() const
375 {
376 return catchHelp;
377 }
378
379 void CmdArgsInterface::SetBriefDescription(const std::string& description)
380 {
381 briefDescription = description;
382 return;
383 }
384
385 const std::string& CmdArgsInterface::GetBriefDescription()
386 {
387 return briefDescription;
388 }
389
390 void Hazelnp::CmdArgsInterface::RegisterDescription(const std::string& parameter, const std::string& description)
391 {
392 parameterDescriptions[parameter] = description;
393 return;
394 }
395
396 const std::string& Hazelnp::CmdArgsInterface::GetDescription(const std::string& parameter) const
397 {
398 // Do we already have a description for this parameter?
399 if (!HasDescription(parameter))
400 // No? Then return ""
401 return Placeholders::g_emptyString;
402
403 // We do? Then return it
404 return parameterDescriptions.find(parameter)->second;
405 }
406
407 bool CmdArgsInterface::HasDescription(const std::string& parameter) const
408 {
409 return parameterDescriptions.find(parameter) != parameterDescriptions.end();
410 }
411
412 void CmdArgsInterface::ClearDescription(const std::string& parameter)
413 {
414 // This will just do nothing if the entry does not exist
415 parameterDescriptions.erase(parameter);
416 return;
417 }
418
419 void Hazelnp::CmdArgsInterface::ClearDescriptions()
420 {
421 parameterDescriptions.clear();
422 return;
423 }
424
425 std::string CmdArgsInterface::GenerateDocumentation() const
426 {
427 std::stringstream ss;
428
429 // Add brief, if available
430 if (briefDescription.length() > 0)
431 ss << briefDescription << std::endl;
432
433 // Collect parameter information
434 struct ParamDocEntry
435 {
436 std::string abbreviation;
437 std::string description;
438 std::string type;
439 bool required = false;
440 bool typeIsForced = false;
441 std::string defaultVal;
442 };
443 std::unordered_map<std::string, ParamDocEntry> paramInfos;
444
445 // Collect descriptions
446 for (const auto& it : parameterDescriptions)
447 {
448 // Do we already have that param in the paramInfo set?
449 if (paramInfos.find(it.first) == paramInfos.end())
450 // No? Create it.
451 paramInfos[it.first] = ParamDocEntry();
452
453 paramInfos[it.first].description = it.second;
454 }
455
456 // Collect abbreviations
457 // first value is abbreviation, second is long form
458 for (const auto& it : parameterAbreviations)
459 {
460 // Do we already have that param in the paramInfo set?
461 if (paramInfos.find(it.second) == paramInfos.end())
462 // No? Create it.
463 paramInfos[it.second] = ParamDocEntry();
464
465 paramInfos[it.second].abbreviation = it.first;
466 }
467
468 // Collect constraints
469 for (const auto& it : parameterConstraints)
470 {
471 // Do we already have that param in the paramInfo set?
472 if (paramInfos.find(it.first) == paramInfos.end())
473 // No? Create it.
474 paramInfos[it.first] = ParamDocEntry();
475
476 ParamDocEntry& cached = paramInfos[it.first];
477 cached.required = it.second.required;
478 cached.typeIsForced = it.second.constrainType;
479 cached.type = DataTypeToString(it.second.requiredType);
480
481 std::stringstream defaultValueSs;
482 for (const std::string& s : it.second.defaultValue)
483 {
484 defaultValueSs << '\'' << s << '\'';
485
486 // Add a space if we are not at the last entry
487 if ((void*)&s != (void*)&it.second.defaultValue.back())
488 defaultValueSs << " ";
489 }
490 cached.defaultVal = defaultValueSs.str();
491 }
492
493 // Now generate the documentatino body
494 if (paramInfos.size() > 0)
495 {
496 ss << std::endl
497 << "==== AVAILABLE PARAMETERS ===="
498 << std::endl << std::endl;
499
500 std::size_t counter = 0;
501 for (const auto& it : paramInfos)
502 {
503 const ParamDocEntry& pde = it.second;
504
505 // Put name
506 ss << it.first << " ";
507
508 // Put abbreviation
509 if (pde.abbreviation.length() > 0)
510 ss << pde.abbreviation << " ";
511
512 // Put type
513 if (pde.typeIsForced)
514 ss << pde.type << " ";
515
516 // Put default value
517 if (pde.defaultVal.length() > 0)
518 ss << "default=[" << pde.defaultVal << "] ";
519
520 // Put required tag, but only if no default value
521 if ((pde.required) && (pde.defaultVal.length() == 0))
522 ss << "[[REQUIRED]] ";
523
524 // Put brief description
525 if (pde.description.length() > 0)
526 ss << pde.description;
527
528 // Omit linebreaks when we're on the last element
529 if (counter < paramInfos.size()-1)
530 ss << std::endl << std::endl;
531
532 counter++;
533 }
534 }
535
536 return ss.str();
537 }
538
539 void CmdArgsInterface::ApplyConstraints()
540 {
541 // Enforce required parameters / default values
542 for (const auto& pc : parameterConstraints)
543 // Parameter in question is not supplied
544 if (!HasParam(pc.second.key))
545 {
546 // Do we have a default value?
547 if (pc.second.defaultValue.size() > 0)
548 {
549 // Then create it now, by its default value
550 Value* tmp = ParseValue(pc.second.defaultValue, &pc.second);
551 parameters.insert(std::pair<std::string, Parameter*>(
552 pc.second.key,
553 new Parameter(pc.second.key, tmp)
554 ));
555
556 delete tmp;
557 tmp = nullptr;
558 }
559 // So we do not have a default value...
560 else
561 {
562 // Is it important to have the missing parameter?
563 if (pc.second.required)
564 // Throw an error message then
565 throw HazelnuppConstraintMissingValue(
566 pc.second.key,
567 GetDescription(pc.second.key)
568 );
569 }
570 }
571 // The parameter in question IS supplied
572 else
573 {
574 // Enforce parameter incompatibility
575
576 // Is ANY parameter present listed as incompatible with our current one?
577 for (const std::string& incompatibility : pc.second.incompatibleParameters)
578 for (const std::pair<std::string, Parameter*>& otherParam : parameters)
579 {
580 if (otherParam.first == incompatibility)
581 throw HazelnuppConstraintIncompatibleParameters(pc.second.key, incompatibility);
582 }
583 }
584
585 return;
586 }
587
588 ParamConstraint CmdArgsInterface::GetConstraint(const std::string& parameter) const
589 {
590 return parameterConstraints.find(parameter)->second;
591 }
592
593 void CmdArgsInterface::ClearConstraint(const std::string& parameter)
594 {
595 parameterConstraints.erase(parameter);
596 return;
597 }
598
599 const std::string& CmdArgsInterface::GetExecutableName() const
600 {
601 return executableName;
602 }
603
604 const Value& CmdArgsInterface::operator[](const std::string& key) const
605 {
606 // Throw exception if param is unknown
607 if (!HasParam(key))
608 throw HazelnuppInvalidKeyException();
609
610 return *parameters.find(key)->second->GetValue();
611 }
612
613 void CmdArgsInterface::RegisterAbbreviation(const std::string& abbrev, const std::string& target)
614 {
615 parameterAbreviations.insert(std::pair<std::string, std::string>(abbrev, target));
616 return;
617 }
618
619 const std::string& CmdArgsInterface::GetAbbreviation(const std::string& abbrev) const
620 {
621 if (!HasAbbreviation(abbrev))
622 return Placeholders::g_emptyString;
623
624 return parameterAbreviations.find(abbrev)->second;
625 }
626
627 bool CmdArgsInterface::HasAbbreviation(const std::string& abbrev) const
628 {
629 return parameterAbreviations.find(abbrev) != parameterAbreviations.end();
630 }
631
632 void CmdArgsInterface::ClearAbbreviation(const std::string& abbrevation)
633 {
634 parameterAbreviations.erase(abbrevation);
635 return;
636 }
637
638 void CmdArgsInterface::ClearAbbreviations()
639 {
640 parameterAbreviations.clear();
641 return;
642 }
643
644 void CmdArgsInterface::RegisterConstraint(const std::string& key, const ParamConstraint& constraint)
645 {
646 // Magic syntax, wooo
647 (parameterConstraints[key] = constraint).key = key;
648 return;
649 }
650
651 void CmdArgsInterface::ClearConstraints()
652 {
653 parameterConstraints.clear();
654 return;
655 }
656
657 void CmdArgsInterface::SetCrashOnFail(bool crashOnFail)
658 {
659 this->crashOnFail = crashOnFail;
660 return;
661 }
662
663 const ParamConstraint* CmdArgsInterface::GetConstraintForKey(const std::string& key) const
664 {
665 const auto constraint = parameterConstraints.find(key);
666
667 if (constraint == parameterConstraints.end())
668 return nullptr;
669
670 return &constraint->second;
671 }
Hazelnp::CmdArgsInterface::GetCatchHelp
bool GetCatchHelp() const
Retruns whether the CmdArgsInterface should automatically catch the –help parameter,...
Definition: CmdArgsInterface.cpp:374
HazelnuppException.h
Hazelnp
Definition: CmdArgsInterface.h:9
Hazelnp::IntValue
Specializations for integer values (uses long long int)
Definition: IntValue.h:8
Hazelnp::CmdArgsInterface::GetConstraint
ParamConstraint GetConstraint(const std::string &parameter) const
Will return the constraint information for a specific parameter.
Definition: CmdArgsInterface.cpp:588
Hazelnp::CmdArgsInterface::ClearAbbreviations
void ClearAbbreviations()
Will delete all abbreviations.
Definition: CmdArgsInterface.cpp:638
Hazelnp::HazelnuppConstraintIncompatibleParameters
Gets thrown when a parameter constrained to be incompatible with other parameters gets supplied along...
Definition: HazelnuppException.h:101
Hazelnp::CmdArgsInterface::SetCatchHelp
void SetCatchHelp(bool catchHelp)
Sets whether the CmdArgsInterface should automatically catch the –help parameter, print the parameter...
Definition: CmdArgsInterface.cpp:368
Hazelnp::CmdArgsInterface::HasAbbreviation
bool HasAbbreviation(const std::string &abbrev) const
Will check wether or not an abbreviation is registered.
Definition: CmdArgsInterface.cpp:627
Hazelnp::HazelnuppInvalidKeyException
Gets thrown when an non-existent key gets dereferenced.
Definition: HazelnuppException.h:29
Hazelnp::CmdArgsInterface::RegisterConstraint
void RegisterConstraint(const std::string &key, const ParamConstraint &constraint)
Will register a constraint for a parameter.
Definition: CmdArgsInterface.cpp:644
StringValue.h
CmdArgsInterface.h
Hazelnp::HazelnuppException::What
const std::string & What() const
Will return an error message.
Definition: HazelnuppException.h:18
IntValue.h
Placeholders.h
Hazelnp::DATA_TYPE::VOID
@ VOID
Hazelnp::FloatValue
Specializations for floating point values (uses long double)
Definition: FloatValue.h:9
Hazelnp::CmdArgsInterface::ClearConstraint
void ClearConstraint(const std::string &parameter)
Will the constraint of a specific parameter.
Definition: CmdArgsInterface.cpp:593
Hazelnp::ParamConstraint::requiredType
DATA_TYPE requiredType
Constrain the parameter to this value. Requires constrainType to be set to true.
Definition: ParamConstraint.h:73
Hazelnp::Value
Abstract class for values.
Definition: Value.h:10
Hazelnp::HazelnuppConstraintException
Gets thrown something bad happens because of parameter constraints.
Definition: HazelnuppException.h:47
Hazelnp::CmdArgsInterface::RegisterAbbreviation
void RegisterAbbreviation(const std::string &abbrev, const std::string &target)
Will register an abbreviation (like -f for –force)
Definition: CmdArgsInterface.cpp:613
Hazelnp::CmdArgsInterface::HasParam
bool HasParam(const std::string &key) const
Will check wether a parameter exists given a key, or not.
Definition: CmdArgsInterface.cpp:199
Hazelnp::DATA_TYPE::LIST
@ LIST
Hazelnp::CmdArgsInterface::ClearConstraints
void ClearConstraints()
Will delete all constraints.
Definition: CmdArgsInterface.cpp:651
Hazelnp::Parameter
Definition: Parameter.h:8
Hazelnp::ParamConstraint
Definition: ParamConstraint.h:8
Hazelnp::Placeholders::g_emptyString
static const std::string g_emptyString
The only purpose of this is to provide the ability to return an empty string as an error for std::str...
Definition: Placeholders.h:9
Hazelnp::CmdArgsInterface::GetCrashOnFail
bool GetCrashOnFail() const
Gets whether the application crashes on an exception whilst parsing, and prints to stderr.
Definition: CmdArgsInterface.cpp:363
Hazelnp::CmdArgsInterface::HasDescription
bool HasDescription(const std::string &parameter) const
Returns whether or not a given parameter has a registered description.
Definition: CmdArgsInterface.cpp:407
Hazelnp::CmdArgsInterface::ClearDescription
void ClearDescription(const std::string &parameter)
Will delete the description of a parameter if it exists.
Definition: CmdArgsInterface.cpp:412
ListValue.h
Hazelnp::ParamConstraint::constrainType
bool constrainType
Should this parameter be forced to be of a certain type? Remember to set constrainTo to the wanted ...
Definition: ParamConstraint.h:70
Hazelnp::HazelnuppException
Generic hazelnupp exception.
Definition: HazelnuppException.h:11
Hazelnp::CmdArgsInterface::CmdArgsInterface
CmdArgsInterface()
Definition: CmdArgsInterface.cpp:15
Hazelnp::Parameter::Key
const std::string & Key() const
Will return the key of this parameter.
Definition: Parameter.cpp:21
Hazelnp::HazelnuppConstraintMissingValue
Gets thrown when a parameter constrained to be required is not provided, and has no default value set...
Definition: HazelnuppException.h:80
Hazelnp::CmdArgsInterface::ClearAbbreviation
void ClearAbbreviation(const std::string &abbrevation)
Will delete the abbreviation for a given parameter.
Definition: CmdArgsInterface.cpp:632
Hazelnp::HazelnuppConstraintTypeMissmatch
Gets thrown when a parameter is of a type that does not match the required type, and is not convertib...
Definition: HazelnuppException.h:56
VoidValue.h
Hazelnp::CmdArgsInterface::Parse
void Parse(const int argc, const char *const *argv)
Will parse command line arguments.
Definition: CmdArgsInterface.cpp:36
Hazelnp::CmdArgsInterface::SetBriefDescription
void SetBriefDescription(const std::string &description)
Sets a brief description of the application to be automatically added to the documentation.
Definition: CmdArgsInterface.cpp:379
Hazelnp::CmdArgsInterface::GetBriefDescription
const std::string & GetBriefDescription()
Returns the brief description of the application to be automatically added to the documentation.
Definition: CmdArgsInterface.cpp:385
Hazelnp::CmdArgsInterface::operator[]
const Value & operator[](const std::string &key) const
Will return the value given a key.
Definition: CmdArgsInterface.cpp:604
Hazelnp::CmdArgsInterface::ClearDescriptions
void ClearDescriptions()
Will delete all parameter descriptions.
Definition: CmdArgsInterface.cpp:419
Hazelnp::ListValue::AddValue
void AddValue(const Value *value)
Will add this value to the list.
Definition: ListValue.cpp:33
Hazelnp::VoidValue
Specializations for void values.
Definition: VoidValue.h:8
Hazelnp::CmdArgsInterface::GenerateDocumentation
std::string GenerateDocumentation() const
Will generate a text-based documentation suited to show the user, for example on –help.
Definition: CmdArgsInterface.cpp:425
Hazelnp::CmdArgsInterface::RegisterDescription
void RegisterDescription(const std::string &parameter, const std::string &description)
Willl register a short description for a parameter.
Definition: CmdArgsInterface.cpp:390
Hazelnp::Internal::StringTools::ParseNumber
static bool ParseNumber(const std::string &str, bool &out_isInt, long double &out_number)
Will convert the number in str to a number.
Definition: StringTools.cpp:82
Hazelnp::DATA_TYPE::FLOAT
@ FLOAT
Hazelnp::CmdArgsInterface::GetDescription
const std::string & GetDescription(const std::string &parameter) const
Will return a short description for a parameter, if it exists.
Definition: CmdArgsInterface.cpp:396
Hazelnp::DATA_TYPE::INT
@ INT
FloatValue.h
Hazelnp::DATA_TYPE
DATA_TYPE
The different data types a paramater can be.
Definition: DataType.h:8
Hazelnp::CmdArgsInterface::GetAbbreviation
const std::string & GetAbbreviation(const std::string &abbrev) const
Will return the long form of an abbreviation (like –force for -f) Returns "" if no match is found.
Definition: CmdArgsInterface.cpp:619
Hazelnp::DATA_TYPE::STRING
@ STRING
Hazelnp::CmdArgsInterface::GetExecutableName
const std::string & GetExecutableName() const
Will return argv[0], the name of the executable.
Definition: CmdArgsInterface.cpp:599
Hazelnp::DataTypeToString
static std::string DataTypeToString(DATA_TYPE type)
Definition: DataType.h:17
Hazelnp::Internal::StringTools::IsNumeric
static bool IsNumeric(const std::string &str, const bool allowDecimalPoint=false)
Will return true if the given string consists only of digits (including signage)
Definition: StringTools.cpp:56
Hazelnp::CmdArgsInterface::SetCrashOnFail
void SetCrashOnFail(bool crashOnFail)
Sets whether to crash the application, and print to stderr, when an exception is raised whilst parsin...
Definition: CmdArgsInterface.cpp:657
Hazelnp::ListValue
Specializations for list values (uses std::vector<Value*>)
Definition: ListValue.h:9
Hazelnp::StringValue
Specializations for string values (uses std::string)
Definition: StringValue.h:9
StringTools.h
Hazelnp::CmdArgsInterface::~CmdArgsInterface
~CmdArgsInterface()
Definition: CmdArgsInterface.cpp:26