Param parser is oriented to geometry processing: some parameter types are related to input model, attributes of primitives. Although not required, command-line interfaces are intended to be interpreted by a third-party application like a modeler (e.g: Graphite using graphite add-on loader).
// Declare parameters
Parameters params;
// Set help message
params.help = "This program aims to demonstrate the use of param parser.";
// Declare parameters
// ...
// ...
// ...
// Parse program arguments and bind to parameters
params.init_from_args(argc, argv);
To add a parameter you need to specify its type, name and default value.
- Type must be described by a string or using
Parameters::Type
- All values must be described by a string (e.g: see
bool
type).
params.add(Parameters::Type::String, "my_string", "")
// can be written as
// params.add("string", "my_string", "")
params.add(Parameters::Type::Bool, "my_bool", "true")
// can be written as
// params.add("bool", "my_bool", "true")
int
: expect aint
float
: expect afloat
double
: expect adouble
bool
: expect abool
{false
,true
}string
: expect astring
file
: expect a file pathinput
: automatically set by the client (e.g: a modeler) by the path of the current model
vertices.int
: expect the name ofvertice
attribute of typeint
as valuevertices.float
: expect the name ofvertice
attribute of typefloat
as valuevertices.double
: expect the name ofvertice
attribute of typedouble
as valuevertices.bool
: expect the name ofvertice
attribute of typebool
as valuefacets.int
: expect the name offacets
attribute of typeint
as valuefacets.float
: expect the name offacets
attribute of typefloat
as valuefacets.double
: expect the name offacets
attribute of typedouble
as valuefacets.bool
: expect the name offacets
attribute of typebool
as valueedges.int
: expect the name ofedges
attribute of typeint
as valueedges.float
: expect the name ofedges
attribute of typefloat
as valueedges.double
: expect the name ofedges
attribute of typedouble
as valueedges.bool
: expect the name ofedges
attribute of typebool
as valuecells.int
: expect the name ofcells
attribute of typeint
as valuecells.float
: expect the name ofcells
attribute of typefloat
as valuecells.double
: expect the name ofcells
attribute of typedouble
as valuecells.bool
: expect the name ofcells
attribute of typebool
as value
Some parameter names are reserved. These special parameters may be interpreted and automatically set by the client (modeler, e.g: Graphite).
result_path
: client set this parameter value with a path that you must use to put your results files.run_from
: the name of the client that call the program, empty if the program is run in standalone mode
These parameters are declared automatically. You can get their values by using the following functions:
std::string result_path = params.result_path();
std::string run_from = params.run_from();
Using builder pattern, you can add some data to your parameter.
description(string desc)
add a description to a parameter. This description will be showed as a label or tooltip text by the client modeler.
Example:
params.add(Parameters::Type::String, "my_string", "").description("A string !");
type_of_param(string type)
Specify a visibilty and a role to your parameter.
With type
belongs to {basic
, advanced
, system
}.
basic
will be show to the useradvanced
will be show under a foldout menusystem
will be hide to the user
By default a parameter is of basic
type.
Example:
params.add(Parameters::Type::String, "my_string", "").type_of_param(Parameters::Kind::advanced);
// can be written as
// params.add(Parameters::Type::String, "my_string", "").type_of_param("advanced");
possible_values(string values)
Constraint parameter to a set of possible values. Client should interpret this as a choice list (combo box).
Example:
params.add(Parameters::Type::String, "my_enum", "x").possible_values("x,y,z");
❗ Possible values must be separated by a comma.
To get a parameter value just use indexation:
std::string my_string = params["my_string"];
int my_int = params["my_int"];
// ...
An implicit conversion was made between the parameter type and the variable type - provided they are consistent.