clockUtils  1.1
ArgumentParser.h
Go to the documentation of this file.
1 /*
2  * clockUtils
3  * Copyright (2015) Michael Baer, Daniel Bonrath, All rights reserved.
4  *
5  * This file is part of clockUtils; clockUtils is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
25 #ifndef __CLOCKUTILS_ARGPARSER_ARGUMENTPARSER_H__
26 #define __CLOCKUTILS_ARGPARSER_ARGUMENTPARSER_H__
27 
29 
30 #include <algorithm>
31 
35 
40 #define PARSE_ARGUMENTS(buffer, length)\
41  clockUtils::argParser::Parser::parseArguments(buffer, length)
42 
48 #define PARSE_COMMANDLINE()\
49  clockUtils::argParser::Parser::parseArguments(++argv, --argc)
50 
54 #define GETLASTPARSERERROR()\
55  clockUtils::argParser::Parser::getLastParserError()
56 
63 #define REGISTER_VARIABLE_INTERNAL(type, longname, shortname, value, description, required, multiple)\
64  {\
65  std::string helpText = std::string("\t--") + std::string(#longname);\
66  if (std::string(#shortname) != "\"\"") {\
67  helpText += std::string(", -") + std::string(#shortname);\
68  }\
69  size_t length = helpText.length();\
70  for (; length < 16; length++) {\
71  helpText += " ";\
72  }\
73  helpText += std::string("[Default: ") + std::string(#value) + std::string("]");\
74  helpText += std::string(std::max(0, int(15 - std::string(#value).length())), ' ');\
75  helpText += std::string(description);\
76  if (required) {\
77  helpText += " (required)";\
78  }\
79  if (multiple) {\
80  helpText += " (multiple)";\
81  }\
82  clockUtils::argParser::Parser::addHelpTextLine(std::make_pair(#longname, helpText));\
83  }\
84  clockUtils::argParser::Variable<type> longname(#longname, #shortname, description, value, required, multiple)
85 
92 #define REGISTER_VARIABLE(type, longname, shortname, value, description) REGISTER_VARIABLE_INTERNAL(type, longname, shortname, value, description, false, false)
93 
101 #define REGISTER_VARIABLE_REQUIRED(type, longname, shortname, value, description) REGISTER_VARIABLE_INTERNAL(type, longname, shortname, value, description, true, false)
102 
110 #define REGISTER_VARIABLE_MULTIPLE(type, longname, shortname, value, description) REGISTER_VARIABLE_INTERNAL(type, longname, shortname, value, description, false, true)
111 
120 #define REGISTER_VARIABLE_MULTIPLE_REQUIRED(type, longname, shortname, value, description) REGISTER_VARIABLE_INTERNAL(type, longname, shortname, value, description, true, true)
121 
125 #define REGISTER_VARIABLE_ARGUMENTS(name)\
126  clockUtils::argParser::ArgumentList name;
127 
131 #define HELPSET()\
132  clockUtils::argParser::Parser::wasHelpSet()
133 
137 #define GETHELPTEXT()\
138  clockUtils::argParser::Parser::getHelpText()
139 
140 #endif /* __CLOCKUTILS_ARGPARSER_ARGUMENTPARSER_H__ */
141