00001
00002
00003
00004
00005
00006
00007
00008
00009 static const char rcsid[] __attribute__((used)) = "$Id: CommandLineOption.cpp 1230 2014-11-16 02:32:01Z sella $";
00010
00011 #include "CommandLineOption.h"
00012
00013 #include <stdio.h>
00014
00015 #include <string>
00016
00017 using namespace sella::util;
00018
00019 CommandLineOption::CommandLineOption(char opt, const std::string &option, const std::string &usage, const std::string &label, const std::string &value) throw () :
00020 opt(opt),
00021 option(option),
00022
00023 usage(usage),
00024 value(value),
00025
00026 argumented(label.size() > 0)
00027 {
00028 char buffer[1024];
00029
00030 if (((opt >= 'a') && (opt <= 'z')) || ((opt >= 'A') && (opt <= 'Z')) || ((opt >= '0') && (opt <= '9'))) {
00031 if (this->argumented) {
00032 snprintf(buffer, sizeof(buffer), " -%c,--%s=%s", opt, option.c_str(), label.c_str());
00033 } else {
00034 snprintf(buffer, sizeof(buffer), " -%c,--%s", opt, option.c_str());
00035 }
00036 } else {
00037 if (this->argumented) {
00038 snprintf(buffer, sizeof(buffer), " --%s=%s", option.c_str(), label.c_str());
00039 } else {
00040 snprintf(buffer, sizeof(buffer), " --%s", option.c_str());
00041 }
00042 }
00043 this->tags = buffer;
00044 }
00045
00046 CommandLineOption::CommandLineOption() throw () :
00047 opt(),
00048 option(),
00049
00050 usage(),
00051 value(),
00052
00053 tags(),
00054
00055 argumented(false)
00056 { }
00057
00058 CommandLineOption::CommandLineOption(const CommandLineOption ©) throw () :
00059 opt(copy.getOpt()),
00060 option(copy.getOption()),
00061
00062 usage(copy.getUsage()),
00063 value(copy.getValue()),
00064
00065 tags(copy.getTags()),
00066
00067 argumented(copy.getArgumented())
00068 { }
00069
00070 CommandLineOption::~CommandLineOption() throw () {
00071 this->option.clear();
00072 this->usage.clear();
00073 this->value.clear();
00074 this->tags.clear();
00075 }
00076
00077 CommandLineOption & CommandLineOption::operator = (const CommandLineOption &other) throw () {
00078 if (this != &other) {
00079 this->setOpt(other.getOpt());
00080 this->setOption(other.getOption());
00081
00082 this->setUsage(other.getUsage());
00083 this->setValue(other.getValue());
00084
00085 this->setTags(other.getTags());
00086
00087 this->setArgumented(other.getArgumented());
00088 }
00089 return *this;
00090 }
00091
00092 void CommandLineOption::setOpt(char opt) throw () {
00093 this->opt = opt;
00094 }
00095
00096 void CommandLineOption::setOption(const std::string &option) throw () {
00097 this->option = option;
00098 }
00099
00100 void CommandLineOption::setUsage(const std::string &usage) throw () {
00101 this->usage = usage;
00102 }
00103
00104 void CommandLineOption::setValue(const std::string &value) throw () {
00105 this->value = value;
00106 }
00107
00108 void CommandLineOption::setTags(const std::string &tags) throw () {
00109 this->tags = tags;
00110 }
00111
00112 void CommandLineOption::setArgumented(bool value) throw () {
00113 this->argumented = value;
00114 }
00115
00116 char CommandLineOption::getOpt() const throw () {
00117 return this->opt;
00118 }
00119
00120 const std::string & CommandLineOption::getOption() const throw () {
00121 return this->option;
00122 }
00123
00124 const std::string & CommandLineOption::getUsage() const throw () {
00125 return this->usage;
00126 }
00127
00128 const std::string & CommandLineOption::getValue() const throw () {
00129 return this->value;
00130 }
00131
00132 const std::string & CommandLineOption::getTags() const throw () {
00133 return this->tags;
00134 }
00135
00136 bool CommandLineOption::getArgumented() const throw () {
00137 return this->argumented;
00138 }
00139
00140
00141
00142