Open Lighting Architecture  0.9.3
 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 DisplayUsageAndExit();
98 
102 void DisplayVersion();
103 
112 void ParseFlags(int *argc, char **argv);
113 } // namespace ola
114 
115 // DECLARE_*
116 
121 #define DECLARE_bool(name) \
122  DECLARE_flag(bool, name)
123 
128 #define DECLARE_int8(name) \
129  DECLARE_flag(int8_t, name)
130 
135 #define DECLARE_int16(name) \
136  DECLARE_flag(int16_t, name)
137 
142 #define DECLARE_int32(name) \
143  DECLARE_flag(int32_t, name)
144 
149 #define DECLARE_uint8(name) \
150  DECLARE_flag(uint8_t, name)
151 
156 #define DECLARE_uint16(name) \
157  DECLARE_flag(uint16_t, name)
158 
163 #define DECLARE_uint32(name) \
164  DECLARE_flag(uint32_t, name)
165 
170 #define DECLARE_string(name) \
171  DECLARE_flag(std::string, name)
172 
173 // DEFINE_*
174 
189 #define DEFINE_bool(name, default_value, help_str) \
190  DEFINE_flag(bool, name, \0, default_value, help_str, true)
191 
207 #define DEFINE_s_bool(name, short_opt, default_value, help_str) \
208  DEFINE_flag_with_short(bool, name, short_opt, default_value, help_str, true)
209 
221 #define DEFINE_default_bool(name, default_value, help_str) \
222  DEFINE_flag(bool, name, \0, default_value, help_str, false)
223 
237 #define DEFINE_s_default_bool(name, short_opt, default_value, help_str) \
238  DEFINE_flag_with_short(bool, name, short_opt, default_value, help_str, false)
239 
247 #define DEFINE_int8(name, default_value, help_str) \
248  DEFINE_flag(int8_t, name, \0, default_value, help_str, true)
249 
258 #define DEFINE_s_int8(name, short_opt, default_value, help_str) \
259  DEFINE_flag_with_short(int8_t, name, short_opt, default_value, help_str, \
260  true)
261 
269 #define DEFINE_uint8(name, default_value, help_str) \
270  DEFINE_flag(uint8_t, name, \0, default_value, help_str, true)
271 
280 #define DEFINE_s_uint8(name, short_opt, default_value, help_str) \
281  DEFINE_flag_with_short(uint8_t, name, short_opt, default_value, help_str, \
282  true)
283 
291 #define DEFINE_int16(name, default_value, help_str) \
292  DEFINE_flag(int16_t, name, \0, default_value, help_str, true)
293 
302 #define DEFINE_s_int16(name, short_opt, default_value, help_str) \
303  DEFINE_flag_with_short(int16_t, name, short_opt, default_value, help_str, \
304  true)
305 
306 
314 #define DEFINE_uint16(name, default_value, help_str) \
315  DEFINE_flag(uint16_t, name, \0, default_value, help_str, true)
316 
325 #define DEFINE_s_uint16(name, short_opt, default_value, help_str) \
326  DEFINE_flag_with_short(uint16_t, name, short_opt, default_value, help_str, \
327  true)
328 
336 #define DEFINE_int32(name, default_value, help_str) \
337  DEFINE_flag(int32_t, name, \0, default_value, help_str, true)
338 
347 #define DEFINE_s_int32(name, short_opt, default_value, help_str) \
348  DEFINE_flag_with_short(int32_t, name, short_opt, default_value, help_str, \
349  true)
350 
358 #define DEFINE_uint32(name, default_value, help_str) \
359  DEFINE_flag(uint32_t, name, \0, default_value, help_str, true)
360 
369 #define DEFINE_s_uint32(name, short_opt, default_value, help_str) \
370  DEFINE_flag_with_short(uint32_t, name, short_opt, default_value, help_str, \
371  true)
372 
380 #define DEFINE_string(name, default_value, help_str) \
381  DEFINE_flag(std::string, name, \0, default_value, help_str, true)
382 
391 #define DEFINE_s_string(name, short_opt, default_value, help_str) \
392  DEFINE_flag_with_short(std::string, name, short_opt, default_value, \
393  help_str, true)
394 
397 #endif // INCLUDE_OLA_BASE_FLAGS_H_