Geogram Version 1.9.6-rc
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
129 void GEOGRAM_API save_config(const std::string& filename);
130
148
158
179 void GEOGRAM_API declare_arg_group(
180 const std::string& name,
181 const std::string& description,
183 );
184
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,
210 );
211
218 ArgType GEOGRAM_API get_arg_type(const std::string& name);
219
220
226 std::string GEOGRAM_API get_arg_desc(const std::string& name);
227
234 bool GEOGRAM_API arg_is_declared(const std::string& name);
235
243 inline void declare_arg(
244 const std::string& name,
245 const std::string& default_value,
246 const std::string& description,
248 ) {
250 name, ARG_STRING, default_value,
251 description, flags
252 );
253 }
254
262 inline void declare_arg(
263 const std::string& name,
264 const char* default_value,
265 const std::string& description,
267 ) {
269 name, ARG_STRING, default_value,
270 description, flags
271 );
272 }
273
281 inline void declare_arg(
282 const std::string& name,
283 int default_value,
284 const std::string& description,
286 ) {
288 name, ARG_INT, String::to_string(default_value),
289 description, flags
290 );
291 }
292
300 inline void declare_arg(
301 const std::string& name,
302 double default_value,
303 const std::string& description,
305 ) {
307 name, ARG_DOUBLE, String::to_string(default_value),
308 description, flags
309 );
310 }
311
319 inline void declare_arg(
320 const std::string& name,
321 bool default_value,
322 const std::string& description,
324 ) {
326 name, ARG_BOOL, default_value ? "true" : "false",
327 description, flags
328 );
329 }
330
341 const std::string& name,
342 double default_value,
343 const std::string& description = "...",
345 ) {
347 name, ARG_PERCENT, String::to_string(default_value) + "%",
348 description, flags
349 );
350 }
351
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
404 bool GEOGRAM_API parse(
405 int argc, char** argv
406 );
407
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
426 charptrptr GEOGRAM_API argv();
427
440 void GEOGRAM_API show_usage(
441 const std::string& additional_args = "",
442 bool advanced = false
443 );
444
452 std::string GEOGRAM_API get_arg(const std::string& name);
453
464 int GEOGRAM_API get_arg_int(const std::string& name);
465
476 unsigned int GEOGRAM_API get_arg_uint(const std::string& name);
477
488 double GEOGRAM_API get_arg_double(const std::string& name);
489
508 double GEOGRAM_API get_arg_percent(
509 const std::string& name, double reference
510 );
511
522 bool GEOGRAM_API get_arg_bool(const std::string& name);
523
536 bool GEOGRAM_API set_arg(
537 const std::string& name, const std::string& value
538 );
539
552 inline bool set_arg(const std::string& name, const char* value) {
553 return set_arg(name, std::string(value));
554 }
555
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
618 void GEOGRAM_API set_arg(const std::string& name, double value);
619
630 void GEOGRAM_API set_arg(const std::string& name, bool value);
631
644 void GEOGRAM_API set_arg_percent(const std::string& name, double value);
645
646 /********************************************************************/
647
652 void GEOGRAM_API get_arg_groups(std::vector<std::string>& groups);
653
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
672 void GEOGRAM_API get_args(std::vector<std::string>& args);
673
679
707 void GEOGRAM_API ui_separator(
708 const std::string& title,
709 const std::string& short_title = ""
710 );
711
725 void GEOGRAM_API ui_separator();
726
739 void GEOGRAM_API ui_close_separator();
740
759 void GEOGRAM_API ui_message(
760 const std::string& message,
761 index_t wrap_margin
762 );
763
772 void GEOGRAM_API ui_message(
773 const std::string& message
774 );
775
781 void GEOGRAM_API ui_clear_line();
782
804 void GEOGRAM_API ui_progress(
805 const std::string& task_name, index_t val,
806 index_t percent, bool clear = true
807 );
808
820 void GEOGRAM_API ui_progress_time(
821 const std::string& task_name,
822 double elapsed, bool clear = true
823 );
824
837 void GEOGRAM_API ui_progress_canceled(
838 const std::string& task_name,
839 double elapsed, index_t percent, bool clear = true
840 );
841
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
877struct android_app;
878
879namespace GEO {
880 namespace CmdLine {
885 void GEOGRAM_API set_android_app(android_app* app);
886
891 android_app* GEOGRAM_API get_android_app();
892 }
893}
894
895#endif
896
897
898#endif
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 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.
void load_config(const std::string &filename, const std::string &program_name="*")
Loads command line argument values from a 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 save_config(const std::string &filename)
Saves command line argument values to a file.
void ui_close_separator()
Closes an opened separator.
ArgFlags
Command line group or argument flags.
void get_arg_groups(std::vector< std::string > &groups)
Lists all group names.
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 get_arg_names_in_group(const std::string &group, std::vector< std::string > &arg_names)
Lists all arg names in a a group.
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.
std::string get_arg_desc(const std::string &name)
Gets the description of an argument.
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:144
int32_t int32
Definition numeric.h:129
uint32_t uint32
Definition numeric.h:141
int64_t int64
Definition numeric.h:132
Global Vorpaline namespace.
Definition basic.h:55
geo_index_t index_t
The type for storing and manipulating indices.
Definition numeric.h:329
Types and functions for numbers manipulation.
Functions for string manipulation.