Open Lighting Architecture  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Flags.h
Go to the documentation of this file.
1 /*
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  *
7  * This library is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10  * Lesser General Public License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with this library; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  *
16  * Flags.h
17  * Command line flag (option) handling.
18  * Copyright (C) 2013 Simon Newton
19  */
20 
71 #ifndef INCLUDE_OLA_BASE_FLAGS_H_
72 #define INCLUDE_OLA_BASE_FLAGS_H_
73 
74 #include <getopt.h>
75 #include <ola/base/FlagsPrivate.h>
76 #include <string>
77 
78 namespace ola {
79 
86 void SetHelpString(const std::string &first_line,
87  const std::string &description);
88 
92 void DisplayUsage();
93 
97 void DisplayVersion();
98 
107 void ParseFlags(int *argc, char **argv);
108 } // namespace ola
109 
110 // DECLARE_*
111 
116 #define DECLARE_bool(name) \
117  DECLARE_flag(bool, name)
118 
123 #define DECLARE_int8(name) \
124  DECLARE_flag(int8_t, name)
125 
130 #define DECLARE_int16(name) \
131  DECLARE_flag(int16_t, name)
132 
137 #define DECLARE_int32(name) \
138  DECLARE_flag(int32_t, name)
139 
144 #define DECLARE_uint8(name) \
145  DECLARE_flag(uint8_t, name)
146 
151 #define DECLARE_uint16(name) \
152  DECLARE_flag(uint16_t, name)
153 
158 #define DECLARE_uint32(name) \
159  DECLARE_flag(uint32_t, name)
160 
165 #define DECLARE_string(name) \
166  DECLARE_flag(std::string, name)
167 
168 // DEFINE_*
169 
178 #define DEFINE_bool(name, default_value, help_str) \
179  DEFINE_flag(bool, name, \0, default_value, help_str)
180 
190 #define DEFINE_s_bool(name, short_opt, default_value, help_str) \
191  DEFINE_flag_with_short(bool, name, short_opt, default_value, help_str)
192 
200 #define DEFINE_int8(name, default_value, help_str) \
201  DEFINE_flag(int8_t, name, \0, default_value, help_str)
202 
211 #define DEFINE_s_int8(name, short_opt, default_value, help_str) \
212  DEFINE_flag_with_short(int8_t, name, short_opt, default_value, help_str)
213 
221 #define DEFINE_uint8(name, default_value, help_str) \
222  DEFINE_flag(uint8_t, name, \0, default_value, help_str)
223 
232 #define DEFINE_s_uint8(name, short_opt, default_value, help_str) \
233  DEFINE_flag_with_short(uint8_t, name, short_opt, default_value, help_str)
234 
242 #define DEFINE_int16(name, default_value, help_str) \
243  DEFINE_flag(int16_t, name, \0, default_value, help_str)
244 
253 #define DEFINE_s_int16(name, short_opt, default_value, help_str) \
254  DEFINE_flag_with_short(int16_t, name, short_opt, default_value, help_str)
255 
256 
264 #define DEFINE_uint16(name, default_value, help_str) \
265  DEFINE_flag(uint16_t, name, \0, default_value, help_str)
266 
275 #define DEFINE_s_uint16(name, short_opt, default_value, help_str) \
276  DEFINE_flag_with_short(uint16_t, name, short_opt, default_value, help_str)
277 
285 #define DEFINE_int32(name, default_value, help_str) \
286  DEFINE_flag(int32_t, name, \0, default_value, help_str)
287 
296 #define DEFINE_s_int32(name, short_opt, default_value, help_str) \
297  DEFINE_flag_with_short(int32_t, name, short_opt, default_value, help_str)
298 
306 #define DEFINE_uint32(name, default_value, help_str) \
307  DEFINE_flag(uint32_t, name, \0, default_value, help_str)
308 
317 #define DEFINE_s_uint32(name, short_opt, default_value, help_str) \
318  DEFINE_flag_with_short(uint32_t, name, short_opt, default_value, help_str)
319 
327 #define DEFINE_string(name, default_value, help_str) \
328  DEFINE_flag(std::string, name, \0, default_value, help_str)
329 
338 #define DEFINE_s_string(name, short_opt, default_value, help_str) \
339  DEFINE_flag_with_short(std::string, name, short_opt, default_value, help_str)
340 
343 #endif // INCLUDE_OLA_BASE_FLAGS_H_