You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CommandLineOption.cpp 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // Created by robin on 8/8/15.
  3. //
  4. #include "CommandLineOption.h"
  5. CommandLineOption::CommandLineOption(CommandLineParser* parser, const std::string &longName, char shortName,
  6. const std::string &description, const std::string &valueName,
  7. const std::string &defaultValue)
  8. : _longName(longName)
  9. , _shortName(shortName)
  10. , _description(description)
  11. , _valueName(valueName)
  12. , _defaultValue(defaultValue)
  13. , _isSet(false)
  14. {
  15. parser->addOption(this);
  16. }
  17. const std::string &CommandLineOption::getLongName() const
  18. {
  19. return _longName;
  20. }
  21. void CommandLineOption::setLongName(const std::string &longName)
  22. {
  23. _longName = longName;
  24. }
  25. char CommandLineOption::getShortName() const
  26. {
  27. return _shortName;
  28. }
  29. void CommandLineOption::setShortName(char shortName)
  30. {
  31. _shortName = shortName;
  32. }
  33. const std::string &CommandLineOption::getDescription() const
  34. {
  35. return _description;
  36. }
  37. void CommandLineOption::setDescription(const std::string &description)
  38. {
  39. _description = description;
  40. }
  41. const std::string &CommandLineOption::getValueName() const
  42. {
  43. return _valueName;
  44. }
  45. void CommandLineOption::setValueName(const std::string &valueName)
  46. {
  47. _valueName = valueName;
  48. }
  49. const std::string &CommandLineOption::getDefaultValue() const
  50. {
  51. return _defaultValue;
  52. }
  53. void CommandLineOption::setDefaultValue(const std::string &defaultValue)
  54. {
  55. _defaultValue = defaultValue;
  56. }
  57. const std::vector<std::string> &CommandLineOption::getValues() const
  58. {
  59. return _values;
  60. }
  61. void CommandLineOption::addValue(const std::string &value)
  62. {
  63. _values.push_back(value);
  64. }
  65. bool CommandLineOption::isSet() const
  66. {
  67. return _isSet;
  68. }
  69. void CommandLineOption::setIsSet(bool isSet)
  70. {
  71. _isSet = isSet;
  72. }
  73. bool CommandLineOption::hasValue() const
  74. {
  75. return !_valueName.empty();
  76. }
  77. const std::string &CommandLineOption::getValue() const
  78. {
  79. if (_values.empty())
  80. return _defaultValue;
  81. return _values[_values.size() - 1];
  82. }