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 
6 namespace 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  {
18  ParamConstraint pc;
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  {
39  ParamConstraint pc;
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  {
61  ParamConstraint pc;
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  {
72  ParamConstraint pc;
73  pc.incompatibleParameters = { incompatibleParameters };
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;
84  pc.incompatibleParameters = { incompatibleParameters };
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  :
102  constrainType{ constrainType },
105  required{ required },
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 }
ParamConstraint AddTypeSafety(DATA_TYPE requiredType, bool constrainType=true)
Daisychain-method.
ParamConstraint AddRequire(const std::initializer_list< std::string > &defaultValue={}, bool required=true)
Daisychain-method.
static ParamConstraint Incompatibility(const std::string &incompatibleParameters)
Constructs an incompatibility constraint.
ParamConstraint AddIncompatibilities(const std::string &incompatibleParameters)
Daisychain-method.
std::vector< std::string > incompatibleParameters
Parameters that are incompatible with this parameter.
std::vector< std::string > defaultValue
The default value for this parameter.
ParamConstraint AddIncompatibilities(const std::initializer_list< std::string > &incompatibleParameters)
Daisychain-method.
DATA_TYPE requiredType
Constrain the parameter to this value. Requires constrainType to be set to true.
static ParamConstraint Require(const std::initializer_list< std::string > &defaultValue={}, bool required=true)
Constructs a require constraint.
static ParamConstraint Incompatibility(const std::initializer_list< std::string > &incompatibleParameters)
Constructs an incompatibility constraint.
bool required
If set to true, and no default value set, an error will be produced if this parameter is not supplied...
ParamConstraint()=default
Empty constructor.
static ParamConstraint TypeSafety(DATA_TYPE requiredType, bool constrainType=true)
Constructs a type-safety constraint.
ParamConstraint(bool constrainType, DATA_TYPE requiredType, const std::initializer_list< std::string > &defaultValue, bool required, const std::initializer_list< std::string > &incompatibleParameters)
Whole constructor.
bool constrainType
Should this parameter be forced to be of a certain type? Remember to set constrainTo to the wanted ty...
DATA_TYPE
The different data types a paramater can be.
Definition: DataType.h:8
The main class to interface with.