AJA NTV2 SDK  18.0.0.2717
NTV2 SDK 18.0.0.2717
commandline.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
10 #include <iomanip>
11 #include <iostream>
12 #include <sstream>
13 
14 static const char kAssignChar = '=';
15 static const char kSingleDash = '-';
16 static const char *kDoubleDash = "--";
17 
19 : _names(),
20  _desc(),
21  _descExtra(),
22  _values(),
23  _defaultValue(),
24  _isSet(false)
25 {}
26 
28  const std::string &desc,
29  const std::string &defaultValue)
30 : _names(),
31  _desc(desc),
32  _descExtra(),
33  _values(),
34  _defaultValue(defaultValue),
35  _isSet(false)
36 {
37  AddName(name);
38 }
39 
41  const std::string &desc,
42  const std::string &defaultValue)
43 : _names(),
44  _desc(desc),
45  _descExtra(),
46  _values(),
47  _defaultValue(defaultValue),
48  _isSet(false)
49 {
50  for (const auto &name : names) {
51  AddName(name);
52  }
53 }
54 
56 {
57 }
58 
59 bool AJACommandLineOption::AddName(const std::string &name)
60 {
61  bool haveName = false;
62  for (size_t i = 0; i < _names.size(); i++) {
63  if (_names.at(i) == name) {
64  haveName = true;
65  break;
66  }
67  }
68  if (!haveName) {
69  _names.push_back(name);
70  }
71 
72  return haveName;
73 }
74 
76 {
77  return _names;
78 }
79 
80 bool AJACommandLineOption::HaveName(const std::string &name) const
81 {
82  for (const auto &n : _names) {
83  if (n == name) {
84  return true;
85  }
86  }
87 
88  return false;
89 }
90 
91 std::string AJACommandLineOption::Desc() const
92 {
93  return _desc;
94 }
95 
96 void AJACommandLineOption::SetDesc(const std::string &desc)
97 {
98  _desc = desc;
99 }
100 
102 {
103  return _descExtra;
104 }
105 
106 void AJACommandLineOption::SetExtraDesc(const std::string &desc)
107 {
108  _descExtra = desc;
109 }
110 
111 
112 void AJACommandLineOption::SetDefaultValue(const std::string &value)
113 {
114  _defaultValue = value;
115 }
116 
118 {
119  return _defaultValue;
120 }
121 
122 void AJACommandLineOption::AddValue(const std::string &value)
123 {
124  _values.push_back(value);
125 }
126 
127 std::string AJACommandLineOption::Value(size_t index) const
128 {
129  if (index > _values.size() || _values.empty()) {
130  return "";
131  }
132  return _values.at(index);
133 }
134 
136 {
137  return _values;
138 }
139 
141 {
142  _values.clear();
143  _isSet = false;
144 }
145 
147 {
148  return _isSet;
149 }
151 {
152  _isSet = isSet;
153 }
154 
156 : _flags(flags), _name(), _commandName(), _desc(), _descExtra(), _usageText(), _helpText(),
157  _options(), _subParsers()
158 {
159  init();
160 }
161 
162 AJACommandLineParser::AJACommandLineParser(const std::string &name, int flags)
163 : _flags(flags), _name(name), _commandName(), _desc(), _descExtra(), _usageText(), _helpText(),
164  _options(), _subParsers()
165 {
166  init();
167 }
168 
170 {
171  operator=(other);
172 }
173 
175 {
176 }
177 
179 {
180  _flags = other._flags;
181  _name = other._name;
182  _commandName = other._commandName;
183  _desc = other._desc;
184  _descExtra = other._descExtra;
185  _usageText = other._usageText;
186  _helpText = other._helpText;
187  _options = other._options;
188  _subParsers.clear();
189  for (SubParserMapConstIter iter = other._subParsers.begin(); iter != other._subParsers.end(); ++iter) {
190  _subParsers.insert(AJASubParserPair(iter->first, iter->second));
191  }
192 }
193 
194 void AJACommandLineParser::init()
195 {
196  if ((_flags & kNoDefaultHelpOption) == 0) {
197  AddHelpOption();
198  }
199  if ((_flags & kNoDefaultUsageOption) == 0) {
200  AddUsageOption();
201  }
202 }
203 
205 {
206  _flags = flags;
207 }
208 
210 {
211  _subParsers.clear();
212  _options.clear();
213 }
214 
215 void AJACommandLineParser::Reset(bool clearAll)
216 {
217  if (clearAll) {
218  Clear();
219  } else {
220  for (auto &sp : _subParsers) {
221  if (sp.second) {
222  sp.second->Reset();
223  }
224  }
225  for (auto &opt : _options) {
226  opt.Reset();
227  }
228  }
229 }
230 
232 {
233  if (!_commandName.empty()) {
234  AJACommandLineParser *sp = _subParsers.at(_commandName);
235  if (sp != NULL) {
236  return sp->Dump();
237  }
238  } else {
239  for (AJACommandLineOptionListIter iter = _options.begin();
240  iter != _options.end(); ++iter) {
241  const AJACommandLineOption &o = *iter;
242  const AJAStringList & names = o.Names();
243  std::ostringstream oss;
244  oss << "[";
245  std::string name;
246  size_t count = 0;
247  for (AJAStringListConstIter sIter = names.begin(); sIter != names.end(); ++sIter) {
248  name = *sIter;
249  oss << name;
250  if (++count < names.size()) {
251  oss << ", ";
252  }
253  }
254  oss << "] " << "set? " << (IsSet(name) ? "true" : "false") << " value = " << o.Value();
255  std::cout << oss.str() << std::endl;
256  }
257  }
258 }
259 
260 bool AJACommandLineParser::HaveOption(const std::string &name) const
261 {
262  for (const auto &opt : _options) {
263  for (const auto &n : opt.Names()) {
264  if (n == name) {
265  return true;
266  }
267  }
268  }
269  return false;
270 }
271 
272 bool AJACommandLineParser::HavePositionalArg(const std::string &name) const
273 {
274  for (const auto &arg : _positionalArgs) {
275  if (arg == name) {
276  return true;
277  }
278  }
279  return false;
280 }
281 
283 {
284  return _positionalArgs;
285 }
286 
287 bool AJACommandLineParser::OptionByName(const std::string &name, AJACommandLineOption &opt) const
288 {
289  for (const auto &o : _options) {
290  for (const auto &n : o.Names()) {
291  if (n == name) {
292  opt = o;
293  return true;
294  }
295  }
296  }
297  return false;
298 }
299 
301 {
302  const std::string &name = p->Name();
303  if (_subParsers.find(name) == _subParsers.end()) {
304  _subParsers.insert(AJASubParserPair(name, p));
305  return true;
306  }
307 
308  return false;
309 }
310 
312 {
313  AJAStringList::const_iterator iter = args.begin();
314  ++iter; // Skip exe path
315 
316  for (SubParserMap::iterator spIter = _subParsers.begin(); spIter != _subParsers.end(); ++spIter) {
317  // Is second arg a command name which belongs to a sub-parser?
318  if (*iter == spIter->first) {
319  _commandName = *iter;
320  }
321  // Iterate all args with all sub-parsers...
322  if (spIter->second != NULL) {
323  if (!spIter->second->Parse(args)) {
324  std::cerr << "Error parsing args with sub-parser: " << spIter->second->Name() << std::endl;
325  return false;
326  }
327  }
328  }
329 
330  // If the the parser name is set, expect the second arg to match (i.e. we are in a sub-parser).
331  // For example, the following case "name" would be "theCommand".
332  // If the second arg doesn't match the name, the sub-parser name is simply not present in the
333  // list of args provided. This is not an error condition.
334  // > MyApp.exe theCommand -d1 -n3 --verbose
335  if (!_name.empty() && *iter != _name) {
336  return true;
337  }
338 
339  // ...otherwise just parse the args.
340  bool havePositionalArgs = false;
341  for (; iter != args.end(); iter++) {
342  const std::string &arg = *iter;
343  // Treat subsequent args as "positional"
344  if (!havePositionalArgs && arg == kDoubleDash) {
345  havePositionalArgs = true;
346  continue;
347  }
348 
349  if (havePositionalArgs) {
350  _positionalArgs.push_back(arg);
351  continue;
352  }
353 
354  if (hasOptionPrefix(arg)) {
356  std::string optName;
357  std::string optValue;
358  std::string argStr;
359  bool doubleDash = aja::starts_with(arg, kDoubleDash);
360  bool singleDash = aja::starts_with(arg, kSingleDash) && !doubleDash;
361  if (doubleDash) {
362  argStr = arg.substr(2, arg.length());
363  } else if (singleDash) {
364  argStr = arg.substr(1, arg.length());
365  }
366  if (hasAssignmentOperator(argStr)) {
367  size_t assignPos = argStr.find_first_of(kAssignChar);
368  optName = argStr.substr(0, assignPos);
369  optValue = argStr.substr(assignPos+1, argStr.length());
370  } else {
371  // Single-dash cases we need to handle:
372  // example args: {a, apple}, {b, ball}, {c, cat}, {r, car}
373  // -a=1
374  // -a1
375  // -a 1
376  // -abc // SPECIAL CASE: short opts as long opts
377  // Should we even allow setting a value for a single-dash arg if the arg name is longer than 1 character?
378  // i.e. should -devicekona5 be legal? seems weird to me...
379  if (singleDash) { /* -argname */
380  /* handle single-dash option */
381  std::string subStr;
382  if (_flags & kShortOptionsAsLong) {
383  for (size_t c = 1; c < arg.length(); c++) {
384  subStr = arg.substr(c, 1);
385  if (HaveOption(subStr))
386  setOption(subStr, true);
387  }
388  continue;
389  } else {
390  for (size_t c = arg.length(); c > 1; c--) {
391  subStr = arg.substr(1, c-1);
392  if (HaveOption(subStr)) {
393  optName = subStr;
394  size_t count = (arg.length()-1)-optName.length();
395  optValue = arg.substr(optName.length()+1, count);
396  break;
397  } else if (_flags & kErrorOnUnknownArgs) {
398  std::cerr << "Unknown arg: " << subStr << std::endl;
399  return false;
400  }
401  }
402  }
403  } else { /* --argname */
404  optName = argStr;
405  }
406 
407  // If we have no value, and the next arg is not another arg, use it as the value for the current arg.
408  if (optValue.empty()) {
409  auto nextIter = iter;
410  nextIter++;
411  if (nextIter != args.end()) {
412  std::string nextArg = *(nextIter++);
413  if (!hasOptionPrefix(nextArg)) {
414  optValue = nextArg;
415  }
416  }
417  }
418  } // else no assignment operator
419 
420  if (HaveOption(optName)) {
421  if (!optValue.empty()) {
422  setOptionValue(optName, optValue);
423  }
424  setOption(optName, true);
425  } else if (_flags & kErrorOnUnknownArgs) {
426  std::cerr << "Unknown arg: " << optName << std::endl;
427  return false;
428  }
429  } // if hasOptionPrefix
430  } // for each arg
431 
432  if (!(_flags & kNoDefaultHelpOption))
433  if (IsSet("help"))
434  {std::cout << HelpText(); return false;}
435 
436  if (!(_flags & kNoDefaultUsageOption))
437  if (IsSet("usage"))
438  {std::cout << UsageText(); return false;}
439 
440  return true;
441 } // Parse (AJAStringList)
442 
443 bool AJACommandLineParser::Parse(int argc, const char *argv[])
444 {
445  if (argc == 0 || argv == NULL) {
446  return false;
447  }
448  AJAStringList argList;
449  for (int i = 0; i < argc; i++) {
450  argList.push_back(std::string(argv[i]));
451  }
452  return Parse(argList);
453 }
454 
455 bool AJACommandLineParser::Parse(int argc, char *argv[])
456 {
457  if (argc == 0 || argv == NULL) {
458  return false;
459  }
460  AJAStringList argList;
461  for (int i = 0; i < argc; i++) {
462  argList.push_back(std::string(argv[i]));
463  }
464  return Parse(argList);
465 }
466 
467 bool AJACommandLineParser::IsSet(const std::string &name) const
468 {
469  if (!_commandName.empty()) {
470  AJACommandLineParser *sp = _subParsers.at(_commandName);
471  if (sp != NULL) {
472  return sp->IsSet(name);
473  }
474  } else {
476  if (OptionByName(name, opt)) {
477  return opt.IsSet();
478  }
479  }
480  return false;
481 }
482 
483 AJAVariant AJACommandLineParser::Value(const std::string &name, size_t index) const
484 {
485  return AJAVariant(ValueString(name, index));
486 }
487 
488 AJAVariantList AJACommandLineParser::Values(const std::string &name) const
489 {
490  AJAStringList values = ValueStrings(name);
491  if (!values.empty()) {
492  AJAVariantList variants;
493  for (AJAStringListConstIter it = values.begin(); it != values.end(); ++it) {
494  variants.push_back(AJAVariant(*it));
495  }
496  return variants;
497  }
498  return AJAVariantList();
499 }
500 
501 std::string AJACommandLineParser::ValueString(const std::string &name, size_t index) const
502 {
503  std::string val;
504  if (!_commandName.empty()) {
505  AJACommandLineParser *sp = _subParsers.at(_commandName);
506  if (sp != NULL) {
507  return sp->ValueString(name, index);
508  }
509  } else {
511  if (OptionByName(name, opt)) {
512  val = opt.Value(index);
513  if (val.empty()) {
514  val = opt.DefaultValue();
515  }
516  }
517  }
518 
519  return val;
520 }
521 
522 AJAStringList AJACommandLineParser::ValueStrings(const std::string &name) const
523 {
524  if (!_commandName.empty()) {
525  AJACommandLineParser *sp = _subParsers.at(_commandName);
526  if (sp != NULL) {
527  return sp->ValueStrings(name);
528  }
529  } else {
531  if (OptionByName(name, opt)) {
532  return opt.Values();
533  }
534  }
535  return AJAStringList();
536 }
537 
539 {
540  bool exists = false;
541  const AJAStringList &wantNames = option.Names();
542  for (AJACommandLineOptionListIter optIter = _options.begin(); optIter != _options.end(); ++optIter) {
543  const AJAStringList &names = optIter->Names();
544  for (AJAStringListConstIter nameIter = names.begin(); nameIter != names.end(); ++nameIter) {
545  for (AJAStringListConstIter wantIter = wantNames.begin(); wantIter != wantNames.end(); ++wantIter) {
546  if (*wantIter == *nameIter) {
547  exists = true;
548  goto next;
549  }
550  }
551  }
552  }
553 
554 next:
555  if (exists) {
556  return false;
557  } else {
558  _options.push_back(option);
559  return true;
560  }
561 }
562 
564 {
565  size_t okCount = 0;
566  for (size_t i = 0; i < options.size(); i++) {
567  if (AddOption(options.at(i))) {
568  ++okCount;
569  }
570  }
571 // if (_Flags & kAutoProcessUsage)
572 // AddOption(AJACommandLineOption("usage", "Show command usage"));
573 // if (_Flags & (kAutoProcessHelp | kAutoProcessUsage))
574 // AddHelpOption();
575  return options.size() ? (okCount == options.size() ? true : false) : false;
576 }
577 
578 bool AJACommandLineParser::AddHelpOption(bool useShortName)
579 {
580  AJACommandLineOption helpOpt;
581  helpOpt.AddName("?");
582  if (useShortName) {
583  helpOpt.AddName("h");
584  }
585  helpOpt.AddName("help");
586  helpOpt.SetDesc("Print the help text");
587  return AddOption(helpOpt);
588 }
589 
591 {
592  AJACommandLineOption usageOpt;
593  usageOpt.AddName("usage");
594  if (useShortName) {
595  usageOpt.AddName("u");
596  }
597  usageOpt.SetDesc("Print the usage text");
598  return AddOption(usageOpt);
599 }
600 
601 std::string AJACommandLineParser::Name() const
602 {
603  if (!_commandName.empty()) {
604  AJACommandLineParser *sp = _subParsers.at(_commandName);
605  if (sp != NULL) {
606  return sp->Name();
607  }
608  }
609 
610  return _name;
611 }
612 
613 void AJACommandLineParser::SetUsageText(const std::string &usageText)
614 {
615  if (!_commandName.empty()) {
616  AJACommandLineParser *sp = _subParsers.at(_commandName);
617  if (sp != NULL) {
618  sp->SetUsageText(usageText);
619  }
620  } else {
621  _usageText = usageText;
622  }
623 }
624 
626 {
627  if (!_commandName.empty()) {
628  AJACommandLineParser *sp = _subParsers.at(_commandName);
629  if (sp != NULL) {
630  return sp->UsageText();
631  }
632  }
633 
634  std::string usageText;
635  if (!_usageText.empty()) {
636  usageText = _usageText;
637  } else {
638  usageText = generateUsageText();
639  }
640  return usageText;
641 }
642 
643 void AJACommandLineParser::SetHelpText(const std::string &helpText)
644 {
645  if (!_commandName.empty()) {
646  AJACommandLineParser *sp = _subParsers.at(_commandName);
647  if (sp != NULL) {
648  sp->SetHelpText(helpText);
649  }
650  } else {
651  _helpText = helpText;
652  }
653 }
654 
656 {
657  if (!_commandName.empty()) {
658  AJACommandLineParser *sp = _subParsers.at(_commandName);
659  if (sp != NULL) {
660  return sp->HelpText();
661  }
662  }
663 
664  std::string helpText;
665  if (_helpText.empty()) {
666  helpText = generateHelpText();
667  } else {
668  helpText = _helpText;
669  }
670  return helpText;
671 }
672 
673 std::string AJACommandLineParser::generateHelpText() const
674 {
675  std::ostringstream oss;
676  std::string exePath;
678  oss << "Usage: " << exePath;
679  if (!_name.empty()) {
680  oss << " " << _name;
681  }
682  oss << " [OPTION...]" << std::endl;
683 
684  // Get the longest line size first...
685  size_t longestSize = 0;
686  for (AJACommandLineOptionListIter it = _options.begin();
687  it != _options.end(); ++it) {
688  const AJAStringList &names = it->Names();
689  size_t namesLength = 0;
690  for (AJAStringListConstIter sIter = names.begin(); sIter != names.end(); ++sIter) {
691  const std::string &name = *sIter;
692  namesLength += name.length();
693  // add size of dashes
694  if (name.length() == 1) {
695  namesLength++;
696  } else {
697  namesLength += 2;
698  }
699  }
700  // add size of commas/spaces (i.e. ", ")
701  namesLength += ((names.size()*2)-2);
702  if (namesLength > longestSize) {
703  longestSize = namesLength;
704  }
705  }
706 
707  // ...now calculate all of the line padding.
708  for (AJACommandLineOptionListIter it = _options.begin();
709  it != _options.end(); ++it) {
710  oss << std::setw(2) << std::right;
711  const AJAStringList &names = it->Names();
712  size_t nameCount = 0;
713  size_t namesLength = 0;
714  for (AJAStringListConstIter sIter = names.begin(); sIter != names.end(); ++sIter) {
715  const std::string &name = *sIter;
716  namesLength += name.length();
717  if (name.length() == 1) {
718  oss << "-" << name;
719  namesLength++;
720  } else {
721  oss << "--" << name;
722  namesLength += 2;
723  }
724  if (++nameCount < names.size()) {
725  oss << ", ";
726  }
727  }
728  namesLength += ((names.size()*2)-2);
729  oss << std::setw((longestSize-namesLength) + it->Desc().length() + 8);
730  oss << it->Desc() << std::endl;
731  }
732 
733  return oss.str();
734 }
735 
736 std::string AJACommandLineParser::generateUsageText() const
737 {
738  std::ostringstream oss;
739  std::string exePath;
741  oss << "Usage: " << exePath;
742  if (!_name.empty()) {
743  oss << " " << _name;
744  }
745 
746  std::string abbrev;
747  std::ostringstream usages;
748  bool haveHelp = false;
749  bool haveUsage = false;
750  for (const auto &opt : _options) {
751  if (opt.HaveName("?")) {
752  haveHelp = true;
753  } else if (opt.HaveName("usage")) {
754  haveUsage = true;
755  } else {
756  auto names = opt.Names();
757  usages << "\t[";
758  for (size_t ndx = 0; ndx < names.size(); ndx++) {
759  auto name = names.at(ndx);
760  bool isShortName = name.length() == 1;
761  if (isShortName) {
762  abbrev += name;
763  usages << '-' << name;
764  } else {
765  usages << "--" << name;
766  }
767  if (ndx < names.size()-1) {
768  usages << '|';
769  }
770  }
771  usages << ']' << std::endl;
772  }
773  }
774 
775  // Make sure help and usage options appear at the end
776  if (haveHelp) {
777  usages << "\t[" << "-?|--help]" << std::endl;
778  }
779  if (haveUsage) {
780  usages << "\t[" << "--usage]" << std::endl;
781  }
782 
783  if (!abbrev.empty()) {
784  if (haveHelp) {
785  abbrev += '?';
786  }
787  oss << " [-" << abbrev << "]" << std::endl;
788  }
789  oss << usages.str() << std::endl;
790 
791  if (!_subParsers.empty()) {
792  oss << '\n' << "commands: " << std::endl;
793  for (const auto &sp : _subParsers) {
794  if (sp.second) {
795  oss << "\t " << sp.second->Name() << std::endl;
796  }
797  }
798  }
799  return oss.str();
800 }
801 
803 {
804  return _commandName;
805 }
806 
807 bool AJACommandLineParser::hasOptionPrefix(const std::string &name)
808 {
809  return aja::starts_with(name, kSingleDash);
810 }
811 
812 bool AJACommandLineParser::hasAssignmentOperator(const std::string &arg)
813 {
814  size_t assignPos = arg.find_first_of(kAssignChar);
815  return assignPos != std::string::npos;
816 }
817 
818 bool AJACommandLineParser::setOptionValue(const std::string &name, const std::string &value)
819 {
820  if (!value.empty()) {
821  for (size_t i = 0; i < _options.size(); i++) {
822  AJACommandLineOption opt = _options.at(i);
823  const AJAStringList &names = opt.Names();
824  for (AJAStringListConstIter iter = names.begin(); iter != names.end(); ++iter) {
825  if (name == *iter) {
826  _options[i].AddValue(value);
827  return true;
828  }
829  }
830  }
831  }
832  return false;
833 }
834 
835 bool AJACommandLineParser::setOption(const std::string &name, bool isSet)
836 {
837  for (size_t i = 0; i < _options.size(); i++) {
838  AJACommandLineOption opt = _options.at(i);
839  const AJAStringList &names = opt.Names();
840  for (AJAStringListConstIter iter = names.begin(); iter != names.end(); ++iter) {
841  if (name == *iter) {
842  _options[i].MarkSet(isSet);
843  return true;
844  }
845  }
846  }
847  return false;
848 }
kAssignChar
static const char kAssignChar
Definition: commandline.cpp:14
nlohmann::json_abiNLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON_v3_11_NLOHMANN_JSON_VERSION_PATCH::detail::parse_event_t::value
@ value
the parser finished reading a JSON value
AJACommandLineParser::Reset
void Reset(bool clearAll=false)
Definition: commandline.cpp:215
AJACommandLineOption::SetDesc
void SetDesc(const std::string &desc)
Definition: commandline.cpp:96
AJACommandLineParser::AddOption
bool AddOption(const AJACommandLineOption &option)
Definition: commandline.cpp:538
AJACommandLineParser::AddHelpOption
bool AddHelpOption(bool useShortName=false)
Definition: commandline.cpp:578
AJACommandLineParser::SetFlags
void SetFlags(int flags)
Definition: commandline.cpp:204
AJACommandLineParser::Value
AJAVariant Value(const std::string &name, size_t index=0) const
Definition: commandline.cpp:483
AJACommandLineOption::AddValue
void AddValue(const std::string &value)
Definition: commandline.cpp:122
AJACommandLineOption::ExtraDesc
std::string ExtraDesc() const
Definition: commandline.cpp:101
NULL
#define NULL
Definition: ntv2caption608types.h:19
AJACommandLineOption::AJACommandLineOption
AJACommandLineOption()
Definition: commandline.cpp:18
AJACommandLineParser::ValueStrings
AJAStringList ValueStrings(const std::string &name) const
Definition: commandline.cpp:522
AJACommandLineParser::operator=
void operator=(const AJACommandLineParser &other)
Definition: commandline.cpp:178
AJACommandLineOption::SetDefaultValue
void SetDefaultValue(const std::string &value)
Definition: commandline.cpp:112
AJACommandLineParser::HavePositionalArg
bool HavePositionalArg(const std::string &name) const
Definition: commandline.cpp:272
AJACommandLineOption::DefaultValue
std::string DefaultValue() const
Definition: commandline.cpp:117
kDoubleDash
static const char * kDoubleDash
Definition: commandline.cpp:16
AJACommandLineParser::~AJACommandLineParser
~AJACommandLineParser()
Definition: commandline.cpp:174
AJACommandLineOption::Values
AJAStringList Values() const
Definition: commandline.cpp:135
n
unsigned int n
Definition: pstream.cpp:148
AJACommandLineParser::PositionalArgs
AJAStringList PositionalArgs() const
Definition: commandline.cpp:282
AJACommandLineOption::IsSet
bool IsSet() const
Definition: commandline.cpp:146
AJACommandLineParser::SetHelpText
void SetHelpText(const std::string &helpText)
Definition: commandline.cpp:643
AJACommandLineParser::OptionByName
bool OptionByName(const std::string &name, AJACommandLineOption &opt) const
Definition: commandline.cpp:287
AJAStringList
std::vector< std::string > AJAStringList
Definition: commandline.h:18
AJACommandLineOption::SetExtraDesc
void SetExtraDesc(const std::string &desc)
Definition: commandline.cpp:106
AJAVariantList
std::vector< AJAVariant > AJAVariantList
Definition: variant.h:330
commandline.h
Declaration of Command Line classes.
AJACommandLineOptionListIter
AJACommandLineOptionList::const_iterator AJACommandLineOptionListIter
Definition: commandline.h:162
AJACommandLineParser::Values
AJAVariantList Values(const std::string &name) const
Definition: commandline.cpp:488
AJAStringListConstIter
AJAStringList::const_iterator AJAStringListConstIter
Definition: commandline.h:19
AJACommandLineParser::AddSubParser
bool AddSubParser(AJACommandLineParser *sp)
Definition: commandline.cpp:300
AJAFileIO::GetExecutablePath
static AJAStatus GetExecutablePath(std::string &path)
Definition: file_io.cpp:1361
AJACommandLineOption::~AJACommandLineOption
virtual ~AJACommandLineOption()
Definition: commandline.cpp:55
AJACommandLineOption
Definition: commandline.h:29
kNoDefaultUsageOption
@ kNoDefaultUsageOption
Definition: commandline.h:172
AJACommandLineParser::Name
std::string Name() const
Definition: commandline.cpp:601
AJASubParserPair
std::pair< std::string, AJACommandLineParser * > AJASubParserPair
Definition: commandline.h:167
AJACommandLineOption::Desc
std::string Desc() const
Definition: commandline.cpp:91
AJACommandLineParser::Clear
void Clear()
Definition: commandline.cpp:209
kSingleDash
static const char kSingleDash
Definition: commandline.cpp:15
AJACommandLineOption::Reset
void Reset()
Definition: commandline.cpp:140
AJAVariant
A simple Variant class.
Definition: variant.h:39
kShortOptionsAsLong
@ kShortOptionsAsLong
Definition: commandline.h:170
AJACommandLineParser::Parse
bool Parse(const AJAStringList &args)
Definition: commandline.cpp:311
AJACommandLineParser
Definition: commandline.h:179
AJACommandLineParser::ValueString
std::string ValueString(const std::string &name, size_t index=0) const
Definition: commandline.cpp:501
AJACommandLineParser::AJACommandLineParser
AJACommandLineParser(int flags=0)
Definition: commandline.cpp:155
kNoDefaultHelpOption
@ kNoDefaultHelpOption
Definition: commandline.h:171
AJACommandLineParser::CommandName
std::string CommandName()
Definition: commandline.cpp:802
AJACommandLineOption::MarkSet
void MarkSet(bool isSet=true)
Definition: commandline.cpp:150
file_io.h
Declares the AJAFileIO class.
AJACommandLineOption::HaveName
bool HaveName(const std::string &name) const
Definition: commandline.cpp:80
false
#define false
Definition: ntv2devicefeatures.h:25
common.h
Private include file for all ajabase sources.
true
#define true
Definition: ntv2devicefeatures.h:26
AJACommandLineOption::Value
std::string Value(size_t index=0) const
Definition: commandline.cpp:127
AJACommandLineParser::UsageText
std::string UsageText()
Definition: commandline.cpp:625
AJACommandLineParser::HaveOption
bool HaveOption(const std::string &name) const
Definition: commandline.cpp:260
AJACommandLineParser::AddOptions
bool AddOptions(const std::vector< AJACommandLineOption > &options)
Definition: commandline.cpp:563
aja::starts_with
bool starts_with(const std::string &str, const std::string &needle)
Definition: common.cpp:61
kErrorOnUnknownArgs
@ kErrorOnUnknownArgs
Definition: commandline.h:173
AJACommandLineParser::AddUsageOption
bool AddUsageOption(bool useShortName=false)
Definition: commandline.cpp:590
AJACommandLineOption::AddName
bool AddName(const std::string &name)
Definition: commandline.cpp:59
AJACommandLineParser::Dump
void Dump()
Definition: commandline.cpp:231
AJACommandLineParser::SetUsageText
void SetUsageText(const std::string &usageText)
Definition: commandline.cpp:613
AJACommandLineOption::Names
AJAStringList Names() const
Definition: commandline.cpp:75
AJACommandLineParser::HelpText
std::string HelpText()
Definition: commandline.cpp:655
SubParserMapConstIter
SubParserMap::const_iterator SubParserMapConstIter
Definition: commandline.h:166
AJACommandLineParser::IsSet
bool IsSet(const std::string &name) const
Definition: commandline.cpp:467
AJACommandLineOptionList
std::vector< AJACommandLineOption > AJACommandLineOptionList
Definition: commandline.h:161