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::string& key, const std::vector<std::string>& defaultValue = {}, bool required = true)
17  {
18  ParamConstraint pc;
19  pc.key = key;
21  pc.required = required;
22 
23  return pc;
24  }
25 
26  //! Constructs a type-safety constraint
27  static ParamConstraint TypeSafety(const std::string& key, DATA_TYPE wantedType, bool constrainType = true)
28  {
29  ParamConstraint pc;
30  pc.key = key;
33 
34  return pc;
35  }
36 
37  //! Whole constructor
38  ParamConstraint(const std::string& key, bool constrainType, DATA_TYPE wantedType, const std::vector<std::string>& defaultValue, bool required)
39  :
40  key{ key },
45  {
46  return;
47  }
48 
49  //! The key of the parameter to constrain
50  std::string key;
51 
52  //! Should this parameter be forced to be of a certain type?
53  //! Remember to set `constrainTo` to the wanted type
54  bool constrainType = false;
55 
56  //! Constrain the parameter to this value. Requires `constrainType` to be set to true.
58 
59  //! The default value for this parameter.
60  //! Gets applied if this parameter was not given.
61  //! Think of this like a list of parameters. Like {"--width", "800"}
62  std::vector<std::string> defaultValue;
63 
64  //! If set to true, and no default value set,
65  //! an error will be produced if this parameter is not supplied by the user.
66  bool required = false;
67  };
68 }
Hazelnp
Definition: DataType.h:4
DataType.h
Hazelnp::DATA_TYPE::VOID
@ VOID
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::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::ParamConstraint::ParamConstraint
ParamConstraint()=default
Empty constructor.
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::Require
static ParamConstraint Require(const std::string &key, const std::vector< std::string > &defaultValue={}, bool required=true)
Constructs a require constraint.
Definition: ParamConstraint.h:16
Hazelnp::ParamConstraint::ParamConstraint
ParamConstraint(const std::string &key, bool constrainType, DATA_TYPE wantedType, const std::vector< std::string > &defaultValue, bool required)
Whole constructor.
Definition: ParamConstraint.h:38
Hazelnp::ParamConstraint::TypeSafety
static ParamConstraint TypeSafety(const std::string &key, DATA_TYPE wantedType, bool constrainType=true)
Constructs a type-safety constraint.
Definition: ParamConstraint.h:27
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:62