AJA NTV2 SDK  17.6.0.2675
NTV2 SDK 17.6.0.2675
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  _subParsers.clear();
207  _options.clear();
208 }
209 
210 void AJACommandLineParser::Reset(bool clearAll)
211 {
212  if (clearAll) {
213  Clear();
214  } else {
215  for (auto &sp : _subParsers) {
216  if (sp.second) {
217  sp.second->Reset();
218  }
219  }
220  for (auto &opt : _options) {
221  opt.Reset();
222  }
223  }
224 }
225 
227 {
228  if (!_commandName.empty()) {
229  AJACommandLineParser *sp = _subParsers.at(_commandName);
230  if (sp != NULL) {
231  return sp->Dump();
232  }
233  } else {
234  for (AJACommandLineOptionListIter iter = _options.begin();
235  iter != _options.end(); ++iter) {
236  const AJACommandLineOption &o = *iter;
237  const AJAStringList & names = o.Names();
238  std::ostringstream oss;
239  oss << "[";
240  std::string name;
241  size_t count = 0;
242  for (AJAStringListConstIter sIter = names.begin(); sIter != names.end(); ++sIter) {
243  name = *sIter;
244  oss << name;
245  if (++count < names.size()) {
246  oss << ", ";
247  }
248  }
249  oss << "] " << "set? " << (IsSet(name) ? "true" : "false") << " value = " << o.Value();
250  std::cout << oss.str() << std::endl;
251  }
252  }
253 }
254 
255 bool AJACommandLineParser::HaveOption(const std::string &name) const
256 {
257  for (const auto &opt : _options) {
258  for (const auto &n : opt.Names()) {
259  if (n == name) {
260  return true;
261  }
262  }
263  }
264  return false;
265 }
266 
267 bool AJACommandLineParser::HavePositionalArg(const std::string &name) const
268 {
269  for (const auto &arg : _positionalArgs) {
270  if (arg == name) {
271  return true;
272  }
273  }
274  return false;
275 }
276 
278 {
279  return _positionalArgs;
280 }
281 
282 bool AJACommandLineParser::OptionByName(const std::string &name, AJACommandLineOption &opt) const
283 {
284  for (const auto &o : _options) {
285  for (const auto &n : o.Names()) {
286  if (n == name) {
287  opt = o;
288  return true;
289  }
290  }
291  }
292  return false;
293 }
294 
296 {
297  const std::string &name = p->Name();
298  if (_subParsers.find(name) == _subParsers.end()) {
299  _subParsers.insert(AJASubParserPair(name, p));
300  return true;
301  }
302 
303  return false;
304 }
305 
307 {
308  AJAStringList::const_iterator iter = args.begin();
309  ++iter; // Skip exe path
310 
311  for (SubParserMap::iterator spIter = _subParsers.begin(); spIter != _subParsers.end(); ++spIter) {
312  // Is second arg a command name which belongs to a sub-parser?
313  if (*iter == spIter->first) {
314  _commandName = *iter;
315  }
316  // Iterate all args with all sub-parsers...
317  if (spIter->second != NULL) {
318  if (!spIter->second->Parse(args)) {
319  std::cerr << "Error parsing args with sub-parser: " << spIter->second->Name() << std::endl;
320  return false;
321  }
322  }
323  }
324 
325  // If the the parser name is set, expect the second arg to match (i.e. we are in a sub-parser).
326  // For example, the following case "name" would be "theCommand".
327  // If the second arg doesn't match the name, the sub-parser name is simply not present in the
328  // list of args provided. This is not an error condition.
329  // > MyApp.exe theCommand -d1 -n3 --verbose
330  if (!_name.empty() && *iter != _name) {
331  return true;
332  }
333 
334  // ...otherwise just parse the args.
335  bool havePositionalArgs = false;
336  for (; iter != args.end(); iter++) {
337  const std::string &arg = *iter;
338  // Treat subsequent args as "positional"
339  if (!havePositionalArgs && arg == kDoubleDash) {
340  havePositionalArgs = true;
341  continue;
342  }
343 
344  if (havePositionalArgs) {
345  _positionalArgs.push_back(arg);
346  continue;
347  }
348 
349  if (hasOptionPrefix(arg)) {
351  std::string optName;
352  std::string optValue;
353  std::string argStr;
354  bool doubleDash = aja::starts_with(arg, kDoubleDash);
355  bool singleDash = aja::starts_with(arg, kSingleDash) && !doubleDash;
356  if (doubleDash) {
357  argStr = arg.substr(2, arg.length());
358  } else if (singleDash) {
359  argStr = arg.substr(1, arg.length());
360  }
361  if (hasAssignmentOperator(argStr)) {
362  size_t assignPos = argStr.find_first_of(kAssignChar);
363  optName = argStr.substr(0, assignPos);
364  optValue = argStr.substr(assignPos+1, argStr.length());
365  } else {
366  // Single-dash cases we need to handle:
367  // example args: {a, apple}, {b, ball}, {c, cat}, {r, car}
368  // -a=1
369  // -a1
370  // -a 1
371  // -abc // SPECIAL CASE: short opts as long opts
372  // Should we even allow setting a value for a single-dash arg if the arg name is longer than 1 character?
373  // i.e. should -devicekona5 be legal? seems weird to me...
374  if (singleDash) { /* -argname */
375  /* handle single-dash option */
376  std::string subStr;
377  if (_flags & kShortOptionsAsLong) {
378  for (size_t c = 1; c < arg.length(); c++) {
379  subStr = arg.substr(c, 1);
380  if (HaveOption(subStr))
381  setOption(subStr, true);
382  }
383  continue;
384  } else {
385  for (size_t c = arg.length(); c > 1; c--) {
386  subStr = arg.substr(1, c-1);
387  if (HaveOption(subStr)) {
388  optName = subStr;
389  size_t count = (arg.length()-1)-optName.length();
390  optValue = arg.substr(optName.length()+1, count);
391  break;
392  } else if (_flags & kErrorOnUnknownArgs) {
393  std::cerr << "Unknown arg: " << subStr << std::endl;
394  return false;
395  }
396  }
397  }
398  } else { /* --argname */
399  optName = argStr;
400  }
401 
402  // If we have no value, and the next arg is not another arg, use it as the value for the current arg.
403  if (optValue.empty()) {
404  auto nextIter = iter;
405  nextIter++;
406  if (nextIter != args.end()) {
407  std::string nextArg = *(nextIter++);
408  if (!hasOptionPrefix(nextArg)) {
409  optValue = nextArg;
410  }
411  }
412  }
413  } // else no assignment operator
414 
415  if (HaveOption(optName)) {
416  if (!optValue.empty()) {
417  setOptionValue(optName, optValue);
418  }
419  setOption(optName, true);
420  } else if (_flags & kErrorOnUnknownArgs) {
421  std::cerr << "Unknown arg: " << optName << std::endl;
422  return false;
423  }
424  } // if hasOptionPrefix
425  } // for each arg
426 
427  if (!(_flags & kNoDefaultHelpOption))
428  if (IsSet("help"))
429  {std::cout << HelpText(); return false;}
430 
431  if (!(_flags & kNoDefaultUsageOption))
432  if (IsSet("usage"))
433  {std::cout << UsageText(); return false;}
434 
435  return true;
436 } // Parse (AJAStringList)
437 
438 bool AJACommandLineParser::Parse(int argc, const char *argv[])
439 {
440  if (argc == 0 || argv == NULL) {
441  return false;
442  }
443  AJAStringList argList;
444  for (int i = 0; i < argc; i++) {
445  argList.push_back(std::string(argv[i]));
446  }
447  return Parse(argList);
448 }
449 
450 bool AJACommandLineParser::Parse(int argc, char *argv[])
451 {
452  if (argc == 0 || argv == NULL) {
453  return false;
454  }
455  AJAStringList argList;
456  for (int i = 0; i < argc; i++) {
457  argList.push_back(std::string(argv[i]));
458  }
459  return Parse(argList);
460 }
461 
462 bool AJACommandLineParser::IsSet(const std::string &name) const
463 {
464  if (!_commandName.empty()) {
465  AJACommandLineParser *sp = _subParsers.at(_commandName);
466  if (sp != NULL) {
467  return sp->IsSet(name);
468  }
469  } else {
471  if (OptionByName(name, opt)) {
472  return opt.IsSet();
473  }
474  }
475  return false;
476 }
477 
478 AJAVariant AJACommandLineParser::Value(const std::string &name, size_t index) const
479 {
480  return AJAVariant(ValueString(name, index));
481 }
482 
483 AJAVariantList AJACommandLineParser::Values(const std::string &name) const
484 {
485  AJAStringList values = ValueStrings(name);
486  if (!values.empty()) {
487  AJAVariantList variants;
488  for (AJAStringListConstIter it = values.begin(); it != values.end(); ++it) {
489  variants.push_back(AJAVariant(*it));
490  }
491  return variants;
492  }
493  return AJAVariantList();
494 }
495 
496 std::string AJACommandLineParser::ValueString(const std::string &name, size_t index) const
497 {
498  std::string val;
499  if (!_commandName.empty()) {
500  AJACommandLineParser *sp = _subParsers.at(_commandName);
501  if (sp != NULL) {
502  return sp->ValueString(name, index);
503  }
504  } else {
506  if (OptionByName(name, opt)) {
507  val = opt.Value(index);
508  if (val.empty()) {
509  val = opt.DefaultValue();
510  }
511  }
512  }
513 
514  return val;
515 }
516 
517 AJAStringList AJACommandLineParser::ValueStrings(const std::string &name) const
518 {
519  if (!_commandName.empty()) {
520  AJACommandLineParser *sp = _subParsers.at(_commandName);
521  if (sp != NULL) {
522  return sp->ValueStrings(name);
523  }
524  } else {
526  if (OptionByName(name, opt)) {
527  return opt.Values();
528  }
529  }
530  return AJAStringList();
531 }
532 
534 {
535  bool exists = false;
536  const AJAStringList &wantNames = option.Names();
537  for (AJACommandLineOptionListIter optIter = _options.begin(); optIter != _options.end(); ++optIter) {
538  const AJAStringList &names = optIter->Names();
539  for (AJAStringListConstIter nameIter = names.begin(); nameIter != names.end(); ++nameIter) {
540  for (AJAStringListConstIter wantIter = wantNames.begin(); wantIter != wantNames.end(); ++wantIter) {
541  if (*wantIter == *nameIter) {
542  exists = true;
543  goto next;
544  }
545  }
546  }
547  }
548 
549 next:
550  if (exists) {
551  return false;
552  } else {
553  _options.push_back(option);
554  return true;
555  }
556 }
557 
559 {
560  size_t okCount = 0;
561  for (size_t i = 0; i < options.size(); i++) {
562  if (AddOption(options.at(i))) {
563  ++okCount;
564  }
565  }
566 // if (_Flags & kAutoProcessUsage)
567 // AddOption(AJACommandLineOption("usage", "Show command usage"));
568 // if (_Flags & (kAutoProcessHelp | kAutoProcessUsage))
569 // AddHelpOption();
570  return options.size() ? (okCount == options.size() ? true : false) : false;
571 }
572 
573 bool AJACommandLineParser::AddHelpOption(bool useShortName)
574 {
575  AJACommandLineOption helpOpt;
576  helpOpt.AddName("?");
577  if (useShortName) {
578  helpOpt.AddName("h");
579  }
580  helpOpt.AddName("help");
581  helpOpt.SetDesc("Print the help text");
582  return AddOption(helpOpt);
583 }
584 
586 {
587  AJACommandLineOption usageOpt;
588  usageOpt.AddName("usage");
589  if (useShortName) {
590  usageOpt.AddName("u");
591  }
592  usageOpt.SetDesc("Print the usage text");
593  return AddOption(usageOpt);
594 }
595 
596 std::string AJACommandLineParser::Name() const
597 {
598  if (!_commandName.empty()) {
599  AJACommandLineParser *sp = _subParsers.at(_commandName);
600  if (sp != NULL) {
601  return sp->Name();
602  }
603  }
604 
605  return _name;
606 }
607 
608 void AJACommandLineParser::SetUsageText(const std::string &usageText)
609 {
610  if (!_commandName.empty()) {
611  AJACommandLineParser *sp = _subParsers.at(_commandName);
612  if (sp != NULL) {
613  sp->SetUsageText(usageText);
614  }
615  } else {
616  _usageText = usageText;
617  }
618 }
619 
621 {
622  if (!_commandName.empty()) {
623  AJACommandLineParser *sp = _subParsers.at(_commandName);
624  if (sp != NULL) {
625  return sp->UsageText();
626  }
627  }
628 
629  std::string usageText;
630  if (!_usageText.empty()) {
631  usageText = _usageText;
632  } else {
633  usageText = generateUsageText();
634  }
635  return usageText;
636 }
637 
638 void AJACommandLineParser::SetHelpText(const std::string &helpText)
639 {
640  if (!_commandName.empty()) {
641  AJACommandLineParser *sp = _subParsers.at(_commandName);
642  if (sp != NULL) {
643  sp->SetHelpText(helpText);
644  }
645  } else {
646  _helpText = helpText;
647  }
648 }
649 
651 {
652  if (!_commandName.empty()) {
653  AJACommandLineParser *sp = _subParsers.at(_commandName);
654  if (sp != NULL) {
655  return sp->HelpText();
656  }
657  }
658 
659  std::string helpText;
660  if (_helpText.empty()) {
661  helpText = generateHelpText();
662  } else {
663  helpText = _helpText;
664  }
665  return helpText;
666 }
667 
668 std::string AJACommandLineParser::generateHelpText() const
669 {
670  std::ostringstream oss;
671  std::string exePath;
673  oss << "Usage: " << exePath;
674  if (!_name.empty()) {
675  oss << " " << _name;
676  }
677  oss << " [OPTION...]" << std::endl;
678 
679  // Get the longest line size first...
680  size_t longestSize = 0;
681  for (AJACommandLineOptionListIter it = _options.begin();
682  it != _options.end(); ++it) {
683  const AJAStringList &names = it->Names();
684  size_t namesLength = 0;
685  for (AJAStringListConstIter sIter = names.begin(); sIter != names.end(); ++sIter) {
686  const std::string &name = *sIter;
687  namesLength += name.length();
688  // add size of dashes
689  if (name.length() == 1) {
690  namesLength++;
691  } else {
692  namesLength += 2;
693  }
694  }
695  // add size of commas/spaces (i.e. ", ")
696  namesLength += ((names.size()*2)-2);
697  if (namesLength > longestSize) {
698  longestSize = namesLength;
699  }
700  }
701 
702  // ...now calculate all of the line padding.
703  for (AJACommandLineOptionListIter it = _options.begin();
704  it != _options.end(); ++it) {
705  oss << std::setw(2) << std::right;
706  const AJAStringList &names = it->Names();
707  size_t nameCount = 0;
708  size_t namesLength = 0;
709  for (AJAStringListConstIter sIter = names.begin(); sIter != names.end(); ++sIter) {
710  const std::string &name = *sIter;
711  namesLength += name.length();
712  if (name.length() == 1) {
713  oss << "-" << name;
714  namesLength++;
715  } else {
716  oss << "--" << name;
717  namesLength += 2;
718  }
719  if (++nameCount < names.size()) {
720  oss << ", ";
721  }
722  }
723  namesLength += ((names.size()*2)-2);
724  oss << std::setw((longestSize-namesLength) + it->Desc().length() + 8);
725  oss << it->Desc() << std::endl;
726  }
727 
728  return oss.str();
729 }
730 
731 std::string AJACommandLineParser::generateUsageText() const
732 {
733  std::ostringstream oss;
734  std::string exePath;
736  oss << "Usage: " << exePath;
737  if (!_name.empty()) {
738  oss << " " << _name;
739  }
740 
741  std::string abbrev;
742  std::ostringstream usages;
743  bool haveHelp = false;
744  bool haveUsage = false;
745  for (const auto &opt : _options) {
746  if (opt.HaveName("?")) {
747  haveHelp = true;
748  } else if (opt.HaveName("usage")) {
749  haveUsage = true;
750  } else {
751  auto names = opt.Names();
752  usages << "\t[";
753  for (size_t ndx = 0; ndx < names.size(); ndx++) {
754  auto name = names.at(ndx);
755  bool isShortName = name.length() == 1;
756  if (isShortName) {
757  abbrev += name;
758  usages << '-' << name;
759  } else {
760  usages << "--" << name;
761  }
762  if (ndx < names.size()-1) {
763  usages << '|';
764  }
765  }
766  usages << ']' << std::endl;
767  }
768  }
769 
770  // Make sure help and usage options appear at the end
771  if (haveHelp) {
772  usages << "\t[" << "-?|--help]" << std::endl;
773  }
774  if (haveUsage) {
775  usages << "\t[" << "--usage]" << std::endl;
776  }
777 
778  if (!abbrev.empty()) {
779  if (haveHelp) {
780  abbrev += '?';
781  }
782  oss << " [-" << abbrev << "]" << std::endl;
783  }
784  oss << usages.str() << std::endl;
785 
786  if (!_subParsers.empty()) {
787  oss << '\n' << "commands: " << std::endl;
788  for (const auto &sp : _subParsers) {
789  if (sp.second) {
790  oss << "\t " << sp.second->Name() << std::endl;
791  }
792  }
793  }
794  return oss.str();
795 }
796 
798 {
799  return _commandName;
800 }
801 
802 bool AJACommandLineParser::hasOptionPrefix(const std::string &name)
803 {
804  return aja::starts_with(name, kSingleDash);
805 }
806 
807 bool AJACommandLineParser::hasAssignmentOperator(const std::string &arg)
808 {
809  size_t assignPos = arg.find_first_of(kAssignChar);
810  return assignPos != std::string::npos;
811 }
812 
813 bool AJACommandLineParser::setOptionValue(const std::string &name, const std::string &value)
814 {
815  if (!value.empty()) {
816  for (size_t i = 0; i < _options.size(); i++) {
817  AJACommandLineOption opt = _options.at(i);
818  const AJAStringList &names = opt.Names();
819  for (AJAStringListConstIter iter = names.begin(); iter != names.end(); ++iter) {
820  if (name == *iter) {
821  _options[i].AddValue(value);
822  return true;
823  }
824  }
825  }
826  }
827  return false;
828 }
829 
830 bool AJACommandLineParser::setOption(const std::string &name, bool isSet)
831 {
832  for (size_t i = 0; i < _options.size(); i++) {
833  AJACommandLineOption opt = _options.at(i);
834  const AJAStringList &names = opt.Names();
835  for (AJAStringListConstIter iter = names.begin(); iter != names.end(); ++iter) {
836  if (name == *iter) {
837  _options[i].MarkSet(isSet);
838  return true;
839  }
840  }
841  }
842  return false;
843 }
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:210
AJACommandLineOption::SetDesc
void SetDesc(const std::string &desc)
Definition: commandline.cpp:96
AJACommandLineParser::AddOption
bool AddOption(const AJACommandLineOption &option)
Definition: commandline.cpp:533
AJACommandLineParser::AddHelpOption
bool AddHelpOption(bool useShortName=false)
Definition: commandline.cpp:573
AJACommandLineParser::Value
AJAVariant Value(const std::string &name, size_t index=0) const
Definition: commandline.cpp:478
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:517
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:267
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:277
AJACommandLineOption::IsSet
bool IsSet() const
Definition: commandline.cpp:146
AJACommandLineParser::SetHelpText
void SetHelpText(const std::string &helpText)
Definition: commandline.cpp:638
AJACommandLineParser::OptionByName
bool OptionByName(const std::string &name, AJACommandLineOption &opt) const
Definition: commandline.cpp:282
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:483
AJAStringListConstIter
AJAStringList::const_iterator AJAStringListConstIter
Definition: commandline.h:19
AJACommandLineParser::AddSubParser
bool AddSubParser(AJACommandLineParser *sp)
Definition: commandline.cpp:295
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:596
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:204
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:306
AJACommandLineParser
Definition: commandline.h:179
AJACommandLineParser::ValueString
std::string ValueString(const std::string &name, size_t index=0) const
Definition: commandline.cpp:496
AJACommandLineParser::AJACommandLineParser
AJACommandLineParser(int flags=0)
Definition: commandline.cpp:155
kNoDefaultHelpOption
@ kNoDefaultHelpOption
Definition: commandline.h:171
AJACommandLineParser::CommandName
std::string CommandName()
Definition: commandline.cpp:797
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:620
AJACommandLineParser::HaveOption
bool HaveOption(const std::string &name) const
Definition: commandline.cpp:255
AJACommandLineParser::AddOptions
bool AddOptions(const std::vector< AJACommandLineOption > &options)
Definition: commandline.cpp:558
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:585
AJACommandLineOption::AddName
bool AddName(const std::string &name)
Definition: commandline.cpp:59
AJACommandLineParser::Dump
void Dump()
Definition: commandline.cpp:226
AJACommandLineParser::SetUsageText
void SetUsageText(const std::string &usageText)
Definition: commandline.cpp:608
AJACommandLineOption::Names
AJAStringList Names() const
Definition: commandline.cpp:75
AJACommandLineParser::HelpText
std::string HelpText()
Definition: commandline.cpp:650
SubParserMapConstIter
SubParserMap::const_iterator SubParserMapConstIter
Definition: commandline.h:166
AJACommandLineParser::IsSet
bool IsSet(const std::string &name) const
Definition: commandline.cpp:462
AJACommandLineOptionList
std::vector< AJACommandLineOption > AJACommandLineOptionList
Definition: commandline.h:161