Leonetienne/Hazelnupp
Simple, easy to use, command line parameter interface
ParamConstraint.h
Go to the documentation of this file.
1#pragma once
2#include "DataType.h"
3#include <string>
4#include <vector>
5
6namespace Hazelnp
7{
9 {
10 public:
11 //! Empty constructor
12 ParamConstraint() = default;
13
14 //! Constructs a require constraint.
15 //! Think of the default value like of a list ofparameters. Like {"--width", "800"}
16 static ParamConstraint Require(const std::initializer_list<std::string>& defaultValue = {}, bool required = true)
17 {
20 pc.required = required;
21
22 return pc;
23 }
24
25 //! Daisychain-method. Will add a the "required-argument" aspect.
26 //! Think of the default value like of a list ofparameters. Like {"--width", "800"}
27 ParamConstraint AddRequire(const std::initializer_list<std::string>& defaultValue = {}, bool required = true)
28 {
29 ParamConstraint pc = *this;
31 pc.required = required;
32
33 return pc;
34 }
35
36 //! Constructs a type-safety constraint
38 {
42
43 return pc;
44 }
45
46 //! Daisychain-method. Will add a the "type-safety" aspect.
47 //! Constructs a type-safety constraint
49 {
50 ParamConstraint pc = *this;
53
54 return pc;
55 }
56
57 //! Constructs an incompatibility constraint.
58 //! This means, that the following parameters are NOT compatible with this one and will throw an error if passed together
59 static ParamConstraint Incompatibility(const std::initializer_list<std::string>& incompatibleParameters)
60 {
63
64 return pc;
65 }
66
67 //! Constructs an incompatibility constraint.
68 //! This means, that the following parameters are NOT compatible with this one and will throw an error if passed together.
69 //! Syntactical-sugar proxy method that will convert the lonely string to an initializer list for you :3
71 {
74
75 return pc;
76 }
77
78 //! Daisychain-method. Will add a the "incompatiblity" aspect.
79 //! This means, that the following parameters are NOT compatible with this one and will throw an error if passed together.
80 //! Syntactical-sugar proxy method that will convert the lonely string to an initializer list for you :3
82 {
83 ParamConstraint pc = *this;
85
86 return pc;
87 }
88
89 //! Daisychain-method. Will add a the "incompatiblity" aspect.
90 //! This means, that the following parameters are NOT compatible with this one and will throw an error if passed together.
91 ParamConstraint AddIncompatibilities(const std::initializer_list<std::string>& incompatibleParameters)
92 {
93 ParamConstraint pc = *this;
95
96 return pc;
97 }
98
99 //! Whole constructor
100 ParamConstraint(bool constrainType, DATA_TYPE requiredType, const std::initializer_list<std::string>& defaultValue, bool required, const std::initializer_list<std::string>& incompatibleParameters)
101 :
107 {
108 return;
109 }
110
111 //! Should this parameter be forced to be of a certain type?
112 //! Remember to set `constrainTo` to the wanted type
113 bool constrainType = false;
114
115 //! Constrain the parameter to this value. Requires `constrainType` to be set to true.
117
118 //! The default value for this parameter.
119 //! Gets applied if this parameter was not given.
120 //! Think of this like a list of parameters. Like {"--width", "800"}
121 std::vector<std::string> defaultValue;
122
123 //! If set to true, and no default value set,
124 //! an error will be produced if this parameter is not supplied by the user.
125 bool required = false;
126
127 //! Parameters that are incompatible with this parameter
128 std::vector<std::string> incompatibleParameters;
129
130 private:
131 //! The parameter this constraint is for.
132 //! This value is automatically set by Hazelnupp.
133 std::string key;
134
135 friend class CmdArgsInterface;
136 };
137}
The main class to interface with.
DATA_TYPE
The different data types a paramater can be.
Definition: DataType.h:9
std::vector< std::string > defaultValue
The default value for this parameter.
DATA_TYPE requiredType
Constrain the parameter to this value. Requires constrainType to be set to true.
ParamConstraint AddIncompatibilities(const std::initializer_list< std::string > &incompatibleParameters)
Daisychain-method.
static ParamConstraint Incompatibility(const std::initializer_list< std::string > &incompatibleParameters)
Constructs an incompatibility constraint.
static ParamConstraint Incompatibility(const std::string &incompatibleParameters)
Constructs an incompatibility constraint.
static ParamConstraint TypeSafety(DATA_TYPE requiredType, bool constrainType=true)
Constructs a type-safety constraint.
bool constrainType
Should this parameter be forced to be of a certain type? Remember to set constrainTo to the wanted ...
static ParamConstraint Require(const std::initializer_list< std::string > &defaultValue={}, bool required=true)
Constructs a require constraint.
bool required
If set to true, and no default value set, an error will be produced if this parameter is not supplied...
ParamConstraint AddRequire(const std::initializer_list< std::string > &defaultValue={}, bool required=true)
Daisychain-method.
std::vector< std::string > incompatibleParameters
Parameters that are incompatible with this parameter.
ParamConstraint AddTypeSafety(DATA_TYPE requiredType, bool constrainType=true)
Daisychain-method.
ParamConstraint AddIncompatibilities(const std::string &incompatibleParameters)
Daisychain-method.
ParamConstraint(bool constrainType, DATA_TYPE requiredType, const std::initializer_list< std::string > &defaultValue, bool required, const std::initializer_list< std::string > &incompatibleParameters)
Whole constructor.
ParamConstraint()=default
Empty constructor.