16 m_nCurrentArgument(0) {
23 while(! m_vecArguments.empty()) {
24 delete m_vecArguments.back();
25 m_vecArguments.pop_back();
33 for(
size_t i = 0; i < m_vecArguments.size(); ++i) {
34 c_log <<
"-" << m_vecArguments[i]->ShortOption <<
"|"
35 <<
"--" << m_vecArguments[i]->LongOption;
36 if(!m_vecArguments[i]->IsFlag) {
40 << m_vecArguments[i]->Description
54 m_nCurrentArgument = 1;
56 while(m_nCurrentArgument < n_argc) {
64 pchCurrentArg = ppch_argv[m_nCurrentArgument];
65 unArgLength = ::strlen(pchCurrentArg);
66 if(ppch_argv[m_nCurrentArgument][0] !=
'-' ||
72 if(pchCurrentArg[1] ==
'-') {
76 ParseLongOption(n_argc, ppch_argv);
85 if(unArgLength == 2) {
87 ParseShortOption(n_argc, ppch_argv);
91 ParseShortOptions(n_argc, ppch_argv);
103 void CCommandLineArgParser::ParseLongOption(
SInt32 n_argc,
106 std::string strArg(ppch_argv[m_nCurrentArgument]+2);
109 for(
size_t i = 0; i < m_vecArguments.size(); ++i) {
110 if(m_vecArguments[i]->LongOption == strArg) {
112 if(m_vecArguments[i]->IsFlag) {
114 m_vecArguments[i]->Parse(
"true");
118 ++m_nCurrentArgument;
119 if(m_nCurrentArgument == n_argc) {
122 m_vecArguments[i]->Parse(ppch_argv[m_nCurrentArgument]);
129 catch(CARGoSException& ex) {
140 void CCommandLineArgParser::ParseShortOption(
SInt32 n_argc,
143 char strArg(ppch_argv[m_nCurrentArgument][1]);
146 for(
size_t i = 0; i < m_vecArguments.size(); ++i) {
147 if(m_vecArguments[i]->ShortOption == strArg) {
149 if(m_vecArguments[i]->IsFlag) {
151 m_vecArguments[i]->Parse(
"true");
155 ++m_nCurrentArgument;
156 if(m_nCurrentArgument == n_argc) {
159 m_vecArguments[i]->Parse(ppch_argv[m_nCurrentArgument]);
166 catch(CARGoSException& ex) {
177 void CCommandLineArgParser::ParseShortOptions(
SInt32 n_argc,
180 std::string strArg(ppch_argv[m_nCurrentArgument]+1);
182 for(
size_t o = 0; o < strArg.length(); ++o) {
187 while(i < m_vecArguments.size() && !bFound) {
188 if(m_vecArguments[i]->ShortOption == strArg[o]) {
190 if(m_vecArguments[i]->IsFlag) {
192 m_vecArguments[i]->Parse(
"true");
196 if(o < strArg.length()-1) {
200 ++m_nCurrentArgument;
201 m_vecArguments[i]->Parse(ppch_argv[m_nCurrentArgument]);
213 catch(CARGoSException& ex) {
#define THROW_ARGOSEXCEPTION_NESTED(message, nested)
This macro throws an ARGoS exception with the passed message and nesting the passed exception.
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
signed int SInt32
32-bit signed integer.
The namespace containing all the ARGoS related code.
virtual void PrintUsage(CARGoSLog &c_log)
Prints the arguments on the log.
virtual void Parse(SInt32 n_argc, char **ppch_argv)
Parses the arguments on the command line.
virtual ~CCommandLineArgParser()
Class destructor.
CCommandLineArgParser()
Class constructor.