Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

CommandLineOption.cpp 1.9KB

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