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