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;
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  //! Whole constructor
90  ParamConstraint(bool constrainType, DATA_TYPE requiredType, const std::initializer_list<std::string>& defaultValue, bool required, const std::initializer_list<std::string>& incompatibleParameters)
91  :
95  required{ required },
97  {
98  return;
99  }
100 
101  //! Should this parameter be forced to be of a certain type?
102  //! Remember to set `constrainTo` to the wanted type
103  bool constrainType = false;
104 
105  //! Constrain the parameter to this value. Requires `constrainType` to be set to true.
107 
108  //! The default value for this parameter.
109  //! Gets applied if this parameter was not given.
110  //! Think of this like a list of parameters. Like {"--width", "800"}
111  std::vector<std::string> defaultValue;
112 
113  //! If set to true, and no default value set,
114  //! an error will be produced if this parameter is not supplied by the user.
115  bool required = false;
116 
117  //! Parameters that are incompatible with this parameter
118  std::vector<std::string> incompatibleParameters;
119 
120  private:
121  //! The parameter this constraint is for.
122  //! This value is automatically set by Hazelnupp.
123  std::string key;
124 
125  friend class CmdArgsInterface;
126  };
127 }
Hazelnp
Definition: CmdArgsInterface.h:9
Hazelnp::ParamConstraint::Require
static ParamConstraint Require(const std::initializer_list< std::string > &defaultValue={}, bool required=true)
Constructs a require constraint.
Definition: ParamConstraint.h:16
DataType.h
Hazelnp::CmdArgsInterface
The main class to interface with.
Definition: CmdArgsInterface.h:13
Hazelnp::ParamConstraint::Incompatibility
static ParamConstraint Incompatibility(const std::string &incompatibleParameters)
Constructs an incompatibility constraint.
Definition: ParamConstraint.h:70
Hazelnp::ParamConstraint::Incompatibility
static ParamConstraint Incompatibility(const std::initializer_list< std::string > &incompatibleParameters)
Constructs an incompatibility constraint.
Definition: ParamConstraint.h:59
Hazelnp::ParamConstraint::AddIncompatibility
ParamConstraint AddIncompatibility(const std::string &incompatibleParameters)
Daisychain-method.
Definition: ParamConstraint.h:81
Hazelnp::ParamConstraint::ParamConstraint
ParamConstraint(bool constrainType, DATA_TYPE requiredType, const std::initializer_list< std::string > &defaultValue, bool required, const std::initializer_list< std::string > &incompatibleParameters)
Whole constructor.
Definition: ParamConstraint.h:90
Hazelnp::DATA_TYPE::VOID
@ VOID
Hazelnp::ParamConstraint::requiredType
DATA_TYPE requiredType
Constrain the parameter to this value. Requires constrainType to be set to true.
Definition: ParamConstraint.h:106
Hazelnp::ParamConstraint
Definition: ParamConstraint.h:8
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:103
Hazelnp::ParamConstraint::AddRequire
ParamConstraint AddRequire(const std::initializer_list< std::string > &defaultValue={}, bool required=true)
Daisychain-method.
Definition: ParamConstraint.h:27
Hazelnp::ParamConstraint::ParamConstraint
ParamConstraint()=default
Empty constructor.
Hazelnp::ParamConstraint::incompatibleParameters
std::vector< std::string > incompatibleParameters
Parameters that are incompatible with this parameter.
Definition: ParamConstraint.h:118
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:115
Hazelnp::ParamConstraint::TypeSafety
static ParamConstraint TypeSafety(DATA_TYPE requiredType, bool constrainType=true)
Constructs a type-safety constraint.
Definition: ParamConstraint.h:37
Hazelnp::DATA_TYPE
DATA_TYPE
The different data types a paramater can be.
Definition: DataType.h:8
Hazelnp::ParamConstraint::defaultValue
std::vector< std::string > defaultValue
The default value for this parameter.
Definition: ParamConstraint.h:111
Hazelnp::ParamConstraint::AddTypeSafety
ParamConstraint AddTypeSafety(DATA_TYPE requiredType, bool constrainType=true)
Daisychain-method.
Definition: ParamConstraint.h:48