GCC Code Coverage Report


Directory: ./
File: lib/geogram/basic/command_line.h
Date: 2026-09-07 02:25:23
Exec Total Coverage
Lines: 22 24 91.7%
Functions: 6 6 100.0%
Branches: 8 16 50.0%

Line Branch Exec Source
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
43 #include <geogram/basic/common.h>
44 #include <geogram/basic/numeric.h>
45 #include <geogram/basic/string.h>
46 #include <geogram/basic/assert.h>
47
48 /**
49 * \file geogram/basic/command_line.h
50 * \brief Functions to parse and store command line arguments
51 */
52
53 namespace GEO {
54
55 /**
56 * \brief Utilities to process command line arguments.
57 * \details CmdLine defines utility functions to declare program options
58 * and parse command line arguments.
59 */
60 namespace CmdLine {
61
62 /**
63 * \brief Initializes the command line framework
64 * \details This function must be called once at program start.
65 * It is called by the general initialization function
66 * GEO::initialize().
67 * \see GEO::initialize().
68 */
69 void GEOGRAM_API initialize();
70
71 /**
72 * \brief Cleans up the command line framework
73 * \details This function must be called at program termination
74 * program. It is called by the general cleanup function
75 * GEO::terminate().
76 * \see GEO::terminate().
77 */
78 void GEOGRAM_API terminate();
79
80
81 /**
82 * \brief Defines the name of the configuration file.
83 * \param[in] filename the name of the configuration file. Before
84 * parsing command line arguments, arguments are set according
85 * to this file, loaded from the home directory (or 'My Documents'
86 * under Windows). Default is 'geogram.ini'.
87 * \param[in] auto_create_args if set, all the args present in the
88 * configuration file are created if they do not already exist, else
89 * a warning message is displayed for args that do not exist.
90 */
91 void GEOGRAM_API set_config_file_name(
92 const std::string& filename,
93 bool auto_create_args = false
94 );
95
96 /**
97 * \brief Tests whether the configuration file was loaded.
98 * \details The default configuration file, or the one specified
99 * by set_config_file_name() may not exist, in this case this
100 * function returns false.
101 * \retval true if the configuration file was loaded.
102 * \retval false otherwise.
103 */
104 bool GEOGRAM_API config_file_loaded();
105
106 /**
107 * \brief Gets the name of the configuration file.
108 * \return the name of the configuration file, as
109 * specified by set_config_file_name(). User's home directory
110 * needs to be prepended to have the complete file path.
111 */
112 std::string GEOGRAM_API get_config_file_name();
113
114 /**
115 * \brief Loads command line argument values from a file.
116 * \details only args in the section with \p program_name
117 * are loaded if \p program_name is specified.
118 * \param[in] filename the complete path to the file.
119 * \param[in] program_name if specified the name of the program.
120 */
121 void GEOGRAM_API load_config(
122 const std::string& filename, const std::string& program_name = "*"
123 );
124
125 /**
126 * \brief Saves command line argument values to a file.
127 * \param[in] filename the complete path to the file.
128 */
129 void GEOGRAM_API save_config(const std::string& filename);
130
131 /**
132 * \brief Command line argument types
133 */
134 enum ArgType {
135 /** Argument type is undefined */
136 ARG_UNDEFINED = 0,
137 /** Argument is a signed integer */
138 ARG_INT = 1,
139 /** Argument is a floating point value */
140 ARG_DOUBLE = 2,
141 /** Argument is a string */
142 ARG_STRING = 4,
143 /** Argument is a boolean */
144 ARG_BOOL = 8,
145 /** Argument is a percentage */
146 ARG_PERCENT = 16
147 };
148
149 /**
150 * \brief Command line group or argument flags
151 */
152 enum ArgFlags {
153 /** Default argument flags (nothing) */
154 ARG_FLAGS_DEFAULT = 0,
155 /** Argument is advanced */
156 ARG_ADVANCED = 1
157 };
158
159 /**
160 * \brief Declares an argument group
161 * \details This creates a new argument group with the given name \p
162 * name. If a group with the same name already exists, the new group
163 * is not created.
164 *
165 * Argument groups are used to organize arguments in a set of
166 * logically related arguments. For instance:
167 * - group "sys" contains arguments to configure the Process module,
168 * - group "log" contains arguments to configure the Logger,
169 * - ...
170 *
171 * To declare an argument in a given group, the argument name must be
172 * prefixed by the group name followed by a colon as in "group:arg".
173 *
174 * \param[in] name the group name
175 * \param[in] description the group description
176 * \param[in] flags the group flags
177 * \see declare_arg()
178 */
179 void GEOGRAM_API declare_arg_group(
180 const std::string& name,
181 const std::string& description,
182 ArgFlags flags = ARG_FLAGS_DEFAULT
183 );
184
185 /**
186 * \brief Declares an argument
187 * \details This is the general function for declaring an argument of
188 * name \p name. The default value \p default_value is given as a
189 * string and must be convertible to the given type \p type. The
190 * command line framework provides type-safe variants of declare_arg()
191 * for declaring arguments, it is highly recommended to use them.
192 *
193 * Argument names can have 2 forms:
194 * - "group:arg" - the argument "arg" is added to the group "group".
195 * - "arg" - without a group name, the argument "arg" is added to the
196 * default group "global"
197 *
198 * \param[in] name the argument name
199 * \param[in] type the argument type
200 * \param[in] default_value the default value as a string
201 * \param[in] description the argument description
202 * \param[in] flags the argument flags
203 */
204 void GEOGRAM_API declare_arg(
205 const std::string& name,
206 ArgType type,
207 const std::string& default_value,
208 const std::string& description,
209 ArgFlags flags = ARG_FLAGS_DEFAULT
210 );
211
212 /**
213 * \brief Gets the type of an argument
214 * \param[in] name the argument name
215 * \retval the type of the argument if it exists
216 * \retval #ARG_UNDEFINED otherwise
217 */
218 ArgType GEOGRAM_API get_arg_type(const std::string& name);
219
220
221 /**
222 * \brief Gets the description of an argument
223 * \param[in] name the argument name
224 * \return the description of the argument
225 */
226 std::string GEOGRAM_API get_arg_desc(const std::string& name);
227
228 /**
229 * \brief Checks if an argument exists
230 * \param[in] name the argument name
231 * \retval true if the argument exists
232 * \retval false otherwise
233 */
234 bool GEOGRAM_API arg_is_declared(const std::string& name);
235
236 /**
237 * \brief Declares an argument of type string
238 * \param[in] name the argument name
239 * \param[in] default_value argument's default string value
240 * \param[in] description argument description
241 * \param[in] flags the argument flags
242 */
243 inline void declare_arg(
244 const std::string& name,
245 const std::string& default_value,
246 const std::string& description,
247 ArgFlags flags = ARG_FLAGS_DEFAULT
248 ) {
249 declare_arg(
250 name, ARG_STRING, default_value,
251 description, flags
252 );
253 }
254
255 /**
256 * \brief Declares an argument of type string
257 * \param[in] name the argument name
258 * \param[in] default_value argument's default C-string value
259 * \param[in] description argument description
260 * \param[in] flags the argument flags
261 */
262 2836 inline void declare_arg(
263 const std::string& name,
264 const char* default_value,
265 const std::string& description,
266 ArgFlags flags = ARG_FLAGS_DEFAULT
267 ) {
268
1/2
✓ Branch 1 taken 2836 times.
✗ Branch 2 not taken.
2836 declare_arg(
269 2836 name, ARG_STRING, default_value,
270 description, flags
271 );
272 2836 }
273
274 /**
275 * \brief Declares an argument of type integer
276 * \param[in] name the argument name
277 * \param[in] default_value argument's default integer value
278 * \param[in] description argument description
279 * \param[in] flags the argument flags
280 */
281 1588 inline void declare_arg(
282 const std::string& name,
283 int default_value,
284 const std::string& description,
285 ArgFlags flags = ARG_FLAGS_DEFAULT
286 ) {
287
1/2
✓ Branch 1 taken 1588 times.
✗ Branch 2 not taken.
1588 declare_arg(
288 1588 name, ARG_INT, String::to_string(default_value),
289 description, flags
290 );
291 1588 }
292
293 /**
294 * \brief Declares an argument of type floating point
295 * \param[in] name the argument name
296 * \param[in] default_value argument's default floating point value
297 * \param[in] description argument description
298 * \param[in] flags the argument flags
299 */
300 489 inline void declare_arg(
301 const std::string& name,
302 double default_value,
303 const std::string& description,
304 ArgFlags flags = ARG_FLAGS_DEFAULT
305 ) {
306
1/2
✓ Branch 1 taken 489 times.
✗ Branch 2 not taken.
489 declare_arg(
307 489 name, ARG_DOUBLE, String::to_string(default_value),
308 description, flags
309 );
310 489 }
311
312 /**
313 * \brief Declares an argument of type boolean
314 * \param[in] name the argument name
315 * \param[in] default_value argument's default boolean value
316 * \param[in] description argument description
317 * \param[in] flags the argument flags
318 */
319 5792 inline void declare_arg(
320 const std::string& name,
321 bool default_value,
322 const std::string& description,
323 ArgFlags flags = ARG_FLAGS_DEFAULT
324 ) {
325
1/2
✓ Branch 1 taken 5792 times.
✗ Branch 2 not taken.
5792 declare_arg(
326
2/2
✓ Branch 0 taken 4193 times.
✓ Branch 1 taken 1599 times.
9985 name, ARG_BOOL, default_value ? "true" : "false",
327 description, flags
328 );
329 5792 }
330
331 /**
332 * \brief Declares an argument of type percentage
333 * \details Percentage values are normal floating point values, except
334 * that their string representation is followed by a percent "%" sign.
335 * \param[in] name the argument name
336 * \param[in] default_value argument's default percentage value
337 * \param[in] description argument description
338 * \param[in] flags the argument flags
339 */
340 528 inline void declare_arg_percent(
341 const std::string& name,
342 double default_value,
343 const std::string& description = "...",
344 ArgFlags flags = ARG_FLAGS_DEFAULT
345 ) {
346
1/2
✓ Branch 1 taken 528 times.
✗ Branch 2 not taken.
528 declare_arg(
347 528 name, ARG_PERCENT, String::to_string(default_value) + "%",
348 description, flags
349 );
350 528 }
351
352 /**
353 * \brief Parses the command line arguments
354 * \details This analyzes command line arguments passed to the main()
355 * program in \p argc and \p argv. Arguments not matching program
356 * options declared with declare_arg() are stored in output vector \p
357 * unparsed_args.
358 *
359 * Command line parsing allows users to specify partial option names
360 * on the command line. If a partial name matches more than 1 declared
361 * argument, it is rejected and the functions fails, otherwise, it is
362 * accepted and replaced by the full argument name.
363 *
364 * Parameter \p additional_arg_specs specifies how to
365 * handle unparsed arguments. It consists in a white space separated
366 * list of additional argument names expected by the program, with the
367 * following meaning:
368 * - "<arg_name>" - means that the argument is optional
369 * - "arg_name" - means that the argument is mandatory
370 *
371 * For instance the following additional argument specification:
372 * \code
373 * "input_file <option_file> <output_file>
374 * \endcode
375 * means that the program expects at least one additional argument
376 * \e input_file, with two additional optional arguments \e
377 * option_file and \e output_file.
378 *
379 * If argument "-h" is found in the list of arguments, then the
380 * program displays a summary of program options and exits (see
381 * show_usage()).
382 *
383 * \param[in] argc number of arguments passed to main()
384 * \param[in] argv array of command line arguments passed to main()
385 * \param[out] unparsed_args output vector of unparsed arguments
386 * \param[in] additional_arg_specs unparsed argument specification
387 * \retval true if the command line arguments are successfully parsed
388 * \retval false otherwise
389 */
390 bool GEOGRAM_API parse(
391 int argc, char** argv, std::vector<std::string>& unparsed_args,
392 const std::string& additional_arg_specs = ""
393 );
394
395 /**
396 * \brief Parses the command line arguments
397 * \details This is a simplified version of parse() which does not
398 * accept additional unparsed arguments.
399 * \param[in] argc number of arguments passed to main()
400 * \param[in] argv array of command line arguments passed to main()
401 * \retval true if the command line arguments are successfully parsed
402 * \retval false otherwise
403 */
404 bool GEOGRAM_API parse(
405 int argc, char** argv
406 );
407
408 /**
409 * \brief Gets the number of arguments of the command line.
410 * \return the number of arguments plus one.
411 * \details parse() should be called before.
412 */
413 int GEOGRAM_API argc();
414
415
416 typedef char** charptrptr; // Need to do that else the compiler thinks
417 // that GEOGRAM_API qualifies the ptr instead
418 // of the function.
419
420 /**
421 * \brief Gets the command line arguments.
422 * \return a pointer to an array of null-terminated strings with
423 * the command line arguments. The first one is the program name.
424 * \details parse() should be called before.
425 */
426 charptrptr GEOGRAM_API argv();
427
428 /**
429 * \brief Displays program help
430 * \details Displays a list of all declared arguments (sorted by
431 * argument group) with their current value. By default, show_usage()
432 * only displays standard groups and arguments. If parameter \p
433 * advanced is set to \c true, show_usage() also displays advanced
434 * groups and arguments (declared with flag ARG_ADVANCED).
435 * \param[in] additional_args additional argument specification (see
436 * parse()).
437 * \param[in] advanced boolean flag that controls the display of
438 * advanced groups and arguments.
439 */
440 void GEOGRAM_API show_usage(
441 const std::string& additional_args = "",
442 bool advanced = false
443 );
444
445 /**
446 * \brief Gets an argument value
447 * \details Retrieves the string value of argument \p name. If the
448 * argument does not exist, then the function calls abort().
449 * \param[in] name the argument name
450 * \return the value of the argument as a string if it exists
451 */
452 std::string GEOGRAM_API get_arg(const std::string& name);
453
454 /**
455 * \brief Gets an argument value as an integer
456 * \details Retrieves the value of argument \p name and converts it to
457 * an integer. If the argument does not exists or its value is not
458 * convertible to an integer, then the function aborts.
459 * \param[in] name the argument name
460 * \return the argument value converted to an integer if the argument
461 * exists
462 * \see String::to_int()
463 */
464 int GEOGRAM_API get_arg_int(const std::string& name);
465
466 /**
467 * \brief Gets an argument value as an unsigned integer
468 * \details Retrieves the value of argument \p name and converts it to
469 * an unsigned integer. If the argument does not exists or its value
470 * is not convertible to an unsigned integer, then the function aborts.
471 * \param[in] name the argument name
472 * \return the argument value converted to an unsigned integer if
473 * the argument exists
474 * \see String::to_uint()
475 */
476 unsigned int GEOGRAM_API get_arg_uint(const std::string& name);
477
478 /**
479 * \brief Gets an argument value as a floating point
480 * \details Retrieves the value of argument \p name and converts it to
481 * a floating point. If the argument does not exists or its value is
482 * not convertible to a floating point, then the function aborts.
483 * \param[in] name the argument name
484 * \return the argument value converted to a floating point if the
485 * argument exists
486 * \see String::to_double()
487 */
488 double GEOGRAM_API get_arg_double(const std::string& name);
489
490 /**
491 * \brief Gets an argument value as a percentage
492 * \details Retrieves the value of argument \p name:
493 * - if the value has the form of a percentage \e "dd%", it is
494 * considered as a relative error of the parameter \p reference. The
495 * returned value is the floating point value \e 0.01*dd multiplied
496 * by the parameter \p reference.
497 * - if the value is directly convertible to a floating point number,
498 * it is considered as an "absolute error" and returned as is. In this
499 * case parameter \p reference is ignored.
500 * - in all other cases, the function aborts
501 * \param[in] name the argument name
502 * \param[in] reference the value to apply the percentage to
503 * \return either:
504 * - the argument value converted to a percentage of the \p reference
505 * - or the floating point value of argument \p name
506 * \see String::to_double()
507 */
508 double GEOGRAM_API get_arg_percent(
509 const std::string& name, double reference
510 );
511
512 /**
513 * \brief Gets an argument value as a boolean
514 * \details Retrieves the value of argument \p name and converts it to
515 * an integer. If the argument does not exists or its value is not
516 * convertible to a boolean, then the function aborts.
517 * \param[in] name the argument name
518 * \return the argument value converted to a boolean if the
519 * argument exists
520 * \see String::to_bool()
521 */
522 bool GEOGRAM_API get_arg_bool(const std::string& name);
523
524 /**
525 * \brief Sets an argument value from a string
526 * \details This replaces the value of argument \p name by the given
527 * string \p value. If the string \p value is not strictly convertible
528 * to the declared type of the argument then the function aborts. If
529 * the argument does not exist, it is added as a new argument of
530 * undefined type.
531 * \param[in] name the argument name
532 * \param[in] value the new value as a string
533 * \retval true if the argument was successfully set
534 * \retval false otherwise
535 */
536 bool GEOGRAM_API set_arg(
537 const std::string& name, const std::string& value
538 );
539
540 /**
541 * \brief Sets an argument value from a C-string
542 * \details This replaces the value of argument \p name by the given
543 * C-string \p value. If the string \p value is not strictly
544 * convertible to the declared type of the argument then the function
545 * aborts. If the argument does not exist, it is added as a new
546 * argument of undefined type.
547 * \param[in] name the argument name
548 * \param[in] value the new value as a C-string
549 * \retval true if the argument was successfully set
550 * \retval false otherwise
551 */
552 15 inline bool set_arg(const std::string& name, const char* value) {
553
1/2
✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
30 return set_arg(name, std::string(value));
554 }
555
556 /**
557 * \brief Sets an argument value from an integer
558 * \details This replaces the value of argument \p name by the given
559 * integer \p value. If the declared type of the argument is not
560 * compatible with an integer then the function aborts (compatible
561 * argument types are: int, double or string). If the argument does
562 * not exist, it is added as a new argument of undefined type.
563 * \param[in] name the argument name
564 * \param[in] value the new value as an integer
565 */
566 void GEOGRAM_API set_arg(const std::string& name, Numeric::int32 value);
567
568 /*
569 * \brief Sets an argument value from an integer
570 * \details This replaces the value of argument \p name by the given
571 * integer \p value. If the declared type of the argument is not
572 * compatible with an integer then the function aborts (compatible
573 * argument types are: int, double or string). If the argument does
574 * not exist, it is added as a new argument of undefined type.
575 * \param[in] name the argument name
576 * \param[in] value the new value as an integer
577 */
578 void GEOGRAM_API set_arg(
579 const std::string& name, Numeric::uint32 value
580 );
581
582 /*
583 * \brief Sets an argument value from an integer
584 * \details This replaces the value of argument \p name by the given
585 * integer \p value. If the declared type of the argument is not
586 * compatible with an integer then the function aborts (compatible
587 * argument types are: int, double or string). If the argument does
588 * not exist, it is added as a new argument of undefined type.
589 * \param[in] name the argument name
590 * \param[in] value the new value as an integer
591 */
592 void GEOGRAM_API set_arg(const std::string& name, Numeric::int64 value);
593
594 /*
595 * \brief Sets an argument value from an integer
596 * \details This replaces the value of argument \p name by the given
597 * integer \p value. If the declared type of the argument is not
598 * compatible with an integer then the function aborts (compatible
599 * argument types are: int, double or string). If the argument does
600 * not exist, it is added as a new argument of undefined type.
601 * \param[in] name the argument name
602 * \param[in] value the new value as an integer
603 */
604 void GEOGRAM_API set_arg(
605 const std::string& name, Numeric::uint64 value
606 );
607
608 /**
609 * \brief Sets an argument value from a floating point
610 * \details This replaces the value of argument \p name by the given
611 * floating point \p value. If the declared type of the argument is
612 * not compatible with a floating point then the function aborts
613 * (compatible argument types are: double or string). If the argument
614 * does not exist, it is added as a new argument of undefined type.
615 * \param[in] name the argument name
616 * \param[in] value the new value as a floating point
617 */
618 void GEOGRAM_API set_arg(const std::string& name, double value);
619
620 /**
621 * \brief Sets an argument value from a boolean
622 * \details This replaces the value of argument \p name by the given
623 * boolean \p value. If the declared type of the argument is not
624 * compatible with a boolean then the function aborts (compatible
625 * argument types are: boolean or string). If the argument does not
626 * exist, it is added as a new argument of undefined type.
627 * \param[in] name the argument name
628 * \param[in] value the new value as a floating point
629 */
630 void GEOGRAM_API set_arg(const std::string& name, bool value);
631
632 /**
633 * \brief Sets an argument value from a percentage
634 * \details This replaces the value of argument \p name by the given
635 * floating point \p value. If the declared type of the argument is
636 * not compatible with a floating point then the function aborts
637 * (compatible argument types are: double or string), otherwise the
638 * argument receives the \p value converted to a floating with a
639 * trailing '%' sign. If the argument does not exist, it is added as a
640 * new argument of undefined type.
641 * \param[in] name the argument name
642 * \param[in] value the new value as a floating point
643 */
644 void GEOGRAM_API set_arg_percent(const std::string& name, double value);
645
646 /********************************************************************/
647
648 /**
649 * \brief Lists all group names
650 * \param[out] groups a vector of strings with all group names
651 */
652 void GEOGRAM_API get_arg_groups(std::vector<std::string>& groups);
653
654 /**
655 * \brief Lists all arg names in a a group
656 * \param[in] group a group name
657 * \param[out] arg_names a vector of strings with all arg names in group
658 */
659 void GEOGRAM_API get_arg_names_in_group(
660 const std::string& group,
661 std::vector<std::string>& arg_names
662 );
663
664 /********************************************************************/
665
666 /**
667 * \brief Gets the value of all arguments
668 * \details Stores in vector \p args the value of all declared
669 * arguments in the form "name=value".
670 * \param[out] args output vector
671 */
672 void GEOGRAM_API get_args(std::vector<std::string>& args);
673
674 /**
675 * \brief Gets the width of the console.
676 * \return the console width in number of characters
677 */
678 index_t GEOGRAM_API ui_terminal_width();
679
680 /**
681 * \brief Outputs a separator with a title on the console
682 * \details Prints a separator string on the console that contains the
683 * given \p title and optional \p short_title. If it is specified, the
684 * \p short_title appears on the left of \p title in the separator as
685 * illustrated below. This function is used by Logger::div() to create
686 * a new division in the log output.
687 *
688 * When the Logger is in pretty mode, the separator has the following
689 * form:
690 * \code
691 * _/ ==[short_title]====[title]== \\______
692 * | |
693 * \endcode
694 *
695 * Otherwise the separator has the following form
696 * In non-pretty mode, or if the program output is redirected to a
697 * file, the separator has the following form:
698 * \code
699 * ==[short_title]====[title]==
700 * \endcode
701 *
702 * \param[in] title the main title string
703 * \param[in] short_title optional title that appears on the left of
704 * \p title
705 * \see Logger::div()
706 */
707 void GEOGRAM_API ui_separator(
708 const std::string& title,
709 const std::string& short_title = ""
710 );
711
712 /**
713 * \brief Outputs a separator without a title on the console.
714 * \details Prints a simple separator string on the console.
715 * When the Logger is in pretty mode, the separator has the following
716 * form:
717 * \code
718 * ________________________________________
719 * | |
720 * \endcode
721 *
722 * In non-pretty mode, or if the program output is redirected to a
723 * file, nothing is printed.
724 */
725 void GEOGRAM_API ui_separator();
726
727 /**
728 * \brief Closes an opened separator
729 * \details This closes the last opened box.
730 * When the Logger is in pretty mode, the separator has the following
731 * form:
732 * \code
733 * \\________________________________________/
734 * \endcode
735 *
736 * In non-pretty mode, or if the program output is redirected to a
737 * file, nothing is printed.
738 */
739 void GEOGRAM_API ui_close_separator();
740
741 /**
742 * \brief Outputs a message on the console.
743 * \details Prints the message \p message to the console. In pretty
744 * mode, the message is enclosed in vertical bars, thus forming a box
745 * with the previous separator (see ui_separator()). If the message is
746 * too long to fit in the console width, it is wrapped on the next
747 * line(s) with an additional left margin given by \p wrap_margin.
748 * \code
749 * | This is an example of a very very long |
750 * | <wrap_margin> message that wraps on th |
751 * | <wrap_margin> e next lines |
752 * \endcode
753 *
754 * In non-pretty mode, the message is printed "as is".
755 * \param[in] message the message to print
756 * \param[in] wrap_margin extra left margin used to print continuation
757 * lines of long messages
758 */
759 void GEOGRAM_API ui_message(
760 const std::string& message,
761 index_t wrap_margin
762 );
763
764 /**
765 * \brief Outputs a message on the console.
766 * \details This is a variant of ui_message() with a default
767 * wrap_margin that keeps wrapped lines aligned with the end of the
768 * feature names.
769 * \param[in] message the message to print
770 * \see ui_feature()
771 */
772 void GEOGRAM_API ui_message(
773 const std::string& message
774 );
775
776 /**
777 * \brief Clears the last line.
778 * \details This function is only used in pretty mode and mainly to
779 * display progress bars.
780 */
781 void GEOGRAM_API ui_clear_line();
782
783 /**
784 * \brief Displays a progress bar
785 * \details This displays a progress bar for the given task \p task
786 * name. The progress of the task is specified by the current progress
787 * value \p val and the percentage of completion \p percent. The
788 * progress bar is formatted as illustrated below:
789 * \code
790 * o-[task_name ] (wheel)-[val]-[percent]--[waves]
791 * \endcode
792 * where:
793 * - wheel is an animated rotating progress wheel
794 * - waves is an animated progress bar
795 * Once the task has completed, one should call ui_progress_time() to
796 * display the elapsed time of for the task.
797 * \param[in] task_name the name of the task in progress
798 * \param[in] val the current progress value
799 * \param[in] percent the percentage of completion
800 * \param[in] clear whether to clear the line before displaying the
801 * progress bar (default is \c true)
802 * \see ui_progress_time()
803 */
804 void GEOGRAM_API ui_progress(
805 const std::string& task_name, index_t val,
806 index_t percent, bool clear = true
807 );
808
809 /**
810 * \brief Displays the time elapsed for a completed task
811 * \details Call this function after successive calls to ui_progress()
812 * to display the elapsed time once the task task \p task_name has
813 * completed.
814 * \param[in] task_name the name of the task being completed.
815 * \param[in] elapsed the time elapsed for completing the task
816 * \param[in] clear whether to clear the line before displaying the
817 * progress bar (default is \c true)
818 * \see ui_progress()
819 */
820 void GEOGRAM_API ui_progress_time(
821 const std::string& task_name,
822 double elapsed, bool clear = true
823 );
824
825 /**
826 * \brief Displays the time elapsed for a canceled task
827 * \details Call this function when a task has been canceled to
828 * display the elapsed time \p elapsed and the percentage of
829 * completion \p percent.
830 * \param[in] task_name the name of the task being completed.
831 * \param[in] elapsed the time elapsed since the beginning of the task
832 * \param[in] percent the percentage of completion of the task
833 * \param[in] clear whether to clear the line before displaying the
834 * progress bar (default is \c true)
835 * \see ui_progress()
836 */
837 void GEOGRAM_API ui_progress_canceled(
838 const std::string& task_name,
839 double elapsed, index_t percent, bool clear = true
840 );
841
842 /**
843 * \brief Formats a Logger feature name
844 * \details Logger features are displayed with a special formatting in
845 * the output log. They precede the messages sent to the Logger as
846 * illustrated below:
847 * \code
848 * o-[feature ] message...
849 * \endcode
850 *
851 * Multiple messages sent to the Logger with the same feature display
852 * the feature only once:
853 *
854 * \code
855 * o-[feature ] first message ...
856 * second message with the same feature...
857 * \endcode
858 *
859 * If parameter \p show is set to \c true, the function returns the
860 * feature formatted as for the first message in the example above. If
861 * \p show is set to \c false, the functions returns an empty
862 * placeholder used as a left margin
863 * length.
864 * \param[in] feature the text of the feature
865 * \param[in] show \c true to actually display the feature name or \c
866 * false to return an empty placeholder of the same width
867 * \return the formatted feature
868 */
869 std::string GEOGRAM_API ui_feature(
870 const std::string& feature, bool show = true
871 );
872 }
873 }
874
875
876 #ifdef GEO_OS_ANDROID
877 struct android_app;
878
879 namespace GEO {
880 namespace CmdLine {
881 /**
882 * \brief Declares the current android app.
883 * \param[in] app a pointer to the android app.
884 */
885 void GEOGRAM_API set_android_app(android_app* app);
886
887 /**
888 * \brief Gets the android app.
889 * \return a pointer to the android app.
890 */
891 android_app* GEOGRAM_API get_android_app();
892 }
893 }
894
895 #endif
896
897
898 #endif
899