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 
7 {
8 public:
10  ParamConstraint() = default;
11 
14  static ParamConstraint Require(const std::string& key, const std::vector<std::string>& defaultValue = {}, bool required = true)
15  {
16  ParamConstraint pc;
17  pc.key = key;
19  pc.required = required;
20 
21  return pc;
22  }
23 
25  static ParamConstraint TypeSafety(const std::string& key, DATA_TYPE wantedType, bool constrainType = true)
26  {
27  ParamConstraint pc;
28  pc.key = key;
31 
32  return pc;
33  }
34 
36  ParamConstraint(const std::string& key, bool constrainType, DATA_TYPE wantedType, const std::vector<std::string>& defaultValue, bool required)
37  :
38  key { key },
43  {
44  return;
45  }
46 
48  std::string key;
49 
52  bool constrainType = false;
53 
56 
60  std::vector<std::string> defaultValue;
61 
64  bool required = false;
65 };
DataType.h
DATA_TYPE
DATA_TYPE
The different data types a paramater can be.
Definition: DataType.h:5
DATA_TYPE::VOID
@ VOID
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:64
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:36
ParamConstraint::TypeSafety
static ParamConstraint TypeSafety(const std::string &key, DATA_TYPE wantedType, bool constrainType=true)
Constructs a type-safety constraint.
Definition: ParamConstraint.h:25
ParamConstraint::defaultValue
std::vector< std::string > defaultValue
The default value for this parameter.
Definition: ParamConstraint.h:60
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:14
ParamConstraint::key
std::string key
The key of the parameter to constrain.
Definition: ParamConstraint.h:48
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:52
ParamConstraint::ParamConstraint
ParamConstraint()=default
Empty constructor.
ParamConstraint::wantedType
DATA_TYPE wantedType
Constrain the parameter to this value. Requires constrainType to be set to true.
Definition: ParamConstraint.h:55
ParamConstraint
Definition: ParamConstraint.h:6