main.cpp File Reference
`#include <iostream>`
`#include "Hazelnupp.h"`
`#include "IntValue.h"`
Include dependency graph for main.cpp:

Go to the source code of this file.

## Functions

int | main (int argc, char **argv)

## Function Documentation

## main()

int main | ( | int | argc,
|  | char ** | argv
| ) |  |

Definition at line 7 of file main.cpp.

{
while (1)
{
// Mock command-line params
std::vector<const char*> testArgv = {
"meinpfad",
"-w",
"-99",
"--alfred",
"apfel",
"banane",
"triangle",
"--numbers",
"1",
"2",
"3",
"4",
"5",
};
argc = testArgv.size();
argv = const_cast<char**>(testArgv.data());
// Prepare Hazelnupp parser
Hazelnupp args;
ParamConstraint pc;
pc.key = "--alfredo";
pc.constrainType = true;
pc.wantedType = DATA_TYPE::LIST;
pc.required = true;
pc.defaultValue = { "coca cola", "fanta" };
args.RegisterConstraints({
pc
});
args.RegisterAbbreviation("-w", "--word");
// Parse
args.Parse(argc, argv);
// Use
if (args.HasParam("--alfredo"))
{
std::cout << args["--alfredo"].GetInt32() << std::endl;
}
else
{
std::cout << "No --alfredo!" << std::endl;
}
}
return 0;
}
Hazelnp::Hazelnupp
The main class to interface with.
Definition: Hazelnupp.h:11
Hazelnp::ParamConstraint::wantedType
DATA_TYPE wantedType
Constrain the parameter to this value. Requires constrainType to be set to true.
Definition: ParamConstraint.h:57
Hazelnp::ParamConstraint
Definition: ParamConstraint.h:8
Hazelnp::Hazelnupp::HasParam
bool HasParam(const std::string &key) const
Will check wether a parameter exists given a key, or not.
Definition: Hazelnupp.cpp:153
Hazelnp::Hazelnupp::Parse
void Parse(const int argc, const char *const *argv)
Will parse command line arguments.
Definition: Hazelnupp.cpp:35
Hazelnp::ParamConstraint::constrainType
bool constrainType
Should this parameter be forced to be of a certain type? Remember to set constrainTo to the wanted ...
Definition: ParamConstraint.h:54
Hazelnp::Hazelnupp::RegisterAbbreviation
void RegisterAbbreviation(const std::string &abbrev, const std::string &target)
Will register an abbreviation (like -f for –force)
Definition: Hazelnupp.cpp:332
Hazelnp::Hazelnupp::RegisterConstraints
void RegisterConstraints(const std::vector< ParamConstraint > &constraints)
Will register parameter constraints.
Definition: Hazelnupp.cpp:354
Hazelnp::ParamConstraint::key
std::string key
The key of the parameter to constrain.
Definition: ParamConstraint.h:50
Hazelnp::ParamConstraint::required
bool required
If set to true, and no default value set, an error will be produced if this parameter is not supplied...
Definition: ParamConstraint.h:66
Hazelnp::ParamConstraint::defaultValue
std::vector< std::string > defaultValue
The default value for this parameter.
Definition: ParamConstraint.h:62