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:
12  ParamConstraint() = default;
13 
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 
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 
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 
50  std::string key;
51 
54  bool constrainType = false;
55 
58 
62  std::vector<std::string> defaultValue;
63 
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