Geogram Version 1.8.5
A programming library of geometric algorithms
Loading...
Searching...
No Matches
command_line.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2000-2022 Inria
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the ALICE Project-Team nor the names of its
14 * contributors may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Contact: Bruno Levy
30 *
31 * https://www.inria.fr/fr/bruno-levy
32 *
33 * Inria,
34 * Domaine de Voluceau,
35 * 78150 Le Chesnay - Rocquencourt
36 * FRANCE
37 *
38 */
39
40#ifndef GEOGRAM_BASIC_COMMAND_LINE
41#define GEOGRAM_BASIC_COMMAND_LINE
42
47
53namespace GEO {
54
60 namespace CmdLine {
61
69 void GEOGRAM_API initialize();
70
78 void GEOGRAM_API terminate();
79
80
91 void GEOGRAM_API set_config_file_name(
92 const std::string& filename,
93 bool auto_create_args = false
94 );
95
104 bool GEOGRAM_API config_file_loaded();
105
112 std::string GEOGRAM_API get_config_file_name();
113
121 void GEOGRAM_API load_config(
122 const std::string& filename, const std::string& program_name
123 );
124
142
152
173 void GEOGRAM_API declare_arg_group(
174 const std::string& name,
175 const std::string& description,
177 );
178
198 void GEOGRAM_API declare_arg(
199 const std::string& name,
200 ArgType type,
201 const std::string& default_value,
202 const std::string& description,
204 );
205
212 ArgType GEOGRAM_API get_arg_type(const std::string& name);
213
220 bool GEOGRAM_API arg_is_declared(const std::string& name);
221
229 inline void declare_arg(
230 const std::string& name,
231 const std::string& default_value,
232 const std::string& description,
234 ) {
236 name, ARG_STRING, default_value,
237 description, flags
238 );
239 }
240
248 inline void declare_arg(
249 const std::string& name,
250 const char* default_value,
251 const std::string& description,
253 ) {
255 name, ARG_STRING, default_value,
256 description, flags
257 );
258 }
259
267 inline void declare_arg(
268 const std::string& name,
269 int default_value,
270 const std::string& description,
272 ) {
274 name, ARG_INT, String::to_string(default_value),
275 description, flags
276 );
277 }
278
286 inline void declare_arg(
287 const std::string& name,
288 double default_value,
289 const std::string& description,
291 ) {
293 name, ARG_DOUBLE, String::to_string(default_value),
294 description, flags
295 );
296 }
297
305 inline void declare_arg(
306 const std::string& name,
307 bool default_value,
308 const std::string& description,
310 ) {
312 name, ARG_BOOL, default_value ? "true" : "false",
313 description, flags
314 );
315 }
316
327 const std::string& name,
328 double default_value,
329 const std::string& description = "...",
331 ) {
333 name, ARG_PERCENT, String::to_string(default_value) + "%",
334 description, flags
335 );
336 }
337
376 bool GEOGRAM_API parse(
377 int argc, char** argv, std::vector<std::string>& unparsed_args,
378 const std::string& additional_arg_specs = ""
379 );
380
390 bool GEOGRAM_API parse(
391 int argc, char** argv
392 );
393
399 int GEOGRAM_API argc();
400
401
402 typedef char** charptrptr; // Need to do that else the compiler thinks
403 // that GEOGRAM_API qualifies the ptr instead
404 // of the function.
405
412 charptrptr GEOGRAM_API argv();
413
426 void GEOGRAM_API show_usage(
427 const std::string& additional_args = "",
428 bool advanced = false
429 );
430
438 std::string GEOGRAM_API get_arg(const std::string& name);
439
450 int GEOGRAM_API get_arg_int(const std::string& name);
451
462 unsigned int GEOGRAM_API get_arg_uint(const std::string& name);
463
474 double GEOGRAM_API get_arg_double(const std::string& name);
475
494 double GEOGRAM_API get_arg_percent(
495 const std::string& name, double reference
496 );
497
508 bool GEOGRAM_API get_arg_bool(const std::string& name);
509
522 bool GEOGRAM_API set_arg(
523 const std::string& name, const std::string& value
524 );
525
538 inline bool set_arg(const std::string& name, const char* value) {
539 return set_arg(name, std::string(value));
540 }
541
552 void GEOGRAM_API set_arg(const std::string& name, Numeric::int32 value);
553
554 /*
555 * \brief Sets an argument value from an integer
556 * \details This replaces the value of argument \p name by the given
557 * integer \p value. If the declared type of the argument is not
558 * compatible with an integer then the function aborts (compatible
559 * argument types are: int, double or string). If the argument does
560 * not exist, it is added as a new argument of undefined type.
561 * \param[in] name the argument name
562 * \param[in] value the new value as an integer
563 */
564 void GEOGRAM_API set_arg(const std::string& name, Numeric::uint32 value);
565
566 /*
567 * \brief Sets an argument value from an integer
568 * \details This replaces the value of argument \p name by the given
569 * integer \p value. If the declared type of the argument is not
570 * compatible with an integer then the function aborts (compatible
571 * argument types are: int, double or string). If the argument does
572 * not exist, it is added as a new argument of undefined type.
573 * \param[in] name the argument name
574 * \param[in] value the new value as an integer
575 */
576 void GEOGRAM_API set_arg(const std::string& name, Numeric::int64 value);
577
578 /*
579 * \brief Sets an argument value from an integer
580 * \details This replaces the value of argument \p name by the given
581 * integer \p value. If the declared type of the argument is not
582 * compatible with an integer then the function aborts (compatible
583 * argument types are: int, double or string). If the argument does
584 * not exist, it is added as a new argument of undefined type.
585 * \param[in] name the argument name
586 * \param[in] value the new value as an integer
587 */
588 void GEOGRAM_API set_arg(const std::string& name, Numeric::uint64 value);
589
600 void GEOGRAM_API set_arg(const std::string& name, double value);
601
612 void GEOGRAM_API set_arg(const std::string& name, bool value);
613
626 void GEOGRAM_API set_arg_percent(const std::string& name, double value);
627
628 /********************************************************************/
629
636 void GEOGRAM_API get_args(std::vector<std::string>& args);
637
643
671 void GEOGRAM_API ui_separator(
672 const std::string& title,
673 const std::string& short_title = ""
674 );
675
689 void GEOGRAM_API ui_separator();
690
703 void GEOGRAM_API ui_close_separator();
704
723 void GEOGRAM_API ui_message(
724 const std::string& message,
725 index_t wrap_margin
726 );
727
736 void GEOGRAM_API ui_message(
737 const std::string& message
738 );
739
745 void GEOGRAM_API ui_clear_line();
746
768 void GEOGRAM_API ui_progress(
769 const std::string& task_name, index_t val,
770 index_t percent, bool clear = true
771 );
772
784 void GEOGRAM_API ui_progress_time(
785 const std::string& task_name,
786 double elapsed, bool clear = true
787 );
788
801 void GEOGRAM_API ui_progress_canceled(
802 const std::string& task_name,
803 double elapsed, index_t percent, bool clear = true
804 );
805
833 std::string GEOGRAM_API ui_feature(
834 const std::string& feature, bool show = true
835 );
836 }
837}
838
839
840#ifdef GEO_OS_ANDROID
841struct android_app;
842
843namespace GEO {
844 namespace CmdLine {
849 void GEOGRAM_API set_android_app(android_app* app);
850
855 android_app* GEOGRAM_API get_android_app();
856 }
857}
858
859#endif
860
861
862#endif
863
Assertion checking mechanism.
Common include file, providing basic definitions. Should be included before anything else by all head...
std::string ui_feature(const std::string &feature, bool show=true)
Formats a Logger feature name.
void load_config(const std::string &filename, const std::string &program_name)
Loads command line argument values from a file.
void ui_progress_canceled(const std::string &task_name, double elapsed, index_t percent, bool clear=true)
Displays the time elapsed for a canceled task.
bool config_file_loaded()
Tests whether the configuration file was loaded.
void show_usage(const std::string &additional_args="", bool advanced=false)
Displays program help.
void declare_arg(const std::string &name, ArgType type, const std::string &default_value, const std::string &description, ArgFlags flags=ARG_FLAGS_DEFAULT)
Declares an argument.
bool get_arg_bool(const std::string &name)
Gets an argument value as a boolean.
void declare_arg_percent(const std::string &name, double default_value, const std::string &description="...", ArgFlags flags=ARG_FLAGS_DEFAULT)
Declares an argument of type percentage.
int argc()
Gets the number of arguments of the command line.
std::string get_config_file_name()
Gets the name of the configuration file.
charptrptr argv()
Gets the command line arguments.
bool parse(int argc, char **argv, std::vector< std::string > &unparsed_args, const std::string &additional_arg_specs="")
Parses the command line arguments.
bool set_arg(const std::string &name, const std::string &value)
Sets an argument value from a string.
void ui_close_separator()
Closes an opened separator.
ArgFlags
Command line group or argument flags.
void ui_separator()
Outputs a separator without a title on the console.
double get_arg_percent(const std::string &name, double reference)
Gets an argument value as a percentage.
void initialize()
Initializes the command line framework.
void ui_clear_line()
Clears the last line.
index_t ui_terminal_width()
Gets the width of the console.
void ui_progress_time(const std::string &task_name, double elapsed, bool clear=true)
Displays the time elapsed for a completed task.
std::string get_arg(const std::string &name)
Gets an argument value.
bool arg_is_declared(const std::string &name)
Checks if an argument exists.
int get_arg_int(const std::string &name)
Gets an argument value as an integer.
double get_arg_double(const std::string &name)
Gets an argument value as a floating point.
void get_args(std::vector< std::string > &args)
Gets the value of all arguments.
ArgType get_arg_type(const std::string &name)
Gets the type of an argument.
ArgType
Command line argument types.
void declare_arg_group(const std::string &name, const std::string &description, ArgFlags flags=ARG_FLAGS_DEFAULT)
Declares an argument group.
void ui_progress(const std::string &task_name, index_t val, index_t percent, bool clear=true)
Displays a progress bar.
unsigned int get_arg_uint(const std::string &name)
Gets an argument value as an unsigned integer.
void ui_message(const std::string &message, index_t wrap_margin)
Outputs a message on the console.
void set_config_file_name(const std::string &filename, bool auto_create_args=false)
Defines the name of the configuration file.
void terminate()
Cleans up the command line framework.
void set_arg_percent(const std::string &name, double value)
Sets an argument value from a percentage.
uint64_t uint64
Definition numeric.h:99
int32_t int32
Definition numeric.h:84
uint32_t uint32
Definition numeric.h:96
int64_t int64
Definition numeric.h:87
Global Vorpaline namespace.
Definition algorithm.h:64
geo_index_t index_t
The type for storing and manipulating indices.
Definition numeric.h:287
Types and functions for numbers manipulation.
Functions for string manipulation.